Scripting - simple-entertainment/simplicity GitHub Wiki
Scripting is the main method for including game logic and any other functionality specific to your game.
If you want a script to be executed, just add it to an entity!
std::unique_ptr<Entity> entity(new Entity);
std::unique_ptr<Script> script(new BadGuyScript);
entity->addUniqueComponent(move(script));
Simplicity::getScene()->addEntity(move(entity));
To create a script just extend Script
. The only function that needs to be defined is execute(Entity& entity)
which it called every frame but there are also a set of callback functions that you can choose to implement. See the API documentation for details on when they are called.
onAddEntity(Entity& entity)
onCloseScene(Scene& scene, Entity& entity)
onOpenScene(Scene& scene, Entity& entity)
onPauseScene(Scene& scene, Entity& entity)
onRemoveEntity(Entity& entity, Entity& entity)
onResumeScene(Scene& scene, Entity& entity)
Since a script can be shared by multiple entities, the entity the script is currently being run for is passed to the script in every function.
The scripting engine is a simple engine that executes the scripts every frame and calls the callback functions during lifecycle events.