Scripting
This is a big vague issue, I'm just collecting/publishing ideas here.
Needed for
- give fighters unique special abilities.
- unique game mechanics
- Ledge getup actions will use it for the following:
- what frame to stop hogging
- what frame to actually land/give control back to player
- position offset from the ledge for each frame
Language choice
There a lot of options. The main ones include:
Rlua
- lua binding
Hlua
- lua binding
Rhai
Dyon
- Functional
Gluon
- Functional
Roll our own
- Would integrate better with treeflection
- Tailor syntax to our needs
- Would never be as nice as a proper language, dont have the resources to devote to such a task.
Scope
The scope for the scripting language is very important, some potential ideas:
- Move all game logic into script callbacks, things like collisionbox/stage collision are kept in rust.
- Each character gets their own script which is called during their step method.
- A unique script is stored for each action or frame for each character
Example Lua API
For each fighter there is a fighter.lua file containing the following functions:
spawn(usize player); action(usize player, usize action, usize frame); hitbox_collide(usize player, usize action, usize frame, int collision_flags); hurtbox_collide(usize player, usize action, usize frame, int collision_flags);
The functions are called by pf sandbox when each event occurs. They have access to an api:
set_acc_player(usize player, float x, float y); get_acc_player(usize player, float x, float y); set_vel_player(usize player, float x, float y); get_vel_player(usize player, float x, float y); set_pos_player(usize player, float x, float y); get_pos_player(usize player, float x, float y); set_action(usize player, usize action); generate_entity(String name, float x, float y); random(int max); // seeded determined at start of game + frame_index // high and low level input e.g. can_jump and press_x