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 From 7e12ebdf945d40d6f11872cf5852c9bb54d1864f Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 22 Dec 2024 16:12:31 +0100 Subject: big WIP --- .gitmodules | 3 ++ game/CMakeLists.txt | 17 ++++----- game/Config.h | 11 ++++++ game/GameScene.cpp | 20 +++++----- game/PlayerScript.cpp | 11 ------ game/PlayerScript.h | 8 ---- game/PlayerSubScene.cpp | 76 ------------------------------------- game/PlayerSubScene.h | 10 ----- game/background/CMakeLists.txt | 9 +++++ game/main.cpp | 3 ++ game/prefab/CMakeLists.txt | 5 +++ game/prefab/PlayerObject.cpp | 76 +++++++++++++++++++++++++++++++++++++ game/prefab/PlayerObject.h | 30 +++++++++++++++ game/prefab/PlayerScript.cpp | 26 +++++++++++++ game/prefab/PlayerScript.h | 23 +++++++++++ game/prefab/ZapperObject.h | 7 ++++ lib/segvcatch/CMakeLists.txt | 35 +++++++++++++++++ lib/segvcatch/lib | 1 + src/CMakeLists.txt | 3 ++ src/crepe/Collider.h | 3 ++ src/crepe/api/BehaviorScript.cpp | 18 +++++++++ src/crepe/api/BehaviorScript.h | 6 +++ src/crepe/api/BehaviorScript.hpp | 1 + src/crepe/api/Components.h | 16 ++++++++ src/crepe/api/Config.h | 3 +- src/crepe/api/Engine.cpp | 27 +++++++++---- src/crepe/api/Engine.h | 5 +++ src/crepe/api/GameObject.h | 7 ++++ src/crepe/facade/CMakeLists.txt | 2 + src/crepe/facade/SignalCatch.cpp | 25 ++++++++++++ src/crepe/facade/SignalCatch.h | 24 ++++++++++++ src/crepe/manager/SystemManager.cpp | 24 ++++++++---- src/crepe/manager/SystemManager.h | 13 +++++-- src/crepe/manager/SystemManager.hpp | 5 ++- src/crepe/system/ScriptSystem.cpp | 15 ++++++-- 35 files changed, 422 insertions(+), 146 deletions(-) delete mode 100644 game/PlayerScript.cpp delete mode 100644 game/PlayerScript.h delete mode 100644 game/PlayerSubScene.cpp delete mode 100644 game/PlayerSubScene.h create mode 100644 game/background/CMakeLists.txt create mode 100644 game/prefab/CMakeLists.txt create mode 100644 game/prefab/PlayerObject.cpp create mode 100644 game/prefab/PlayerObject.h create mode 100644 game/prefab/PlayerScript.cpp create mode 100644 game/prefab/PlayerScript.h create mode 100644 game/prefab/ZapperObject.h create mode 100644 lib/segvcatch/CMakeLists.txt create mode 160000 lib/segvcatch/lib create mode 100644 src/crepe/api/Components.h create mode 100644 src/crepe/facade/SignalCatch.cpp create mode 100644 src/crepe/facade/SignalCatch.h (limited to 'game/Config.h') diff --git a/.gitmodules b/.gitmodules index 8155600..6e2ae88 100644 --- a/.gitmodules +++ b/.gitmodules @@ -30,3 +30,6 @@ path = lib/fontconfig url = https://gitlab.freedesktop.org/fontconfig/fontconfig.git shallow = true +[submodule "lib/segvcatch/lib"] + path = lib/segvcatch/lib + url = https://github.com/Plaristote/segvcatch diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 937b5e6..a149487 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -8,20 +8,19 @@ set(CMAKE_BUILD_TYPE Debug) project(game C CXX) add_subdirectory(../src crepe) -add_executable(main - background/AquariumSubScene.cpp - background/BackgroundSubScene.cpp - background/ForestParallaxScript.cpp - background/ForestSubScene.cpp + +add_executable(main) + +target_sources(main PUBLIC GameScene.cpp - background/HallwaySubScene.cpp MoveCameraManualyScript.cpp - PlayerScript.cpp - PlayerSubScene.cpp StartGameScript.cpp - background/StartSubScene.cpp main.cpp ) +add_subdirectory(background) +add_subdirectory(prefab) + target_link_libraries(main PUBLIC crepe) +target_include_directories(main PRIVATE .) diff --git a/game/Config.h b/game/Config.h index ec753df..350cd02 100644 --- a/game/Config.h +++ b/game/Config.h @@ -1,5 +1,16 @@ #pragma once +#include + +static const crepe::Config ENGINE_CONFIG { + .log { + .level = crepe::Log::Level::DEBUG, + }, + .window_settings { + .window_title = "Jetpack joyride clone", + }, +}; + 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 diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 2511567..57c6531 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -1,11 +1,3 @@ -#include "GameScene.h" -#include "Config.h" -#include "MoveCameraManualyScript.h" -#include "PlayerSubScene.h" -#include "StartGameScript.h" - -#include "background/BackgroundSubScene.h" - #include #include #include @@ -22,10 +14,20 @@ #include #include +#include "GameScene.h" +#include "Config.h" +#include "MoveCameraManualyScript.h" +#include "StartGameScript.h" + +#include "background/BackgroundSubScene.h" +#include "prefab/PlayerObject.h" + using namespace crepe; using namespace std; void GameScene::load_scene() { + logf(Log::DEBUG, "Loading (main) GameScene..."); + BackgroundSubScene background(*this); GameObject camera = new_object("camera", "camera", vec2(650, 0)); @@ -38,7 +40,7 @@ void GameScene::load_scene() { camera.add_component().set_script(); camera.add_component(Rigidbody::Data {}); - PlayerSubScene player(*this); + PlayerObject player {new_object("player", "player", vec2(-100, 200))}; GameObject floor = new_object("floor", "game_world", vec2(0, 325)); floor.add_component(Rigidbody::Data { diff --git a/game/PlayerScript.cpp b/game/PlayerScript.cpp deleted file mode 100644 index 1c388f5..0000000 --- a/game/PlayerScript.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "PlayerScript.h" - -#include - -using namespace crepe; -using namespace std; - -void PlayerScript::fixed_update(crepe::duration_t dt) { - Rigidbody & rb = this->get_components_by_name("player").front(); - if (this->get_key_state(Keycode::SPACE)) rb.add_force_linear(vec2(0, -10)); -} diff --git a/game/PlayerScript.h b/game/PlayerScript.h deleted file mode 100644 index 84c4f7f..0000000 --- a/game/PlayerScript.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include - -class PlayerScript : public crepe::Script { -public: - void fixed_update(crepe::duration_t dt); -}; diff --git a/game/PlayerSubScene.cpp b/game/PlayerSubScene.cpp deleted file mode 100644 index 00b7810..0000000 --- a/game/PlayerSubScene.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "PlayerSubScene.h" -#include "Config.h" -#include "PlayerScript.h" - -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -PlayerSubScene::PlayerSubScene(Scene & scn) { - GameObject player = scn.new_object("player", "player", vec2(-100, 200)); - Asset player_body_asset {"asset/barry/defaultBody.png"}; - Sprite & player_body_sprite = player.add_component( - player_body_asset, - Sprite::Data { - .sorting_in_layer = SORT_IN_LAY_PLAYER, - .order_in_layer = 0, - .size = vec2(0, 50), - } - ); - player.add_component( - player_body_sprite, ivec2(32, 32), uvec2(4, 8), - Animator::Data { - .fps = 5, - .looping = true, - } - ); - Asset player_head_asset {"asset/barry/defaultHead.png"}; - Sprite & player_head_sprite = player.add_component( - player_head_asset, - Sprite::Data { - .sorting_in_layer = SORT_IN_LAY_PLAYER, - .order_in_layer = 1, - .size = vec2(0, 50), - .position_offset = vec2(0, -20), - } - ); - player.add_component( - player_head_sprite, ivec2(32, 32), uvec2(4, 8), - Animator::Data { - .fps = 5, - .looping = true, - } - ); - Asset player_jetpack_asset {"asset/barry/jetpackDefault.png"}; - Sprite & player_jetpack_sprite = player.add_component( - player_jetpack_asset, - Sprite::Data { - .sorting_in_layer = SORT_IN_LAY_PLAYER, - .order_in_layer = 2, - .size = vec2(0, 60), - .position_offset = vec2(-20, 0), - } - ); - player_jetpack_sprite.active = false; - player.add_component( - player_jetpack_sprite, ivec2(32, 44), uvec2(4, 4), - Animator::Data { - .fps = 5, - .looping = true, - } - ); - player.add_component(Rigidbody::Data { - .gravity_scale = 20, - .body_type = Rigidbody::BodyType::DYNAMIC, - .linear_velocity = vec2(100, 0), - .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/PlayerSubScene.h b/game/PlayerSubScene.h deleted file mode 100644 index bf94c32..0000000 --- a/game/PlayerSubScene.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -namespace crepe { -class Scene; -} - -class PlayerSubScene { -public: - PlayerSubScene(crepe::Scene & scn); -}; diff --git a/game/background/CMakeLists.txt b/game/background/CMakeLists.txt new file mode 100644 index 0000000..1d705f5 --- /dev/null +++ b/game/background/CMakeLists.txt @@ -0,0 +1,9 @@ +target_sources(main PUBLIC + AquariumSubScene.cpp + BackgroundSubScene.cpp + ForestParallaxScript.cpp + ForestSubScene.cpp + HallwaySubScene.cpp + StartSubScene.cpp +) + diff --git a/game/main.cpp b/game/main.cpp index 325b66d..2198f73 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -1,11 +1,14 @@ #include #include +#include "Config.h" #include "GameScene.h" using namespace crepe; int main() { + Config::get_instance() = ENGINE_CONFIG; + Engine gameloop; gameloop.add_scene(); diff --git a/game/prefab/CMakeLists.txt b/game/prefab/CMakeLists.txt new file mode 100644 index 0000000..a588090 --- /dev/null +++ b/game/prefab/CMakeLists.txt @@ -0,0 +1,5 @@ +target_sources(main PUBLIC + PlayerObject.cpp + PlayerScript.cpp +) + diff --git a/game/prefab/PlayerObject.cpp b/game/prefab/PlayerObject.cpp new file mode 100644 index 0000000..736704a --- /dev/null +++ b/game/prefab/PlayerObject.cpp @@ -0,0 +1,76 @@ +#include + +#include "Config.h" +#include "PlayerObject.h" +#include "PlayerScript.h" + +using namespace crepe; + +PlayerObject::PlayerObject(crepe::GameObject && base) + : GameObject(std::move(base)), + sprite { + .body = add_component( + Asset {"asset/barry/defaultBody.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 0, + .size = vec2(0, 50), + } + ), + .head = add_component( + Asset {"asset/barry/defaultHead.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 1, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ), + .jetpack = add_component( + Asset {"asset/barry/jetpackDefault.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 2, + .size = vec2(0, 60), + .position_offset = vec2(-20, 0), + } + ) + }, + animator { + .body = add_component( + sprite.body, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = 5, + .looping = true, + } + ), + .head = add_component( + sprite.head, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = 5, + .looping = true, + } + ), + .jetpack = add_component( + sprite.jetpack, ivec2(32, 44), uvec2(4, 4), + Animator::Data { + .fps = 5, + .looping = true, + } + ), + }, + body(add_component(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(100, 0), + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_PLAYER, + })), + collider(add_component(vec2(50, 50))), + controller(add_component().set_script(this)) { + sprite.jetpack.active = false; + // controller.active = false; + + Log::logf(Log::DEBUG, "PlayerObject: ref {}", (void*) &(this->body.game_object_id)); +} + diff --git a/game/prefab/PlayerObject.h b/game/prefab/PlayerObject.h new file mode 100644 index 0000000..a44d367 --- /dev/null +++ b/game/prefab/PlayerObject.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +class PlayerObject : public crepe::GameObject { +public: + PlayerObject(crepe::GameObject &&); + +public: + struct { + crepe::Sprite & body; + crepe::Sprite & head; + crepe::Sprite & jetpack; + } sprite; + + struct { + crepe::Animator & body; + crepe::Animator & head; + crepe::Animator & jetpack; + } animator; + + crepe::Rigidbody & body; + crepe::BoxCollider & collider; + crepe::BehaviorScript & controller; +}; diff --git a/game/prefab/PlayerScript.cpp b/game/prefab/PlayerScript.cpp new file mode 100644 index 0000000..e4a4951 --- /dev/null +++ b/game/prefab/PlayerScript.cpp @@ -0,0 +1,26 @@ +#include +#include + +#include "PlayerScript.h" + +using namespace crepe; +using namespace std; + +PlayerScript::PlayerScript(PlayerObject * player) : player(player) { + logf(Log::DEBUG, "PlayerScript: [C] player {}", (void*) &(*player)); + logf(Log::DEBUG, "PlayerScript: [C] player.body {}", (void*) &(player->body)); + logf(Log::DEBUG, "PlayerScript: [C] player.body.id {}", (void*) &(player->body.game_object_id)); +} + +void PlayerScript::init() { + logf(Log::DEBUG, "PlayerScript: [C] player {}", (void*) &(*player)); + logf(Log::DEBUG, "PlayerScript: [C] player.body {}", (void*) &(player->body)); + logf(Log::DEBUG, "PlayerScript: [C] player.body.id {}", (void*) &(player->body.game_object_id)); + player->controller.active = false; +} + +void PlayerScript::fixed_update(crepe::duration_t dt) { + if (this->get_key_state(Keycode::SPACE)) + player->body.add_force_linear({ 0, -10 }); +} + diff --git a/game/prefab/PlayerScript.h b/game/prefab/PlayerScript.h new file mode 100644 index 0000000..bd4a00a --- /dev/null +++ b/game/prefab/PlayerScript.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include "PlayerObject.h" + +class PlayerScript : public crepe::Script { +public: + PlayerScript(PlayerObject * player); + + PlayerScript(const PlayerScript &) = delete; + PlayerScript(PlayerScript &&) = delete; + PlayerScript & operator=(const PlayerScript &) = delete; + PlayerScript & operator=(PlayerScript &&) = delete; + +protected: + void fixed_update(crepe::duration_t dt); + void init(); + +protected: + PlayerObject * player = nullptr; +}; + diff --git a/game/prefab/ZapperObject.h b/game/prefab/ZapperObject.h new file mode 100644 index 0000000..1f32cd7 --- /dev/null +++ b/game/prefab/ZapperObject.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +class ZapperObject : public crepe::GameObject { + // afsd +}; diff --git a/lib/segvcatch/CMakeLists.txt b/lib/segvcatch/CMakeLists.txt new file mode 100644 index 0000000..4449e77 --- /dev/null +++ b/lib/segvcatch/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.28) +set(CMAKE_CXX_STANDARD 20) +project(segvcatch CXX) + +include(CMakePackageConfigHelpers) + +add_library(segvcatch SHARED lib/lib/segvcatch.cpp) + +install( + TARGETS segvcatch + EXPORT segvcatchTargets + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION lib + INCLUDES DESTINATION include +) +install( + FILES lib/lib/segvcatch.h + DESTINATION include +) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/segvcatch-config-version.cmake" + VERSION 0.0.0 + COMPATIBILITY AnyNewerVersion +) +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/segvcatch-config-version.cmake" + DESTINATION lib/cmake/segvcatch +) +install( + EXPORT segvcatchTargets + FILE segvcatch-config.cmake + DESTINATION lib/cmake/segvcatch +) diff --git a/lib/segvcatch/lib b/lib/segvcatch/lib new file mode 160000 index 0000000..afe79c4 --- /dev/null +++ b/lib/segvcatch/lib @@ -0,0 +1 @@ +Subproject commit afe79c49f7d996e2b3143199e6cef69f406247bb diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 696856c..b7d63d7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,8 @@ find_package(GTest REQUIRED) find_package(whereami REQUIRED) find_library(BERKELEY_DB db) find_library(FONTCONFIG_LIB fontconfig) +find_package(segvcatch REQUIRED) +find_package(segvcatch REQUIRED) add_library(crepe SHARED) add_executable(test_main EXCLUDE_FROM_ALL) @@ -31,6 +33,7 @@ target_link_libraries(crepe PUBLIC ${BERKELEY_DB} PUBLIC whereami PUBLIC ${FONTCONFIG_LIB} + PUBLIC segvcatch ) add_subdirectory(crepe) diff --git a/src/crepe/Collider.h b/src/crepe/Collider.h index 42ccfd4..4344f15 100644 --- a/src/crepe/Collider.h +++ b/src/crepe/Collider.h @@ -5,6 +5,9 @@ namespace crepe { +/** + * \brief Base collider class + */ class Collider : public Component { public: Collider(game_object_id_t id, const vec2 & offset); diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp index af7572c..e1c06b0 100644 --- a/src/crepe/api/BehaviorScript.cpp +++ b/src/crepe/api/BehaviorScript.cpp @@ -13,3 +13,21 @@ BehaviorScript & GameObject::add_component() { ComponentManager & mgr = this->mediator.component_manager; return mgr.add_component(this->id, this->mediator); } + +BehaviorScript::BehaviorScript(const BehaviorScript & other) : mediator(other.mediator), Component(other.game_object_id) { + Log::logf("COPY CONSTRUCTOR!!!"); +} + +BehaviorScript::BehaviorScript(BehaviorScript && other) : mediator(other.mediator), Component(other.game_object_id) { + Log::logf("MOVE CONSTRUCTOR!!!"); +} + +BehaviorScript & BehaviorScript::operator = (const BehaviorScript & other) { + Log::logf("COPY OPERATOR!!!"); + return *this; +} + +BehaviorScript & BehaviorScript::operator = (BehaviorScript && other) { + Log::logf("MOVE OPERATOR!!!"); + return *this; +} diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index 3909b96..52a7cbf 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -33,6 +33,11 @@ protected: //! Only ComponentManager is allowed to instantiate BehaviorScript friend class ComponentManager; + BehaviorScript(const BehaviorScript &); + BehaviorScript(BehaviorScript &&); + BehaviorScript & operator = (const BehaviorScript &); + BehaviorScript & operator = (BehaviorScript &&); + public: /** * \brief Set the concrete script of this component @@ -48,6 +53,7 @@ public: BehaviorScript & set_script(Args &&... args); protected: + std::string name = "unknown script"; //! Script instance std::unique_ptr