diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2024-12-14 13:24:14 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2024-12-14 13:24:14 +0100 |
commit | 1a5116b944bcbdeeb3474faefbe150e82f8697b1 (patch) | |
tree | 2e81437bfe5b2ac88f103a6aa4e847a550121e2c | |
parent | 876896e50711509e80ef551b4e8ad440e8039b97 (diff) |
updated api and game
-rw-r--r-- | src/crepe/api/BoxCollider.cpp | 3 | ||||
-rw-r--r-- | src/crepe/api/BoxCollider.h | 2 | ||||
-rw-r--r-- | src/crepe/api/CircleCollider.cpp | 3 | ||||
-rw-r--r-- | src/crepe/api/CircleCollider.h | 2 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.h | 2 | ||||
-rw-r--r-- | src/example/game.cpp | 26 |
6 files changed, 13 insertions, 25 deletions
diff --git a/src/crepe/api/BoxCollider.cpp b/src/crepe/api/BoxCollider.cpp index c097a24..302bdd2 100644 --- a/src/crepe/api/BoxCollider.cpp +++ b/src/crepe/api/BoxCollider.cpp @@ -4,7 +4,6 @@ using namespace crepe; -BoxCollider::BoxCollider(game_object_id_t game_object_id, const vec2 & offset, - const vec2 & dimensions) +BoxCollider::BoxCollider(game_object_id_t game_object_id,const vec2 & dimensions,const vec2 & offset) : Collider(game_object_id, offset), dimensions(dimensions) {} diff --git a/src/crepe/api/BoxCollider.h b/src/crepe/api/BoxCollider.h index 1ac4d46..a507e0c 100644 --- a/src/crepe/api/BoxCollider.h +++ b/src/crepe/api/BoxCollider.h @@ -13,7 +13,7 @@ namespace crepe { */ class BoxCollider : public Collider { public: - BoxCollider(game_object_id_t game_object_id, const vec2 & offset, const vec2 & dimensions); + BoxCollider(game_object_id_t game_object_id, const vec2 & dimensions,const vec2 & offset= {0,0}); //! Width and height of the box collider vec2 dimensions; diff --git a/src/crepe/api/CircleCollider.cpp b/src/crepe/api/CircleCollider.cpp index a4271e9..e542275 100644 --- a/src/crepe/api/CircleCollider.cpp +++ b/src/crepe/api/CircleCollider.cpp @@ -2,7 +2,6 @@ using namespace crepe; -CircleCollider::CircleCollider(game_object_id_t game_object_id, const vec2 & offset, - float radius) +CircleCollider::CircleCollider(game_object_id_t game_object_id, float radius, const vec2 & offset) : Collider(game_object_id, offset), radius(radius) {} diff --git a/src/crepe/api/CircleCollider.h b/src/crepe/api/CircleCollider.h index c7bf66e..ea40068 100644 --- a/src/crepe/api/CircleCollider.h +++ b/src/crepe/api/CircleCollider.h @@ -13,7 +13,7 @@ namespace crepe { */ class CircleCollider : public Collider { public: - CircleCollider(game_object_id_t game_object_id, const vec2 & offset, float radius); + CircleCollider(game_object_id_t game_object_id, float radius, const vec2 & offset= {0,0}); //! Radius of the circle collider. float radius; diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h index b08c8db..6900295 100644 --- a/src/crepe/api/Rigidbody.h +++ b/src/crepe/api/Rigidbody.h @@ -139,7 +139,7 @@ public: * Each element represents a layer ID, and the GameObject will only detect * collisions with other GameObjects that belong to these layers. */ - std::set<int> collision_layers; + std::set<int> collision_layers = {0}; }; public: diff --git a/src/example/game.cpp b/src/example/game.cpp index 8ea50ea..60c9088 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -176,19 +176,11 @@ public: .gravity_scale = 0, .body_type = Rigidbody::BodyType::STATIC, .offset = {0, 0}, - .collision_layers = {0}, }); - world.add_component<BoxCollider>( - vec2{0, 0 - (screen_size_height / 2 + world_collider / 2)}, - vec2{world_collider, world_collider}); - ; // Top - world.add_component<BoxCollider>(vec2{0, screen_size_height / 2 + world_collider / 2}, - vec2{world_collider, world_collider}); // Bottom - world.add_component<BoxCollider>( - vec2{0 - (screen_size_width / 2 + world_collider / 2), 0}, - vec2{world_collider, world_collider}); // Left - world.add_component<BoxCollider>(vec2{screen_size_width / 2 + world_collider / 2, 0}, - vec2{world_collider, world_collider}); // right + world.add_component<BoxCollider>(vec2{world_collider, world_collider},vec2{0, 0 - (screen_size_height / 2 + world_collider / 2)}); // Top + world.add_component<BoxCollider>(vec2{world_collider, world_collider},vec2{0, screen_size_height / 2 + world_collider / 2}); // Bottom + world.add_component<BoxCollider>(vec2{world_collider, world_collider},vec2{0 - (screen_size_width / 2 + world_collider / 2), 0}); // Left + world.add_component<BoxCollider>(vec2{world_collider, world_collider},vec2{screen_size_width / 2 + world_collider / 2, 0}); // right world.add_component<Camera>( ivec2{static_cast<int>(screen_size_width), static_cast<int>(screen_size_height)}, vec2{screen_size_width, screen_size_height}, @@ -207,10 +199,9 @@ public: .constraints = {0, 0, 0}, .elastisity_coefficient = 1, .offset = {0, 0}, - .collision_layers = {0}, }); // add box with boxcollider - game_object1.add_component<BoxCollider>(vec2{0, 0}, vec2{20, 20}); + game_object1.add_component<BoxCollider>(vec2{20, 20}); game_object1.add_component<BehaviorScript>().set_script<MyScript1>(); Asset img1{"asset/texture/square.png"}; @@ -219,7 +210,7 @@ public: }); //add circle with cirlcecollider deactiveated - game_object1.add_component<CircleCollider>(vec2{0, 0}, 10).active = false; + game_object1.add_component<CircleCollider>(10).active = false; Asset img2{"asset/texture/circle.png"}; game_object1 .add_component<Sprite>(img2, @@ -239,10 +230,9 @@ public: .constraints = {0, 0, 0}, .elastisity_coefficient = 1, .offset = {0, 0}, - .collision_layers = {0}, }); // add box with boxcollider - game_object2.add_component<BoxCollider>(vec2{0, 0}, vec2{20, 20}); + game_object2.add_component<BoxCollider>(vec2{20, 20}); game_object2.add_component<BehaviorScript>().set_script<MyScript2>(); game_object2.add_component<Sprite>(img1, Sprite::Data{ @@ -250,7 +240,7 @@ public: }); //add circle with cirlcecollider deactiveated - game_object2.add_component<CircleCollider>(vec2{0, 0}, 10).active = false; + game_object2.add_component<CircleCollider>(10).active = false; game_object2 .add_component<Sprite>(img2, |