#include #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; } bool mousemove(const MouseMoveEvent & event) { RefVector aivec = this->get_components(); AI & ai = aivec.front().get(); ai.flee_target = vec2{static_cast(event.mouse_x), static_cast(event.mouse_y)}; return true; } void init() { subscribe( [this](const ShutDownEvent & ev) -> bool { return this->shutdown(ev); }); subscribe( [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{250, 250}, 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(img, Color::MAGENTA, Sprite::FlipSettings{false, false}, 1, 1, 195); AI & ai = game_object1.add_component(30); ai.arrive_on(); ai.flee_on(); game_object1.add_component(Rigidbody::Data{ .mass = 0.5f, .max_linear_velocity = {21, 21}, // sqrt(21^2 + 21^2) = 30 }); game_object1.add_component().set_script(); game_object2.add_component(Color::WHITE, ivec2{1080, 720}, vec2{1036, 780}, 1.0f); } string get_name() const override { return "Scene1"; } }; int main() { LoopManager engine; engine.add_scene(); engine.start(); return 0; }