aboutsummaryrefslogtreecommitdiff
path: root/src/example
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-12-07 15:54:13 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-12-07 15:54:13 +0100
commita61149733e8661c97f15fc99e5b28489c29a2b22 (patch)
treef164cdb849097b6dffb4dcf093e2b9a1a28adaaf /src/example
parentfdb4c99e139a264d4e15e6913a3756fc6cccb2f2 (diff)
parent33a072db28d71ba65e59f9491abd42dbf9695fc4 (diff)
merge AI
Diffstat (limited to 'src/example')
-rw-r--r--src/example/AITest.cpp81
-rw-r--r--src/example/CMakeLists.txt1
-rw-r--r--src/example/game.cpp4
3 files changed, 86 insertions, 0 deletions
diff --git a/src/example/AITest.cpp b/src/example/AITest.cpp
new file mode 100644
index 0000000..d12a99a
--- /dev/null
+++ b/src/example/AITest.cpp
@@ -0,0 +1,81 @@
+#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/Rigidbody.h>
+#include <crepe/api/Scene.h>
+#include <crepe/api/Script.h>
+#include <crepe/api/Sprite.h>
+#include <crepe/api/Texture.h>
+#include <crepe/manager/Mediator.h>
+#include <crepe/types.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;
+ }
+
+ bool mousemove(const MouseMoveEvent & event) {
+ /*RefVector<AI> aivec = this->get_components<AI>();
+ AI & ai = aivec.front().get();
+ ai.flee_target
+ = vec2{static_cast<float>(event.mouse_x), static_cast<float>(event.mouse_y)};*/
+ return true;
+ }
+
+ void init() {
+ subscribe<ShutDownEvent>(
+ [this](const ShutDownEvent & ev) -> bool { return this->shutdown(ev); });
+ subscribe<MouseMoveEvent>(
+ [this](const MouseMoveEvent & ev) -> bool { return this->mousemove(ev); });
+ }
+};
+
+class Scene1 : public Scene {
+public:
+ void load_scene() override {
+ Mediator & mediator = this->mediator;
+ ComponentManager & mgr = mediator.component_manager;
+
+ GameObject game_object1 = mgr.new_object("", "", vec2{0, 0}, 0, 1);
+ GameObject game_object2 = mgr.new_object("", "", vec2{0, 0}, 0, 1);
+
+ Texture img = Texture("asset/texture/test_ap43.png");
+ game_object1.add_component<Sprite>(img, Color::MAGENTA,
+ Sprite::FlipSettings{false, false}, 1, 1, 195);
+ AI & ai = game_object1.add_component<AI>(300);
+ // ai.arrive_on();
+ // ai.flee_on();
+ ai.path_follow_on();
+ ai.add_path_node(vec2{1200, 1200});
+ ai.add_path_node(vec2{-1200, 1200});
+ ai.add_path_node(vec2{1200, -1200});
+ ai.add_path_node(vec2{-1200, -1200});
+ game_object1.add_component<Rigidbody>(Rigidbody::Data{
+ .mass = 0.5f, .max_linear_velocity = {50, 50}, // sqrt(21^2 + 21^2) = 30
+ });
+ game_object1.add_component<BehaviorScript>().set_script<Script1>();
+
+ game_object2.add_component<Camera>(Color::WHITE, ivec2{1080, 720}, vec2{5000, 5000},
+ 1.0f);
+ }
+
+ string get_name() const override { return "Scene1"; }
+};
+
+int main() {
+ LoopManager engine;
+ engine.add_scene<Scene1>();
+ engine.start();
+
+ return 0;
+}
diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt
index 8ef71bb..149c412 100644
--- a/src/example/CMakeLists.txt
+++ b/src/example/CMakeLists.txt
@@ -21,3 +21,4 @@ add_example(savemgr)
add_example(rendering_particle)
add_example(game)
add_example(button)
+add_example(AITest)
diff --git a/src/example/game.cpp b/src/example/game.cpp
index 4239c15..2b4e46f 100644
--- a/src/example/game.cpp
+++ b/src/example/game.cpp
@@ -66,6 +66,10 @@ class MyScript1 : public Script {
//add collider switch
break;
}
+ case Keycode::Q: {
+ throw "Test";
+ break;
+ }
default:
break;
}