diff options
-rw-r--r-- | src/example/AITest.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/example/AITest.cpp b/src/example/AITest.cpp index 841b195..91a529c 100644 --- a/src/example/AITest.cpp +++ b/src/example/AITest.cpp @@ -1,19 +1,33 @@ #include <SDL2/SDL_timer.h> #include <chrono> #include <crepe/api/AI.h> +#include <crepe/api/BehaviorScript.h> #include <crepe/api/Camera.h> #include <crepe/api/Color.h> #include <crepe/api/GameObject.h> #include <crepe/api/LoopManager.h> #include <crepe/api/Scene.h> +#include <crepe/api/Script.h> #include <crepe/api/Sprite.h> #include <crepe/api/Texture.h> -#include <crepe/manager/ComponentManager.h> #include <crepe/manager/Mediator.h> using namespace crepe; using namespace std; +class Script1 : public Script { + bool shutdown(const ShutDownEvent & event) { + // Very dirty way of shutting down the game + throw "ShutDownEvent"; + return true; + } + + void init() { + subscribe<ShutDownEvent>( + [this](const ShutDownEvent & ev) -> bool { return this->shutdown(ev); }); + } +}; + class Scene1 : public Scene { public: void load_scene() override { @@ -30,6 +44,7 @@ public: game_object2.add_component<Camera>(Color::WHITE, ivec2{1080, 720}, vec2{1036, 780}, 1.0f); + game_object2.add_component<BehaviorScript>().set_script<Script1>(); } string get_name() const override { return "Scene1"; } |