From 18c7e528f3df31d62cd05c2cc34be92be83d5367 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Fri, 20 Dec 2024 12:17:14 +0100 Subject: button now using channel --- src/example/FontExample.cpp | 55 --------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 src/example/FontExample.cpp (limited to 'src/example') diff --git a/src/example/FontExample.cpp b/src/example/FontExample.cpp deleted file mode 100644 index 6a334b1..0000000 --- a/src/example/FontExample.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace crepe; -using namespace std; -using namespace std::chrono; -class TestScript : public Script { -public: - steady_clock::time_point start_time; - virtual void init() override { start_time = steady_clock::now(); } - virtual void update() override { - auto now = steady_clock::now(); - auto elapsed = duration_cast(now - start_time).count(); - - if (elapsed >= 5) { - Mediator & med = mediator; - EventManager & event_mgr = med.event_manager; - event_mgr.trigger_event(); - } - } -}; -class TestScene : public Scene { -public: - void load_scene() override { - GameObject text_object = this->new_object("test", "test", vec2{0, 0}, 0, 1); - text_object.add_component(vec2(100, 100), vec2(0, 0), "OpenSymbol", - Text::Data{}); - text_object.add_component().set_script(); - text_object.add_component(ivec2{300, 300}, vec2{100, 100}, Camera::Data{}); - } - std::string get_name() const override { return "hey"; } -}; -int main() { - // Config& config = Config::get_instance(); - // config.log.level = Log::Level::TRACE; - LoopManager engine; - engine.add_scene(); - engine.start(); - - return 0; -} -- cgit v1.2.3 From 49e7d902ec2b6f509ab79994e7e2626f4bbbccf2 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Fri, 20 Dec 2024 12:20:01 +0100 Subject: make format --- src/crepe/system/InputSystem.cpp | 8 +- src/example/game.cpp | 200 +++++++++++++++++++++------------------ 2 files changed, 114 insertions(+), 94 deletions(-) (limited to 'src/example') diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index 49ffeac..8e9f763 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -171,12 +171,12 @@ void InputSystem::handle_move(const EventData & event_data, const vec2 & mouse_p if (this->is_mouse_inside_button(mouse_pos, button, transform, cam_transform)) { button.hover = true; if (!was_hovering) { - event_mgr.trigger_event(metadata,metadata.game_object_id); + event_mgr.trigger_event(metadata, metadata.game_object_id); } } else { button.hover = false; if (was_hovering) { - event_mgr.trigger_event(metadata,metadata.game_object_id); + event_mgr.trigger_event(metadata, metadata.game_object_id); } } } @@ -196,7 +196,7 @@ void InputSystem::handle_click(const MouseButton & mouse_button, const vec2 & mo const Transform & transform = mgr.get_components_by_id(button.game_object_id).front(); if (this->is_mouse_inside_button(mouse_pos, button, transform, cam_transform)) { - event_mgr.trigger_event(metadata,metadata.game_object_id); + event_mgr.trigger_event(metadata, metadata.game_object_id); } } } @@ -209,7 +209,7 @@ bool InputSystem::is_mouse_inside_button(const vec2 & mouse_pos, const Button & actual_pos += cam_transform.position; } vec2 half_dimensions = button.dimensions / 2; - + return mouse_pos.x >= actual_pos.x - half_dimensions.x && mouse_pos.x <= actual_pos.x + half_dimensions.x && mouse_pos.y >= actual_pos.y - half_dimensions.y diff --git a/src/example/game.cpp b/src/example/game.cpp index 7ee784a..1f8b9e9 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -25,7 +25,8 @@ using namespace std; class ScriptBox : public Script { public: bool oncollision(const CollisionEvent & test) { - Log::logf("Box {} on_collision() with {}", test.info.self.metadata.game_object_id, test.info.other.metadata.game_object_id); + Log::logf("Box {} on_collision() with {}", test.info.self.metadata.game_object_id, + test.info.other.metadata.game_object_id); return true; } @@ -38,7 +39,8 @@ public: class ScriptCircle : public Script { public: bool oncollision(const CollisionEvent & test) { - Log::logf("Circle {} on_collision() with {}", test.info.self.metadata.game_object_id, test.info.other.metadata.game_object_id); + Log::logf("Circle {} on_collision() with {}", test.info.self.metadata.game_object_id, + test.info.other.metadata.game_object_id); return true; } @@ -68,22 +70,20 @@ class ConcreteScene1 : public Scene { public: void load_scene() { GameObject camera = this->new_object("camera"); - camera.add_component(ivec2(1080, 720), vec2(10, 10), Camera::Data{ - .bg_color = Color::WHITE, - .zoom = 1 - }); + camera.add_component(ivec2(1080, 720), vec2(10, 10), + Camera::Data{.bg_color = Color::WHITE, .zoom = 1}); GameObject reference = this->new_object("reference", "tag", vec2(0, 0), 0, 1); Asset reference_asset = Asset("asset/texture/square.png"); reference.add_component(reference_asset, Sprite::Data{ - .color = Color::RED, - .sorting_in_layer = 10, - .order_in_layer = 0, - .size = vec2(0.1, 0.1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(0, 0), - }); + .color = Color::RED, + .sorting_in_layer = 10, + .order_in_layer = 0, + .size = vec2(0.1, 0.1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(0, 0), + }); /*GameObject box_1 = this->new_object("box_1", "tag", vec2(0, 0), 0, 1); Asset box_1_asset = Asset("asset/texture/square.png"); @@ -140,16 +140,18 @@ public: const float OFFSET_Y_LEFT = 0; const float OFFSET_Y_RIGHT = 0; - GameObject box_1 = this->new_object("box_1", "tag", ONTOP ? vec2(-0.25, -4) : vec2(-2, -4), 0, SCALE); + GameObject box_1 = this->new_object("box_1", "tag", + ONTOP ? vec2(-0.25, -4) : vec2(-2, -4), 0, SCALE); Asset box_1_asset = Asset("asset/texture/square.png"); - box_1.add_component(box_1_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), - }); + box_1.add_component(box_1_asset, + Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), + }); box_1.add_component(Rigidbody::Data{ .gravity_scale = 0, .body_type = BODYTYPE_LEFT, @@ -161,16 +163,18 @@ public: box_1.add_component(vec2(1, 1), vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); box_1.add_component().set_script(); - GameObject circle_1 = this->new_object("ricle_1", "tag", ONTOP ? vec2(0.25, -4) : vec2(2, -4), 0, SCALE); + GameObject circle_1 = this->new_object("ricle_1", "tag", + ONTOP ? vec2(0.25, -4) : vec2(2, -4), 0, SCALE); Asset circle_1_asset = Asset("asset/texture/circle.png"); - circle_1.add_component(circle_1_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), - }); + circle_1.add_component( + circle_1_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), + }); circle_1.add_component(Rigidbody::Data{ .gravity_scale = 0, .body_type = BODYTYPE_RIGHT, @@ -178,20 +182,23 @@ public: .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, .kinematic_collision = KINEMATIC_COLLISION, }); - circle_1.add_component().set_script().active = SCRIPT; + circle_1.add_component().set_script().active + = SCRIPT; circle_1.add_component(0.5, vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); circle_1.add_component().set_script(); - GameObject circle_2 = this->new_object("ricle_2", "tag", ONTOP ? vec2(-0.25, -1.5) : vec2(-2.5, -1.5), 0, SCALE); + GameObject circle_2 = this->new_object( + "ricle_2", "tag", ONTOP ? vec2(-0.25, -1.5) : vec2(-2.5, -1.5), 0, SCALE); Asset circle_2_asset = Asset("asset/texture/circle.png"); - circle_2.add_component(circle_2_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), - }); + circle_2.add_component( + circle_2_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), + }); circle_2.add_component(Rigidbody::Data{ .gravity_scale = 0, .body_type = BODYTYPE_LEFT, @@ -199,20 +206,23 @@ public: .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, .kinematic_collision = KINEMATIC_COLLISION, }); - circle_2.add_component().set_script().active = SCRIPT; + circle_2.add_component().set_script().active + = SCRIPT; circle_2.add_component(0.5, vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); circle_2.add_component().set_script(); - GameObject box_2 = this->new_object("box_2", "tag", ONTOP ? vec2(0.25, -1.5) : vec2(2.5, -1.5), 0, SCALE); + GameObject box_2 = this->new_object( + "box_2", "tag", ONTOP ? vec2(0.25, -1.5) : vec2(2.5, -1.5), 0, SCALE); Asset box_2_asset = Asset("asset/texture/square.png"); - box_2.add_component(box_2_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), - }); + box_2.add_component( + box_2_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), + }); box_2.add_component(Rigidbody::Data{ .gravity_scale = 0, .body_type = BODYTYPE_RIGHT, @@ -224,16 +234,18 @@ public: box_2.add_component(vec2(1, 1), vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); box_2.add_component().set_script(); - GameObject box_3 = this->new_object("box_3", "tag", ONTOP ? vec2(-0.25, 1.5) : vec2(-3, 1.5), 0, SCALE); + GameObject box_3 = this->new_object( + "box_3", "tag", ONTOP ? vec2(-0.25, 1.5) : vec2(-3, 1.5), 0, SCALE); Asset box_3_asset = Asset("asset/texture/square.png"); - box_3.add_component(box_3_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), - }); + box_3.add_component(box_3_asset, + Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), + }); box_3.add_component(Rigidbody::Data{ .gravity_scale = 0, .body_type = BODYTYPE_LEFT, @@ -245,16 +257,18 @@ public: box_3.add_component(vec2(1, 1), vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); box_3.add_component().set_script(); - GameObject box_4 = this->new_object("box_4", "tag", ONTOP ? vec2(0.25, 1.5) : vec2(3, 1.5), 0, SCALE); + GameObject box_4 = this->new_object("box_4", "tag", + ONTOP ? vec2(0.25, 1.5) : vec2(3, 1.5), 0, SCALE); Asset box_4_asset = Asset("asset/texture/square.png"); - box_4.add_component(box_4_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), - }); + box_4.add_component( + box_4_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), + }); box_4.add_component(Rigidbody::Data{ .gravity_scale = 0, .body_type = BODYTYPE_RIGHT, @@ -266,16 +280,18 @@ public: box_4.add_component(vec2(1, 1), vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); box_4.add_component().set_script(); - GameObject circle_3 = this->new_object("ricle_3", "tag", ONTOP ? vec2(-0.25, 4) : vec2(-3.5, 4), 0, SCALE); + GameObject circle_3 = this->new_object( + "ricle_3", "tag", ONTOP ? vec2(-0.25, 4) : vec2(-3.5, 4), 0, SCALE); Asset circle_3_asset = Asset("asset/texture/circle.png"); - circle_3.add_component(circle_3_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), - }); + circle_3.add_component( + circle_3_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), + }); circle_3.add_component(Rigidbody::Data{ .gravity_scale = 0, .body_type = BODYTYPE_LEFT, @@ -283,20 +299,23 @@ public: .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, .kinematic_collision = KINEMATIC_COLLISION, }); - circle_3.add_component().set_script().active = SCRIPT; + circle_3.add_component().set_script().active + = SCRIPT; circle_3.add_component(0.5, vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); circle_3.add_component().set_script(); - GameObject circle_4 = this->new_object("ricle_4", "tag", ONTOP ? vec2(0.25, 4) : vec2(3.5, 4), 0, SCALE); + GameObject circle_4 = this->new_object("ricle_4", "tag", + ONTOP ? vec2(0.25, 4) : vec2(3.5, 4), 0, SCALE); Asset circle_4_asset = Asset("asset/texture/circle.png"); - circle_4.add_component(circle_4_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), - }); + circle_4.add_component( + circle_4_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), + }); circle_4.add_component(Rigidbody::Data{ .gravity_scale = 0, .body_type = BODYTYPE_RIGHT, @@ -304,7 +323,8 @@ public: .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, .kinematic_collision = KINEMATIC_COLLISION, }); - circle_4.add_component().set_script().active = SCRIPT; + circle_4.add_component().set_script().active + = SCRIPT; circle_4.add_component(0.5, vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); circle_4.add_component().set_script(); } -- cgit v1.2.3