aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-06 10:14:33 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-06 10:14:33 +0100
commit42ecf9c1d0e3ed1f37f99a24f31241b68f978b28 (patch)
tree6c6c6c3b3c13b2fe68653a4ba9a97e6955d56da5
parent93893dbe710d864d5865f361f9a8a8f8f85b94f6 (diff)
Added script to shutdown game (by throwing an exception and not catching it)
-rw-r--r--src/example/AITest.cpp17
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"; }