From d2af158ac63ab05b2fbfdcdf1b483662e48c0544 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sat, 21 Dec 2024 11:36:37 +0100 Subject: Added Config.h --- game/Config.h | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 game/Config.h (limited to 'game/Config.h') diff --git a/game/Config.h b/game/Config.h new file mode 100644 index 0000000..7a83ee6 --- /dev/null +++ b/game/Config.h @@ -0,0 +1,11 @@ +#pragma once + +static constexpr int SORT_IN_LAY_BACK_BACKGROUND = 3; +static constexpr int SORT_IN_LAY_BACKGROUND = 4; +static constexpr int SORT_IN_LAY_FORE_BACKGROUND = 5; +static constexpr int SORT_IN_LAY_PARTICLES_BACKGROUND = 6; +static constexpr int SORT_IN_LAY_OBSTACLES = 8; +static constexpr int SORT_IN_LAY_PLAYER = 10; +static constexpr int SORT_IN_LAY_PARTICLES_FOREGROUND = 15; + + -- cgit v1.2.3 From 799a376aeecd9bdc712e89324cbe9153206839c9 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sat, 21 Dec 2024 11:38:19 +0100 Subject: Added comments --- game/Config.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'game/Config.h') diff --git a/game/Config.h b/game/Config.h index 7a83ee6..0d6f880 100644 --- a/game/Config.h +++ b/game/Config.h @@ -1,11 +1,9 @@ #pragma once -static constexpr int SORT_IN_LAY_BACK_BACKGROUND = 3; -static constexpr int SORT_IN_LAY_BACKGROUND = 4; -static constexpr int SORT_IN_LAY_FORE_BACKGROUND = 5; -static constexpr int SORT_IN_LAY_PARTICLES_BACKGROUND = 6; -static constexpr int SORT_IN_LAY_OBSTACLES = 8; -static constexpr int SORT_IN_LAY_PLAYER = 10; -static constexpr int SORT_IN_LAY_PARTICLES_FOREGROUND = 15; - - +static constexpr int SORT_IN_LAY_BACK_BACKGROUND = 3; // For all scenes +static constexpr int SORT_IN_LAY_BACKGROUND = 4; // For all scenes +static constexpr int SORT_IN_LAY_FORE_BACKGROUND = 5; // For all scenes +static constexpr int SORT_IN_LAY_PARTICLES_BACKGROUND = 6; // For all scenes +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 -- cgit v1.2.3 From e72dc913e7b35bcd2f6ba8107ea46e383afd25e1 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sat, 21 Dec 2024 11:52:48 +0100 Subject: Added more to Config.h --- game/Config.h | 6 ++++++ game/GameScene.cpp | 3 ++- game/background/AquariumSubScene.cpp | 12 ++++++------ game/background/ForestSubScene.cpp | 8 ++++---- game/background/HallwaySubScene.cpp | 12 ++++++------ game/background/StartSubScene.cpp | 4 ++-- 6 files changed, 26 insertions(+), 19 deletions(-) (limited to 'game/Config.h') diff --git a/game/Config.h b/game/Config.h index 0d6f880..7c16b47 100644 --- a/game/Config.h +++ b/game/Config.h @@ -7,3 +7,9 @@ static constexpr int SORT_IN_LAY_PARTICLES_BACKGROUND = 6; // For all scenes 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 GAME_HEIGHT = 800; // In game units + +static constexpr int VIEWPORT_X = 1100; // In game units +// 'GAME_HEIGHT' (below) should be replaced by '500' when game development is finished +static constexpr int VIEWPORT_Y = GAME_HEIGHT; // In game units diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 9606244..db1a753 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -1,4 +1,5 @@ #include "GameScene.h" +#include "Config.h" #include "MoveCameraManualyScript.h" #include "PlayerSubScene.h" #include "StartGameScript.h" @@ -29,7 +30,7 @@ void GameScene::load_scene() { BackgroundSubScene background(*this); GameObject camera = new_object("camera", "camera", vec2(650, 0)); - camera.add_component(ivec2(990, 720), vec2(1100, 800), + camera.add_component(ivec2(990, 720), vec2(VIEWPORT_X, VIEWPORT_Y), Camera::Data{ .bg_color = Color::RED, }); diff --git a/game/background/AquariumSubScene.cpp b/game/background/AquariumSubScene.cpp index 9994a9e..579e633 100644 --- a/game/background/AquariumSubScene.cpp +++ b/game/background/AquariumSubScene.cpp @@ -21,7 +21,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 0, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; @@ -32,7 +32,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 2, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 400; @@ -45,7 +45,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 3, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 400; @@ -56,7 +56,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 4, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 400; @@ -69,7 +69,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 5, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; @@ -81,7 +81,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 1, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; diff --git a/game/background/ForestSubScene.cpp b/game/background/ForestSubScene.cpp index f0848f2..7eac53a 100644 --- a/game/background/ForestSubScene.cpp +++ b/game/background/ForestSubScene.cpp @@ -26,7 +26,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n begin.add_component(begin_asset, Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 0, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 800; @@ -38,7 +38,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 2, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 800; @@ -50,7 +50,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 3, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 800; @@ -61,7 +61,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n end.add_component(end_asset, Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 1, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; diff --git a/game/background/HallwaySubScene.cpp b/game/background/HallwaySubScene.cpp index b5e3635..2aa9bab 100644 --- a/game/background/HallwaySubScene.cpp +++ b/game/background/HallwaySubScene.cpp @@ -18,7 +18,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu begin.add_component(begin_asset, Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 0, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; @@ -32,7 +32,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 2, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; @@ -42,7 +42,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 3, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 200; @@ -52,7 +52,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 4, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 400; @@ -64,7 +64,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 5, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; @@ -73,7 +73,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu end.add_component(end_asset, Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 1, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; diff --git a/game/background/StartSubScene.cpp b/game/background/StartSubScene.cpp index 547b00d..c769a5f 100644 --- a/game/background/StartSubScene.cpp +++ b/game/background/StartSubScene.cpp @@ -22,7 +22,7 @@ float StartSubScene::create(Scene & scn, float begin_x) { begin.add_component(begin_asset, Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 0, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); GameObject hole = scn.new_object("start_hole", "background", vec2(begin_x - 250, 140)); Asset hole_asset{"asset/background/start/titleWallHole.png"}; @@ -44,7 +44,7 @@ float StartSubScene::create(Scene & scn, float begin_x) { end.add_component(end_asset, Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 1, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 100; -- cgit v1.2.3 From e7599e648ea24d5e8a27bd9f4f162ef1a7c53d21 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sat, 21 Dec 2024 12:25:27 +0100 Subject: Added collision layers to Config.h --- game/Config.h | 6 ++++++ game/GameScene.cpp | 13 +++++++++++++ game/PlayerSubScene.cpp | 3 ++- game/background/StartSubScene.cpp | 38 +++++++++++++++++++++++++------------- 4 files changed, 46 insertions(+), 14 deletions(-) (limited to 'game/Config.h') 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::Data{ .body_type = Rigidbody::BodyType::STATIC, + .collision_layer = COLL_LAY_BOT_TOP, }); floor.add_component(vec2(INFINITY, 200)); + GameObject floor_low = new_object("floor_low", "game_world", vec2(0, 350)); + floor_low.add_component(Rigidbody::Data{ + .body_type = Rigidbody::BodyType::STATIC, + .collision_layer = COLL_LAY_BOT_LOW, + }); + floor_low.add_component(vec2(INFINITY, 200)); + GameObject floor_high = new_object("floor_high", "game_world", vec2(0, 300)); + floor_high.add_component(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::Data{ .body_type = Rigidbody::BodyType::STATIC, + .collision_layer = COLL_LAY_BOT_TOP, }); ceiling.add_component(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(vec2(50, 50)); player.add_component().set_script().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(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(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(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(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(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(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(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(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(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(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( 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(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(50); -- cgit v1.2.3