From 42ecf9c1d0e3ed1f37f99a24f31241b68f978b28 Mon Sep 17 00:00:00 2001 From: max-001 Date: Fri, 6 Dec 2024 10:14:33 +0100 Subject: Added script to shutdown game (by throwing an exception and not catching it) --- src/example/AITest.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/example/AITest.cpp') 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 #include #include +#include #include #include #include #include #include +#include #include #include -#include #include 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( + [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(Color::WHITE, ivec2{1080, 720}, vec2{1036, 780}, 1.0f); + game_object2.add_component().set_script(); } string get_name() const override { return "Scene1"; } -- cgit v1.2.3