solarus-games / solarus

This repository was moved to GitLab: https://gitlab.com/solarus-games/solarus
http://www.solarus-games.org
Other
712 stars 133 forks source link

Feature request: Allow to create custom grounds #812

Open Diarandor opened 8 years ago

Diarandor commented 8 years ago

Add creation of custom grounds, with some properties as follows.

Properties: -string ground_type. The new type of the ground. We could also allow to override built-in types of ground for custom ones. -boolean is_solid_ground. If true, it will automatically save ground for the hero in case he falls in bad ground or not. This can be set to false to create bad grounds similar to lava (acid grounds, etc). -walking sprite (optional): to change the stopped/walking animations of the hero temporarily while walking on this ground (like the swimming one). -additional sprite (optional): like the ones of grass and shallow water, to display a sprite over the hero. -collision event (optional): called in case the hero or other entities (enemies or custom entities) walk on it. This could be used to draw temporarily the footsteps on sand or snow grounds (for the hero or enemies). Also, this (combined with the property "is_solid_ground = false") can be used to create new types of bad ground, like acid ground, or custom water/lava/hole grounds. Also, we could choose dynamically if this ground is bad ground or not, depending on some variable (for instance, we could create an item that allows to swim on custom lava grounds when you have it, and otherwise you die in lava with the usual behaviour). The usual behaviours of entities and enemies falling on it can be coded (like when they fall on water/lava/holes), but we could make different behaviours if we want. -integer speed_modifier (optional): to modify the speed of the hero temporarily while we are walking over this custom ground. This can be positive or negative, to increase or decrease speed of the hero.

This would be useful for: -creating new types of ground, like sand ground and snow grounds (that create footsteps and slow down the walking speed), diggable grounds where we can use the shovel, acid grounds (similar to lava but with some differences for behaviour), etc. -overriding built-in grounds just in case they are not what we want or if we need some slight change of their behaviour. -creating several grounds of the same type but with different walking sprites (like different types of grass ground in the same map). -dynamic behaviour and more customization with the collision event. -also useful for moving platforms if we do not want to save ground on them. -etc.

wrightmat commented 8 years ago

I love the depth of the request, but in my opinion the special property speed_modifier should be left out. Doesn't the API already allow us to change the hero's walking speed dynamically? Placing this code in the coliision event of the ground would have the same effect, wouldn't it?

Diarandor commented 8 years ago

I agree. Also, the hero walking sprite and the additional sprite can be coded using the event (we could also use it to add a walking sound).

The most necessary and useful properties would be then: -The collision event. -The name of the ground (maybe with possibility of overriding built-in ones if they are scripted). -The is_solid_ground variable. Very useful to know if we have good ground or bad ground.

The rest can be coded when Solarus 1.5 is released (we will have access to the sprites of the hero).

EDIT: well, I have thought about this again and maybe it's better to include the speed modifier, the hero sprite and the additional sprite, since it would be quite hard to code it in Lua. Besides, the engine has already code to do that (for the built-in grounds), so it would be better to make more use of that.

Diarandor commented 8 years ago

Another use to create new types of grounds: in Zelda OoA there are very-deep water grounds where you can dive if you have the mermaid's suit. Otherwise you drown, even if you have the flippers to swim. These could be easily done with the "is_solid_ground" variable set to false, and using the event to start some drowning animation on the hero and then reset position to solid ground.

Diarandor commented 8 years ago

Another use: we could create "cracked" type of ground that crashes transforming into a hole. (Obviously we do not need to create the hole, if suffices to put it under the cracked ground and make it disappear.) The cracked ground would need to set the property for not saving solid ground on it, because if it cracks with you above and you fall in the hole, then you need to reappear in other position. The collision test combined with a timer can be used to break the ground when you stay for a while over it. This kind of ground is quite common in 2D Zelda games (at least they appear in all Zeldas of the GameBoy), so this is almost a must do for future versions of the engine.

Diarandor commented 8 years ago

I am closing this issue since some solutions to the problem were found in: http://forum.solarus-games.org/index.php/topic,514.msg2519.html#new

Diarandor commented 8 years ago

I changed my mind again. And although this is not prioritary, I still think that someday the engine should allow more customization for grounds to make our lives easier. These properties are probably the most important ones:

1-If we allow to define custom grounds, we would also need the name for the ground type (a string). 2-It would be very useful to have a boolean property for not saving the solid ground position in certain tiles. This would make our life easier when making grounds that break, moving platforms, and other bad grounds made with custom entities, so that we do not need to redefine the event hero.on_position_changed and the function that is used to save the position of the hero, etc. 3-Allow to use a different animation on the hero (like the one used for swimming), which would affect only the stopped and walking animations. If the hero swims on custom lava, the swimming animation may be a different one (it should be slightly different), etc. 4-Allow to define collision tests: this would allow to make grass (with grass effect when walking over it) that can be cut, or sand grounds that make a different sound when walking over them, or snow tiles that draw the footprints of the hero, etc. 5-Changing the walking speed.

What we could do: the editor and engine should allow defining the new ground types by using the properties, variables and functions: 1-A string variable for the name of the ground type. 2-The optional boolean property "is_solid_ground" (and maybe getter/setter functions to allow modifying this during the game). 3-An optional string for the animation names (and maybe setter/getter functions to allow changing this string during the game). For instance, if we use the string "snow" for this variable, the engine would try to use the animations "snow_stopped" and "snow_walking" for the hero (if they do not exist then nothing would happen). 4-The optional collision test could be defined in some script, if necessary. 5-An integer for the walking speed, and maybe getter/setter functions.

Diarandor commented 8 years ago

Idea: Another use for custom grounds would be to make whirlpools like "holes" in the water, i.e., they would be bad grounds, with their custom falling animation. These would need the property of not saving the solid ground position. Some of them could allow the hero to fall into an underground cavern (in the same way some holes allow to fall to a map in a lower "floor"), but the falling animation could be different; this can be done using the collision test to freeze the hero and set the custom falling animation. (The property of not saving solid ground position is the important thing to create this type of ground.)

Diarandor commented 6 years ago

We'll probably do all of this in pure Lua, with custom entities having a collision test. IMO, this is too specific to be done in C++. A Lua API for custom grounds has to be scripted in Lua.