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

Introduce a grounds Lua API #929

Open ghost opened 8 years ago

ghost commented 8 years ago

As discussed in #926, there should probably be a grounds API. Here are some of my thoughts on it, in a kind of C++-y dialect, and a kind of Lua-y dialect.

C++

class Ground
  public:
    Ground { name : string,
         speed_factor : double -> double [default id]
             must_swim : bool [default false],
         wall_type : WALL_TYPE [default NO_WALL]
       }
    get_must_swim()
    set_must_swim(bool)
    get_speed_factor()
    set_speed_factor(double -> double)
    get_wall_type()
    set_wall_type(WALL_TYPE)
  private:
    name : string
    must_swim : bool 
    speed_factor : double -> double
    wall_type : WALL_TYPE

enum WALL_TYPE = NO_WALL | LOW_WALL | HIGH_WALL

riverrock = Ground { "river-rock" }
riverrock.set_speed_factor(*0)
riverrock.set_wall_type(LOW_WALL)

waterfall = Ground { "waterfall" }
waterfall.set_speed_factor(/8)
waterfall.set_must_swim(true)

Lua

methods:
  must_swim
    -shallow_water:set_must_swim(true)
    -deep_water:set_must_swim(false)
    -water:get_must_swim()
    speed_factor
    -shallow_water:set_speed_factor(/2)
    -escalator:set_speed_factor(*1.5)
    -water:get_speed_factor()
    wall_type
    -tree:set_wall_type(HIGH_WALL)
    -fence:set_wall_type(LOW_WALL)
    -grass:get_wall_type()

events:
  on_traversed_by(entity):
    pit:on_traversed_by(hero, function() game:remove_life(2); hero:set_blinking(true, 500); end)
  on_left_by(entity):
    platform:on_left_by(hero, function() train:leave())

This is all just based on stuff I happen to need/want in my game. I'm sure others want other things. Feel free to suggest them here, as well as to discuss my proposal in general. If anyone have a better idea on how to structure it altogether, it would be worth hearing.

Diarandor commented 8 years ago

Custom (and built-in) grounds could be explained appart, in a different part of the API (inside the tab "Solarus 1.5 - Lua API reference"), when they are implemented.