diff options
author | Max-001 <80035972+Max-001@users.noreply.github.com> | 2024-12-11 14:14:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-11 14:14:43 +0100 |
commit | 78c4a8772526f40c531b5402b56932b0a41e22e8 (patch) | |
tree | 7305c4f88bf177cb8dd704eb9363d3935325804f /src/example/AITest.cpp | |
parent | c45b60941b82dec2097d958b396a117b1634eada (diff) | |
parent | 0dbbbe4bac4ad4fcb9e88908034e90000056363e (diff) |
Merge pull request #68 from lonkaars/max/AI
Max/ai
Diffstat (limited to 'src/example/AITest.cpp')
-rw-r--r-- | src/example/AITest.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/example/AITest.cpp b/src/example/AITest.cpp new file mode 100644 index 0000000..f4efc9f --- /dev/null +++ b/src/example/AITest.cpp @@ -0,0 +1,86 @@ +#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, Sprite::Data{ + .color = Color::MAGENTA, + .flip = Sprite::FlipSettings{false, false}, + .sorting_in_layer = 1, + .order_in_layer = 1, + .size = {0, 195}, + }); + AI & ai = game_object1.add_component<AI>(3000); + // ai.arrive_on(); + // ai.flee_on(); + ai.path_follow_on(); + ai.make_oval_path(500, 1000, {0, -1000}, 1.5708, true); + ai.make_oval_path(1000, 500, {0, 500}, 4.7124, false); + game_object1.add_component<Rigidbody>(Rigidbody::Data{ + .mass = 0.1f, + .max_linear_velocity = {40, 40}, + }); + game_object1.add_component<BehaviorScript>().set_script<Script1>(); + + game_object2.add_component<Camera>(ivec2{1080, 720}, vec2{5000, 5000}, + Camera::Data{ + .bg_color = Color::WHITE, + .zoom = 1, + }); + } + + string get_name() const override { return "Scene1"; } +}; + +int main() { + LoopManager engine; + engine.add_scene<Scene1>(); + engine.start(); + + return 0; +} |