diff options
author | Max-001 <maxsmits21@kpnmail.nl> | 2024-12-21 12:25:27 +0100 |
---|---|---|
committer | Max-001 <maxsmits21@kpnmail.nl> | 2024-12-21 12:25:27 +0100 |
commit | e7599e648ea24d5e8a27bd9f4f162ef1a7c53d21 (patch) | |
tree | da609faa3974250a6543373e3fe81e29fec1a90d | |
parent | 94f99f931e22b5eecbc26b19038788e620ff27ee (diff) |
Added collision layers to Config.h
-rw-r--r-- | game/Config.h | 6 | ||||
-rw-r--r-- | game/GameScene.cpp | 13 | ||||
-rw-r--r-- | game/PlayerSubScene.cpp | 3 | ||||
-rw-r--r-- | game/background/StartSubScene.cpp | 38 |
4 files changed, 46 insertions, 14 deletions
diff --git a/game/Config.h b/game/Config.h index 7c16b47..ec753df 100644 --- a/game/Config.h +++ b/game/Config.h @@ -8,6 +8,12 @@ static constexpr int SORT_IN_LAY_OBSTACLES = 8; // Only for GameScene static constexpr int SORT_IN_LAY_PLAYER = 10; // Only for GameScene static constexpr int SORT_IN_LAY_PARTICLES_FOREGROUND = 15; // Only for GameScene +static constexpr int COLL_LAY_BOT_TOP = 1; // Only for GameScene +static constexpr int COLL_LAY_BOT_LOW = 2; // Only for GameScene +static constexpr int COLL_LAY_BOT_HIGH = 3; // Only for GameScene +static constexpr int COLL_LAY_PLAYER = 4; // Only for GameScene +static constexpr int COLL_LAY_WALL_FRAGS = 5; // Only for GameScene + static constexpr int GAME_HEIGHT = 800; // In game units static constexpr int VIEWPORT_X = 1100; // In game units diff --git a/game/GameScene.cpp b/game/GameScene.cpp index a224cfd..91da092 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -41,11 +41,24 @@ void GameScene::load_scene() { GameObject floor = new_object("floor", "game_world", vec2(0, 325)); floor.add_component<Rigidbody>(Rigidbody::Data{ .body_type = Rigidbody::BodyType::STATIC, + .collision_layer = COLL_LAY_BOT_TOP, }); floor.add_component<BoxCollider>(vec2(INFINITY, 200)); + GameObject floor_low = new_object("floor_low", "game_world", vec2(0, 350)); + floor_low.add_component<Rigidbody>(Rigidbody::Data{ + .body_type = Rigidbody::BodyType::STATIC, + .collision_layer = COLL_LAY_BOT_LOW, + }); + floor_low.add_component<BoxCollider>(vec2(INFINITY, 200)); + GameObject floor_high = new_object("floor_high", "game_world", vec2(0, 300)); + floor_high.add_component<Rigidbody>(Rigidbody::Data{ + .body_type = Rigidbody::BodyType::STATIC, + .collision_layer = COLL_LAY_BOT_HIGH, + }); GameObject ceiling = new_object("ceiling", "game_world", vec2(0, -325)); ceiling.add_component<Rigidbody>(Rigidbody::Data{ .body_type = Rigidbody::BodyType::STATIC, + .collision_layer = COLL_LAY_BOT_TOP, }); ceiling.add_component<BoxCollider>(vec2(INFINITY, 200)); diff --git a/game/PlayerSubScene.cpp b/game/PlayerSubScene.cpp index d81dd34..b361a82 100644 --- a/game/PlayerSubScene.cpp +++ b/game/PlayerSubScene.cpp @@ -56,7 +56,8 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .gravity_scale = 20, .body_type = Rigidbody::BodyType::DYNAMIC, .linear_velocity = vec2(100, 0), - .collision_layer = 10, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_PLAYER, }); player.add_component<BoxCollider>(vec2(50, 50)); player.add_component<BehaviorScript>().set_script<PlayerScript>().active = false; diff --git a/game/background/StartSubScene.cpp b/game/background/StartSubScene.cpp index c769a5f..a918c05 100644 --- a/game/background/StartSubScene.cpp +++ b/game/background/StartSubScene.cpp @@ -168,7 +168,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 500, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_1_rb.active = false; frag_1.add_component<CircleCollider>(25); @@ -189,7 +190,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 400, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_2_rb.active = false; frag_2.add_component<CircleCollider>(55); @@ -210,7 +212,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 300, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_3_rb.active = false; frag_3.add_component<CircleCollider>(35); @@ -231,7 +234,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 200, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_4_rb.active = false; frag_4.add_component<CircleCollider>(60); @@ -252,7 +256,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 100, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_5_rb.active = false; frag_5.add_component<CircleCollider>(5); @@ -273,7 +278,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 100, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_6_rb.active = false; frag_6.add_component<CircleCollider>(30); @@ -294,7 +300,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 800, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_7_rb.active = false; frag_7.add_component<CircleCollider>(45); @@ -315,7 +322,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 500, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_8_rb.active = false; frag_8.add_component<CircleCollider>(25); @@ -336,7 +344,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 500, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_9_rb.active = false; frag_9.add_component<CircleCollider>(15); @@ -357,12 +366,13 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 300, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_10_rb.active = false; frag_10.add_component<CircleCollider>(60); - GameObject frag_11 = scn.new_object("frag_11", "wall_fragment", vec2(begin_x, 90)); + GameObject frag_11 = scn.new_object("frag_11", "wall_fragment", vec2(begin_x, 70)); Asset frag_11_asset{"asset/background/start/StartWall_frag11.png"}; Sprite & frag_11_sprite = frag_11.add_component<Sprite>( frag_11_asset, Sprite::Data{ @@ -378,7 +388,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 200, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_11_rb.active = false; frag_11.add_component<CircleCollider>(5); @@ -399,7 +410,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 100, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_12_rb.active = false; frag_12.add_component<CircleCollider>(50); |