From 26d66b7a73ac8d172d342be03bd75bd5bea221e1 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Sat, 28 Dec 2024 16:22:58 +0100 Subject: coin system --- game/GameScene.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'game/GameScene.cpp') diff --git a/game/GameScene.cpp b/game/GameScene.cpp index c280474..3d692f8 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -3,6 +3,9 @@ #include "MoveCameraManualyScript.h" #include "PlayerSubScene.h" #include "StartGameScript.h" +#include "coins/CoinSubScene.h" +#include "coins/CoinSystem.h" +#include "coins/CoinSystemScript.h" #include #include @@ -33,6 +36,7 @@ void GameScene::load_scene() { .bg_color = Color::RED, }); camera.add_component().set_script(); + camera.add_component().set_script(); camera.add_component(Rigidbody::Data{}); PlayerSubScene player(*this); @@ -50,6 +54,14 @@ void GameScene::load_scene() { GameObject start_game_script = new_object("start_game_script", "script", vec2(0, 0)); start_game_script.add_component().set_script(); + + CoinSubScene coin; + coin.create(*this); + + // CoinSystem coin_system; + // coin_system.create_coins(*this); + // coin_system.add_location({900,0}); + } string GameScene::get_name() const { return "scene1"; } -- cgit v1.2.3 From fb096afbdf3d24f5b9f31626ddf8581033346f88 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Sat, 28 Dec 2024 19:33:06 +0100 Subject: coins with system pooling --- game/GameScene.cpp | 5 +- game/coins/CoinSubScene.cpp | 9 +-- game/coins/CoinSystem.cpp | 71 ------------------- game/coins/CoinSystem.h | 14 +--- game/coins/CoinSystemScript.cpp | 134 ++++++++++++++++++++++++++++++++++-- game/coins/CoinSystemScript.h | 16 ++++- game/mainmenu/ITransitionScript.cpp | 2 +- game/mainmenu/MainMenuScene.cpp | 6 -- 8 files changed, 152 insertions(+), 105 deletions(-) (limited to 'game/GameScene.cpp') diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 3d692f8..ad42421 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -58,9 +58,8 @@ void GameScene::load_scene() { CoinSubScene coin; coin.create(*this); - // CoinSystem coin_system; - // coin_system.create_coins(*this); - // coin_system.add_location({900,0}); + CoinSystem coin_system; + coin_system.create_coins(*this); } diff --git a/game/coins/CoinSubScene.cpp b/game/coins/CoinSubScene.cpp index 12ddb7a..97f5877 100644 --- a/game/coins/CoinSubScene.cpp +++ b/game/coins/CoinSubScene.cpp @@ -5,6 +5,7 @@ #include "api/Scene.h" #include "api/AudioSource.h" #include +#include using namespace crepe; using namespace std; @@ -13,10 +14,10 @@ int CoinSubScene::create(Scene & scn){ vec2 size = {20, 20}; static int coin_counter = 0; - std::string unique_name = "coin_" + std::to_string(coin_counter++); + string unique_name = "coin_" + to_string(coin_counter++); + cout << "new coin: "<< unique_name << endl; - - GameObject coin = scn.new_object(unique_name.c_str(),"coin",vec2{0,0},0,1); + GameObject coin = scn.new_object(unique_name.c_str(),"coin",vec2{650,0},0,1); coin.add_component(Rigidbody::Data{}); coin.add_component(size.x / 2).active = false; crepe::OptionalRef coin_sprite = coin.add_component(Asset{"asset/coin/coin1_TVOS.png"}, Sprite::Data{ @@ -24,7 +25,7 @@ int CoinSubScene::create(Scene & scn){ .order_in_layer = 100, .size = size, }); - // coin_sprite->active = false; + coin_sprite->active = false; coin.add_component(coin_sprite, ivec2{32, 32}, uvec2{8, 1}, Animator::Data{ .fps = 15, diff --git a/game/coins/CoinSystem.cpp b/game/coins/CoinSystem.cpp index 4474195..60d558b 100644 --- a/game/coins/CoinSystem.cpp +++ b/game/coins/CoinSystem.cpp @@ -1,81 +1,10 @@ #include "CoinSystem.h" #include "CoinSubScene.h" -#include "api/CircleCollider.h" -#include "api/Metadata.h" -#include "api/Script.h" -#include "api/Sprite.h" -#include "api/Transform.h" -#include "types.h" using namespace crepe; using namespace std; -std::vector CoinSystem::coin_locations; - void CoinSystem::create_coins(crepe::Scene & scn) { CoinSubScene coin; while(coin.create(scn) < this->MAXIMUM_AMOUNT); } - -void CoinSystem::add_location(const crepe::vec2& location){ - coin_locations.push_back(CoinData(location)); -} - -void CoinSystem::remove_location(const std::string& name){ - auto it = std::find_if(coin_locations.begin(), coin_locations.end(), - [&name](const CoinData& data) { - return data.name == name; - }); - - // If a match is found, erase - if (it != coin_locations.end()) { - coin_locations.erase(it); - } -} - - -void CoinSystem::update(float position, RefVector coin_sprites, RefVector coin_colliders, RefVector coin_metadatas) { - for (auto& coin : coin_locations) { - if (!coin.active) { - if (coin.start_location.x > SPAWN_DISTANCE + position && coin.start_location.x < SPAWN_AREA + SPAWN_DISTANCE + position) { - - // Local variables to hold the matching coin data - Metadata* coin_metadata = nullptr; - CircleCollider* coin_collider = nullptr; - - // Iterate over the sprites to find the matching one - for (Sprite& coin_sprite : coin_sprites) { - if (!coin_sprite.active) { - // Find the matching Metadata - for (Metadata& coin_metadata_unkown : coin_metadatas) { - if (coin_metadata_unkown.game_object_id == coin_sprite.game_object_id) { - coin_metadata = &coin_metadata_unkown; - // No need to continue searching - break; - } - } - - // Find the matching CircleCollider - for (CircleCollider& coin_collider_unkown : coin_colliders) { - if (coin_collider_unkown.game_object_id == coin_sprite.game_object_id) { - coin_collider = &coin_collider_unkown; - // No need to continue searching - break; - } - } - - // If we found both the metadata and collider, activate the coin - if (coin_metadata && coin_collider) { - coin.name = coin_metadata->name; - coin.active = true; - coin_sprite.active = true; - coin_collider->active = true; - break; - } - } - } - } - } - } -} - diff --git a/game/coins/CoinSystem.h b/game/coins/CoinSystem.h index 93cbf98..31e72f1 100644 --- a/game/coins/CoinSystem.h +++ b/game/coins/CoinSystem.h @@ -1,22 +1,12 @@ #pragma once -#include "CoinData.h" #include "api/Scene.h" -#include "api/Script.h" -#include "api/Sprite.h" -#include "types.h" -#include -#include + class CoinSystem { public: void create_coins(crepe::Scene & scn); - void add_location(const crepe::vec2& location); - void remove_location(const std::string& name); - void update(float position,crepe::RefVector coin_sprites,crepe::RefVector coin_colliders,crepe::RefVector coin_metadatas); private: - static constexpr float SPAWN_DISTANCE = 200; - static constexpr float SPAWN_AREA = 50; static constexpr int MAXIMUM_AMOUNT = 100; - static std::vector coin_locations; }; + diff --git a/game/coins/CoinSystemScript.cpp b/game/coins/CoinSystemScript.cpp index 90405a8..da1fc65 100644 --- a/game/coins/CoinSystemScript.cpp +++ b/game/coins/CoinSystemScript.cpp @@ -2,17 +2,141 @@ #include "CoinSystem.h" #include "api/CircleCollider.h" #include "api/Metadata.h" +#include "api/Sprite.h" #include "api/Transform.h" using namespace crepe; using namespace std; -void CoinSystemScript::frame_update(crepe::duration_t dt) -{ +std::vector CoinSystemScript::coin_locations; + +void CoinSystemScript::init() { + this->add_location(vec2{1500,-30}); + this->add_location(vec2{1500,0}); + this->add_location(vec2{1500,30}); + this->add_location(vec2{1500,60}); + this->add_location(vec2{1550,-30}); + this->add_location(vec2{1550,0}); + this->add_location(vec2{1550,30}); + this->add_location(vec2{1550,60}); + + this->add_location(vec2{2500,-30}); + this->add_location(vec2{2500,0}); + this->add_location(vec2{2500,30}); + this->add_location(vec2{2500,60}); + this->add_location(vec2{2550,-30}); + this->add_location(vec2{2550,0}); + this->add_location(vec2{2550,30}); + this->add_location(vec2{2550,60}); + this->add_location(vec2{2600,-30}); + this->add_location(vec2{2600,0}); + this->add_location(vec2{2600,30}); + this->add_location(vec2{2600,60}); + this->add_location(vec2{2650,-30}); + this->add_location(vec2{2650,0}); + this->add_location(vec2{2650,30}); + this->add_location(vec2{2650,60}); + this->add_location(vec2{2700,-30}); + this->add_location(vec2{2700,0}); + this->add_location(vec2{2700,30}); + this->add_location(vec2{2700,60}); + this->add_location(vec2{2750,-30}); + this->add_location(vec2{2750,0}); + this->add_location(vec2{2750,30}); + this->add_location(vec2{2750,60}); + this->add_location(vec2{2800,-30}); + this->add_location(vec2{2800,0}); + this->add_location(vec2{2800,30}); + this->add_location(vec2{2800,60}); + this->add_location(vec2{2850,-30}); + this->add_location(vec2{2850,0}); + this->add_location(vec2{2850,30}); + this->add_location(vec2{2850,60}); +} + +void CoinSystemScript::add_location(const crepe::vec2& location){ + coin_locations.push_back(CoinData(location)); +} + +void CoinSystemScript::despawn_coins() { + // Get the current x-position of the CoinSystem's Transform component float position = this->get_component().position.x; + + // Retrieve all active coin sprites tagged as "coin" RefVector coin_sprites = this->get_components_by_tag("coin"); - RefVector coin_colliders = this->get_components_by_tag("coin"); - RefVector coin_metadatas = this->get_components_by_tag("coin"); - this->coin_system.update(position, coin_sprites, coin_colliders, coin_metadatas); + + for (Sprite& coin_sprite : coin_sprites) { + if (!coin_sprite.active) continue; // Skip inactive sprites + + // Retrieve the corresponding Transform, Metadata, and CircleCollider components + Transform& coin_transform = this->get_components_by_id(coin_sprite.game_object_id).front().get(); + Metadata& coin_metadata = this->get_components_by_id(coin_sprite.game_object_id).front().get(); + CircleCollider& coin_collider = this->get_components_by_id(coin_sprite.game_object_id).front().get(); + + // Check if the coin is out of bounds based on DESPAWN_DISTANCE + if (coin_transform.position.x < position - this->DESPAWN_DISTANCE) { + // Find the coin in the coin_locations vector using its name + auto it = std::find_if( + coin_locations.begin(), + coin_locations.end(), + [&coin_metadata](const CoinData& data) { + return data.name == coin_metadata.name; + } + ); + + // If a match is found, erase it from coin_locations + if (it != coin_locations.end()) { + coin_locations.erase(it); + coin_sprite.active = false; + coin_collider.active = false; + } + } + } } +void CoinSystemScript::spawn_coins(){ + // Get the current x-position of the CoinSystem's Transform component + float position = this->get_component().position.x; + + // Iterate through the list of coin locations + for (auto& coin : coin_locations) { + // Skip this coin if it is already active + if (coin.active)continue; + // Skip this coin if it is not within the defined spawn area + if (coin.start_location.x < this->SPAWN_DISTANCE + position || coin.start_location.x > this->SPAWN_AREA + this->SPAWN_DISTANCE + position) continue; + + // Retrieve all sprites tagged as "coin" + RefVector coin_sprites = this->get_components_by_tag("coin"); + + // Check for an available (inactive) coin sprite + for (Sprite& coin_sprite : coin_sprites) { + // Skip this sprite if it is already active + if (coin_sprite.active) continue; + + // Found an available (inactive) coin sprite + // Retrieve its associated components + Transform & coin_transform = this->get_components_by_id(coin_sprite.game_object_id).front().get(); + Metadata & coin_metadata = this->get_components_by_id(coin_sprite.game_object_id).front().get(); + CircleCollider & coin_collider = this->get_components_by_id(coin_sprite.game_object_id).front().get(); + + // Assign data and set active + coin.name = coin_metadata.name; + coin.active = true; + coin_sprite.active = true; + coin_collider.active = true; + coin_transform.position = coin.start_location; + + // Break out of the inner loop since we've assigned this coin to an available sprite + break; + } + } +} + +void CoinSystemScript::frame_update(crepe::duration_t dt) +{ + this->despawn_coins(); + this->spawn_coins(); +} + + + diff --git a/game/coins/CoinSystemScript.h b/game/coins/CoinSystemScript.h index 96744f1..6cf613a 100644 --- a/game/coins/CoinSystemScript.h +++ b/game/coins/CoinSystemScript.h @@ -1,13 +1,23 @@ #pragma once -#include "CoinSystem.h" +#include "CoinData.h" +#include "api/CircleCollider.h" #include "api/Script.h" +#include "api/Sprite.h" +#include "api/Transform.h" class CoinSystemScript : public crepe::Script { public: CoinSystemScript() {}; - // void init() override; + void init() override; void frame_update(crepe::duration_t dt) override; private: - CoinSystem coin_system; + void add_location(const crepe::vec2& location); + void despawn_coins(); + void spawn_coins(); +private: + static constexpr float SPAWN_DISTANCE = 400; + static constexpr float DESPAWN_DISTANCE = 400; + static constexpr float SPAWN_AREA = 50; + static std::vector coin_locations; }; diff --git a/game/mainmenu/ITransitionScript.cpp b/game/mainmenu/ITransitionScript.cpp index a7f5a0d..433f9f7 100644 --- a/game/mainmenu/ITransitionScript.cpp +++ b/game/mainmenu/ITransitionScript.cpp @@ -11,7 +11,7 @@ using namespace std; void ITransitionScript::frame_update(crepe::duration_t delta_time){ if(this->transition) { - cout << "transition:" << velocity << std::endl; + // cout << "transition:" << velocity << std::endl; Transform & cam = this->get_components_by_name(MainMenuConfig::CAMERA_NAME).front(); if(velocity < MainMenuConfig::VELOCITY_MAX && cam.position.x < MainMenuConfig::SLOW_DOWN) velocity += MainMenuConfig::VELOCITY_STEP * delta_time.count(); else if(velocity > 20) velocity -= MainMenuConfig::VELOCITY_STEP * delta_time.count(); diff --git a/game/mainmenu/MainMenuScene.cpp b/game/mainmenu/MainMenuScene.cpp index 472f190..80c945b 100644 --- a/game/mainmenu/MainMenuScene.cpp +++ b/game/mainmenu/MainMenuScene.cpp @@ -5,10 +5,8 @@ #include "api/BehaviorScript.h" #include "api/Camera.h" #include "../StartSubScene.h" -#include "../coins/CoinSubScene.h" #include "MainMenuConfig.h" #include "api/GameObject.h" -#include "api/Rigidbody.h" #include "api/Sprite.h" using namespace crepe; @@ -49,10 +47,6 @@ void MainMenuScene::load_scene(){ .position = pos, .script = ButtonSubScene::ScriptSelect::SHOP, }); - - CoinSubScene coin; - coin.create(*this); - coin.create(*this); //Start of map StartSubScene start; -- cgit v1.2.3 From 9afadbd2b2d2c5ec730154a426e83722e4c3da32 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Sat, 28 Dec 2024 19:34:07 +0100 Subject: renamed file --- game/GameScene.cpp | 4 ++-- game/coins/CoinPool.cpp | 10 ++++++++++ game/coins/CoinPool.h | 12 ++++++++++++ game/coins/CoinSystem.cpp | 10 ---------- game/coins/CoinSystem.h | 12 ------------ 5 files changed, 24 insertions(+), 24 deletions(-) create mode 100644 game/coins/CoinPool.cpp create mode 100644 game/coins/CoinPool.h delete mode 100644 game/coins/CoinSystem.cpp delete mode 100644 game/coins/CoinSystem.h (limited to 'game/GameScene.cpp') diff --git a/game/GameScene.cpp b/game/GameScene.cpp index ad42421..bb64d08 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -4,7 +4,7 @@ #include "PlayerSubScene.h" #include "StartGameScript.h" #include "coins/CoinSubScene.h" -#include "coins/CoinSystem.h" +#include "coins/CoinPool.h" #include "coins/CoinSystemScript.h" #include @@ -58,7 +58,7 @@ void GameScene::load_scene() { CoinSubScene coin; coin.create(*this); - CoinSystem coin_system; + CoinPool coin_system; coin_system.create_coins(*this); } diff --git a/game/coins/CoinPool.cpp b/game/coins/CoinPool.cpp new file mode 100644 index 0000000..5720c2f --- /dev/null +++ b/game/coins/CoinPool.cpp @@ -0,0 +1,10 @@ +#include "CoinPool.h" +#include "CoinSubScene.h" + +using namespace crepe; +using namespace std; + +void CoinPool::create_coins(crepe::Scene & scn) { + CoinSubScene coin; + while(coin.create(scn) < this->MAXIMUM_AMOUNT); +} diff --git a/game/coins/CoinPool.h b/game/coins/CoinPool.h new file mode 100644 index 0000000..83058f7 --- /dev/null +++ b/game/coins/CoinPool.h @@ -0,0 +1,12 @@ +#pragma once + +#include "api/Scene.h" + + +class CoinPool { +public: + void create_coins(crepe::Scene & scn); +private: + static constexpr int MAXIMUM_AMOUNT = 100; +}; + diff --git a/game/coins/CoinSystem.cpp b/game/coins/CoinSystem.cpp deleted file mode 100644 index 60d558b..0000000 --- a/game/coins/CoinSystem.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "CoinSystem.h" -#include "CoinSubScene.h" - -using namespace crepe; -using namespace std; - -void CoinSystem::create_coins(crepe::Scene & scn) { - CoinSubScene coin; - while(coin.create(scn) < this->MAXIMUM_AMOUNT); -} diff --git a/game/coins/CoinSystem.h b/game/coins/CoinSystem.h deleted file mode 100644 index 31e72f1..0000000 --- a/game/coins/CoinSystem.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "api/Scene.h" - - -class CoinSystem { -public: - void create_coins(crepe::Scene & scn); -private: - static constexpr int MAXIMUM_AMOUNT = 100; -}; - -- cgit v1.2.3 From ba170d00586ab261e015cc2febbb43f9aa7ae43e Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Sun, 5 Jan 2025 14:26:19 +0100 Subject: added hud --- game/CMakeLists.txt | 2 ++ game/Config.h | 20 ++++++++++++++++++++ game/GameScene.cpp | 10 +++++++--- game/coins/CoinScript.cpp | 5 +++-- game/coins/CoinScript.h | 2 -- game/hud/HudConfig.h | 28 ++++++++++++++++++++++++++++ game/hud/HudScript.cpp | 33 +++++++++++++++++++++++++++++++++ game/hud/HudScript.h | 12 ++++++++++++ game/hud/HudSubScene.cpp | 35 +++++++++++++++++++++++++++++++++++ game/hud/HudSubScene.h | 8 ++++++++ game/mainmenu/BannerSubScene.cpp | 5 +++-- game/mainmenu/ButtonSubScene.cpp | 5 +++-- game/mainmenu/MainMenuConfig.h | 5 +---- game/mainmenu/MainMenuScene.cpp | 3 ++- 14 files changed, 157 insertions(+), 16 deletions(-) create mode 100644 game/hud/HudConfig.h create mode 100644 game/hud/HudScript.cpp create mode 100644 game/hud/HudScript.h create mode 100644 game/hud/HudSubScene.cpp create mode 100644 game/hud/HudSubScene.h (limited to 'game/GameScene.cpp') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index ece2a40..50c9b4d 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -35,6 +35,8 @@ add_executable(main coins/CoinPool.cpp coins/CoinSystemScript.cpp coins/CoinScript.cpp + hud/HudSubScene.cpp + hud/HudScript.cpp ) target_link_libraries(main PUBLIC crepe) diff --git a/game/Config.h b/game/Config.h index ec753df..210326e 100644 --- a/game/Config.h +++ b/game/Config.h @@ -1,4 +1,5 @@ #pragma once +#include "types.h" static constexpr int SORT_IN_LAY_BACK_BACKGROUND = 3; // For all scenes static constexpr int SORT_IN_LAY_BACKGROUND = 4; // For all scenes @@ -19,3 +20,22 @@ 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 + +// Font settings +static constexpr const char* FONT = "Jetpackia"; +static constexpr crepe::vec2 FONTOFFSET = {0,0}; + +// Save data + +// Amount of coins in game +static constexpr const char* TOTAL_COINS_GAME = "total_coins_game"; + +// Amount of coins in current run +static constexpr const char* TOTAL_COINS_RUN = "total_coins_run"; + +// Distance +static constexpr const char* DISTANCE_GAME = "distance_game"; +static constexpr const char* DISTANCE_RUN = "distance_run"; + +// Global tags and names +static constexpr const char* PLAYER_NAME = "player"; diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 551f4f1..2073a1e 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -8,6 +8,8 @@ #include "coins/CoinSystemScript.h" #include "background/BackgroundSubScene.h" +#include "hud/HudScript.h" +#include "hud/HudSubScene.h" #include #include @@ -40,6 +42,7 @@ void GameScene::load_scene() { ); camera.add_component().set_script(); camera.add_component().set_script(); + camera.add_component().set_script(); camera.add_component(Rigidbody::Data{}); PlayerSubScene player(*this); @@ -71,12 +74,13 @@ void GameScene::load_scene() { GameObject start_game_script = new_object("start_game_script", "script", vec2(0, 0)); start_game_script.add_component().set_script(); - CoinSubScene coin; - coin.create(*this); - + //create coin pool CoinPool coin_system; coin_system.create_coins(*this); + HudSubScene hud; + hud.create(*this); + } string GameScene::get_name() const { return "scene1"; } diff --git a/game/coins/CoinScript.cpp b/game/coins/CoinScript.cpp index 862e7f9..5a1e922 100644 --- a/game/coins/CoinScript.cpp +++ b/game/coins/CoinScript.cpp @@ -2,6 +2,7 @@ #include "api/CircleCollider.h" #include "api/Sprite.h" #include "manager/SaveManager.h" +#include "../Config.h" using namespace crepe; using namespace std; @@ -12,8 +13,8 @@ bool CoinScript::on_collision(const CollisionEvent & collisionData){ this->get_component().active = false; this->get_component().active = false; SaveManager & savemgr = this->get_save_manager(); - int amount = savemgr.get(COIN_GAME_AMOUNT,0).get() + 1; - savemgr.set(COIN_GAME_AMOUNT, amount); + int amount = savemgr.get(TOTAL_COINS_RUN,0).get() + 1; + savemgr.set(TOTAL_COINS_RUN, amount); return true; } diff --git a/game/coins/CoinScript.h b/game/coins/CoinScript.h index 3fcee6d..96e54fa 100644 --- a/game/coins/CoinScript.h +++ b/game/coins/CoinScript.h @@ -6,6 +6,4 @@ class CoinScript : public crepe::Script { public: void init() override; bool on_collision(const crepe::CollisionEvent & collisionData); - static constexpr const char* PLAYER_NAME = "player"; - static constexpr const char* COIN_GAME_AMOUNT = "coin_game_amount"; }; diff --git a/game/hud/HudConfig.h b/game/hud/HudConfig.h new file mode 100644 index 0000000..91e3bfa --- /dev/null +++ b/game/hud/HudConfig.h @@ -0,0 +1,28 @@ +#pragma once +#include "types.h" + +static constexpr crepe::vec2 TOP_LEFT = {-500,-380}; +static constexpr const char* HUD_DISTANCE = "hud_distance"; +static constexpr const char* HUD_BEST = "hud_best"; +static constexpr const char* HUD_COINS = "hud_coins"; + +// Distance +static constexpr const char* DISTANCE_PLACEHOLDER = "0000m"; +static constexpr const char* DISTANCE_UNIT = "m"; +static constexpr int DISTANCE_LENGTH = 5; +static constexpr float DISTANCE_WIDTH = 60; +static constexpr float STEP_SIZE_DISTANCE = 100; + +// BEST +static constexpr const char* BEST = "BEST:"; +static constexpr int BEST_LENGTH = 5; +static constexpr float BEST_WIDTH = 40; +static constexpr crepe::vec2 BEST_OFFSET = {0,25}; + +// COINS +static constexpr const char* COINS = "0000"; +static constexpr int COINS_LENGTH = 4; +static constexpr float COINS_WIDTH = 40; +static constexpr crepe::vec2 COINS_OFFSET = {0,50}; + + \ No newline at end of file diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp new file mode 100644 index 0000000..42ff118 --- /dev/null +++ b/game/hud/HudScript.cpp @@ -0,0 +1,33 @@ +#include "HudScript.h" +#include "api/Text.h" +#include "api/Transform.h" +#include "manager/SaveManager.h" +#include "../Config.h" +#include "HudConfig.h" + +using namespace crepe; +using namespace std; + +void HudScript::init() { + savemgr = &this->get_save_manager(); + savemgr->set(TOTAL_COINS_RUN,0); + Text & txt = this->get_components_by_name(HUD_BEST).front(); + string record = BEST+to_string(savemgr->get(DISTANCE_GAME,0).get())+DISTANCE_UNIT; + txt.text = record; +} + +void HudScript::frame_update(crepe::duration_t dt) { + + // string number = std::to_string(savemgr->get(DISTANCE_RUN,0).get()); + + // Distance + Text & txt_dt = this->get_components_by_name(HUD_DISTANCE).front(); + Transform & tf = this->get_components_by_name(PLAYER_NAME).front(); + string distance = to_string(static_cast(tf.position.x/STEP_SIZE_DISTANCE)) + DISTANCE_UNIT; + txt_dt.text = distance; + + // Coins + Text & txt_co = this->get_components_by_name(HUD_COINS).front(); + string amount_of_coins = to_string(savemgr->get(TOTAL_COINS_RUN,0).get()); + txt_co.text = amount_of_coins; +} diff --git a/game/hud/HudScript.h b/game/hud/HudScript.h new file mode 100644 index 0000000..aa92582 --- /dev/null +++ b/game/hud/HudScript.h @@ -0,0 +1,12 @@ +#pragma once + +#include "api/Script.h" +#include "manager/SaveManager.h" + +class HudScript : public crepe::Script { +public: + void init() override; + void frame_update(crepe::duration_t dt) override; +private: + crepe::SaveManager* savemgr; +}; diff --git a/game/hud/HudSubScene.cpp b/game/hud/HudSubScene.cpp new file mode 100644 index 0000000..e76623d --- /dev/null +++ b/game/hud/HudSubScene.cpp @@ -0,0 +1,35 @@ +#include "HudSubScene.h" +#include "api/GameObject.h" +#include "api/Text.h" +#include "../Config.h" +#include "HudConfig.h" + +using namespace crepe; +using namespace std; + +void HudSubScene::create(Scene & scn){ + + // Distance + GameObject hud_dis = scn.new_object(HUD_DISTANCE); + crepe::vec2 size_distance = {DISTANCE_WIDTH,(DISTANCE_WIDTH/DISTANCE_LENGTH)*2}; + hud_dis.add_component(size_distance, FONT,Text::Data{ + .world_space = false, + .text_color = Color::WHITE, + }, TOP_LEFT+FONTOFFSET, DISTANCE_PLACEHOLDER); + + // Best + GameObject hud_best = scn.new_object(HUD_BEST); + crepe::vec2 size_best = {BEST_WIDTH,(BEST_WIDTH/BEST_LENGTH)*2}; + hud_best.add_component(size_best, FONT,Text::Data{ + .world_space = false, + .text_color = Color::WHITE, + }, TOP_LEFT+FONTOFFSET+BEST_OFFSET, BEST); + + // Coins + GameObject hud_coin = scn.new_object(HUD_COINS); + crepe::vec2 size = {COINS_WIDTH,(COINS_WIDTH/COINS_LENGTH)*2}; + hud_coin.add_component(size, FONT,Text::Data{ + .world_space = false, + .text_color = Color::WHITE, + }, TOP_LEFT+FONTOFFSET+COINS_OFFSET, COINS); +} diff --git a/game/hud/HudSubScene.h b/game/hud/HudSubScene.h new file mode 100644 index 0000000..711a34d --- /dev/null +++ b/game/hud/HudSubScene.h @@ -0,0 +1,8 @@ +#pragma once + +#include "api/Scene.h" +class HudSubScene +{ +public: + void create(crepe::Scene & scn); +}; diff --git a/game/mainmenu/BannerSubScene.cpp b/game/mainmenu/BannerSubScene.cpp index ba4c126..0659d96 100644 --- a/game/mainmenu/BannerSubScene.cpp +++ b/game/mainmenu/BannerSubScene.cpp @@ -1,5 +1,6 @@ #include "BannerSubScene.h" #include "MainMenuConfig.h" +#include "../Config.h" #include @@ -33,9 +34,9 @@ void BannerSubScene::create(Scene & scn,const Data & data){ }); crepe::vec2 size = {data.banner_title_width,(data.banner_title_width/data.banner_title.size())*2}; - menu_banner.add_component( size, MainMenuConfig::FONT, Text::Data{ + menu_banner.add_component( size, FONT, Text::Data{ .world_space = true, .text_color = Color::WHITE, - }, data.banner_title_offset + MainMenuConfig::FONTOFFSET, data.banner_title); + }, data.banner_title_offset + FONTOFFSET, data.banner_title); } diff --git a/game/mainmenu/ButtonSubScene.cpp b/game/mainmenu/ButtonSubScene.cpp index 53ac8d0..760fc0d 100644 --- a/game/mainmenu/ButtonSubScene.cpp +++ b/game/mainmenu/ButtonSubScene.cpp @@ -4,6 +4,7 @@ #include "ButtonTransitionPreviewScript.h" #include "IButtonScript.h" #include "MainMenuConfig.h" +#include "../Config.h" #include "api/Color.h" #include @@ -26,10 +27,10 @@ void ButtonSubScene::create(Scene & scn,const Data & data){ void ButtonSubScene::btn_text(crepe::GameObject & button_object,const Data & data){ crepe::vec2 size = {data.text_width,(data.text_width/data.text.size())*2}; - button_object.add_component(size, MainMenuConfig::FONT,Text::Data{ + button_object.add_component(size, FONT,Text::Data{ .world_space = data.worldspace, .text_color = Color::WHITE, - }, data.text_offset+MainMenuConfig::FONTOFFSET, data.text); + }, data.text_offset+FONTOFFSET, data.text); } void ButtonSubScene::set_script(crepe::GameObject & button_object,const Data & data){ diff --git a/game/mainmenu/MainMenuConfig.h b/game/mainmenu/MainMenuConfig.h index 99d29e8..0ce5980 100644 --- a/game/mainmenu/MainMenuConfig.h +++ b/game/mainmenu/MainMenuConfig.h @@ -29,14 +29,11 @@ struct MainMenuConfig { static constexpr float VELOCITY_STEP = 200; static constexpr float VELOCITY_INFO_UP = 30; //button config - static constexpr const char* FONT = "Jetpackia"; - static constexpr crepe::vec2 FONTOFFSET = {0,0}; static constexpr crepe::vec2 LARGE_OVERLAY_SIZE = {250,100}; static constexpr crepe::vec2 SMALL_OVERLAY_SIZE_RIGHT = {150,100}; static constexpr crepe::vec2 SMALL_OVERLAY_SIZE_LEFT = {50,100}; static constexpr crepe::vec2 SIDE_PANEL_SIZE = {50,150}; static constexpr crepe::vec2 ICON_SIZE = {50,50}; - //total coins (move to main config) - static constexpr const char* TOTAL_COINS = "total_coins"; + }; diff --git a/game/mainmenu/MainMenuScene.cpp b/game/mainmenu/MainMenuScene.cpp index e68696b..c2306b1 100644 --- a/game/mainmenu/MainMenuScene.cpp +++ b/game/mainmenu/MainMenuScene.cpp @@ -9,6 +9,7 @@ #include "api/GameObject.h" #include "api/Sprite.h" #include "manager/SaveManager.h" +#include "../Config.h" using namespace crepe; using namespace std; @@ -71,7 +72,7 @@ void MainMenuScene::load_scene(){ .world_space = false, }); SaveManager & savemgr = this->get_save_manager(); - std::string number = std::to_string(savemgr.get(MainMenuConfig::TOTAL_COINS,123).get()); + string number = std::to_string(savemgr.get(TOTAL_COINS_GAME,0).get()); float amount_number = static_cast(number.size()); // savemgr.set(COIN_GAME_AMOUNT, amount); button.create(*this,ButtonSubScene::Data{ -- cgit v1.2.3 From 2726785d64aa117aff0791d4591046c442709aac Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Sun, 5 Jan 2025 16:36:38 +0100 Subject: improved hud --- game/CMakeLists.txt | 1 + game/GameScene.cpp | 3 +++ game/hud/HudConfig.h | 8 ++++---- game/hud/HudScript.cpp | 7 +++++++ game/hud/HudSubScene.cpp | 17 +++++++++-------- game/hud/SpeedScript.cpp | 28 ++++++++++++++++++++++++++++ game/hud/SpeedScript.h | 13 +++++++++++++ 7 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 game/hud/SpeedScript.cpp create mode 100644 game/hud/SpeedScript.h (limited to 'game/GameScene.cpp') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 50c9b4d..e14e132 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -37,6 +37,7 @@ add_executable(main coins/CoinScript.cpp hud/HudSubScene.cpp hud/HudScript.cpp + hud/SpeedScript.cpp ) target_link_libraries(main PUBLIC crepe) diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 2073a1e..57cb8c4 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -10,6 +10,7 @@ #include "background/BackgroundSubScene.h" #include "hud/HudScript.h" #include "hud/HudSubScene.h" +#include "hud/SpeedScript.h" #include #include @@ -43,6 +44,8 @@ void GameScene::load_scene() { camera.add_component().set_script(); camera.add_component().set_script(); camera.add_component().set_script(); + camera.add_component().set_script(); + camera.add_component(Rigidbody::Data{}); PlayerSubScene player(*this); diff --git a/game/hud/HudConfig.h b/game/hud/HudConfig.h index 91e3bfa..983a557 100644 --- a/game/hud/HudConfig.h +++ b/game/hud/HudConfig.h @@ -1,7 +1,7 @@ #pragma once #include "types.h" -static constexpr crepe::vec2 TOP_LEFT = {-500,-380}; +static constexpr crepe::vec2 TOP_LEFT = {-530,-380}; static constexpr const char* HUD_DISTANCE = "hud_distance"; static constexpr const char* HUD_BEST = "hud_best"; static constexpr const char* HUD_COINS = "hud_coins"; @@ -10,19 +10,19 @@ static constexpr const char* HUD_COINS = "hud_coins"; static constexpr const char* DISTANCE_PLACEHOLDER = "0000m"; static constexpr const char* DISTANCE_UNIT = "m"; static constexpr int DISTANCE_LENGTH = 5; -static constexpr float DISTANCE_WIDTH = 60; +static constexpr float DISTANCE_CHAR_WIDTH = 12; static constexpr float STEP_SIZE_DISTANCE = 100; // BEST static constexpr const char* BEST = "BEST:"; static constexpr int BEST_LENGTH = 5; -static constexpr float BEST_WIDTH = 40; +static constexpr float BEST_CHAR_WIDTH = 10; static constexpr crepe::vec2 BEST_OFFSET = {0,25}; // COINS static constexpr const char* COINS = "0000"; static constexpr int COINS_LENGTH = 4; -static constexpr float COINS_WIDTH = 40; +static constexpr float COINS_CHAR_WIDTH = 10; static constexpr crepe::vec2 COINS_OFFSET = {0,50}; \ No newline at end of file diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp index 42ff118..deeea14 100644 --- a/game/hud/HudScript.cpp +++ b/game/hud/HudScript.cpp @@ -4,6 +4,7 @@ #include "manager/SaveManager.h" #include "../Config.h" #include "HudConfig.h" +#include using namespace crepe; using namespace std; @@ -14,6 +15,8 @@ void HudScript::init() { Text & txt = this->get_components_by_name(HUD_BEST).front(); string record = BEST+to_string(savemgr->get(DISTANCE_GAME,0).get())+DISTANCE_UNIT; txt.text = record; + txt.dimensions = {BEST_CHAR_WIDTH*record.size(),(BEST_CHAR_WIDTH)*2}; + txt.offset = TOP_LEFT+FONTOFFSET+BEST_OFFSET + vec2{record.size() * BEST_CHAR_WIDTH/2,0}; } void HudScript::frame_update(crepe::duration_t dt) { @@ -25,9 +28,13 @@ void HudScript::frame_update(crepe::duration_t dt) { Transform & tf = this->get_components_by_name(PLAYER_NAME).front(); string distance = to_string(static_cast(tf.position.x/STEP_SIZE_DISTANCE)) + DISTANCE_UNIT; txt_dt.text = distance; + txt_dt.dimensions = {DISTANCE_CHAR_WIDTH*distance.size(),(DISTANCE_CHAR_WIDTH)*2}; + txt_dt.offset = TOP_LEFT+FONTOFFSET + vec2{distance.size() * DISTANCE_CHAR_WIDTH/2,0}; // Coins Text & txt_co = this->get_components_by_name(HUD_COINS).front(); string amount_of_coins = to_string(savemgr->get(TOTAL_COINS_RUN,0).get()); txt_co.text = amount_of_coins; + txt_co.dimensions = {COINS_CHAR_WIDTH*amount_of_coins.size(),(COINS_CHAR_WIDTH)*2}; + txt_co.offset = TOP_LEFT+FONTOFFSET+COINS_OFFSET + vec2{amount_of_coins.size() * COINS_CHAR_WIDTH/2,0}; } diff --git a/game/hud/HudSubScene.cpp b/game/hud/HudSubScene.cpp index e76623d..126f933 100644 --- a/game/hud/HudSubScene.cpp +++ b/game/hud/HudSubScene.cpp @@ -11,25 +11,26 @@ void HudSubScene::create(Scene & scn){ // Distance GameObject hud_dis = scn.new_object(HUD_DISTANCE); - crepe::vec2 size_distance = {DISTANCE_WIDTH,(DISTANCE_WIDTH/DISTANCE_LENGTH)*2}; + + crepe::vec2 size_distance = {DISTANCE_CHAR_WIDTH*DISTANCE_LENGTH,(DISTANCE_CHAR_WIDTH)*2}; hud_dis.add_component(size_distance, FONT,Text::Data{ .world_space = false, .text_color = Color::WHITE, - }, TOP_LEFT+FONTOFFSET, DISTANCE_PLACEHOLDER); + }, TOP_LEFT+FONTOFFSET + vec2{DISTANCE_LENGTH * DISTANCE_CHAR_WIDTH/2,0}, DISTANCE_PLACEHOLDER); // Best GameObject hud_best = scn.new_object(HUD_BEST); - crepe::vec2 size_best = {BEST_WIDTH,(BEST_WIDTH/BEST_LENGTH)*2}; + crepe::vec2 size_best = {BEST_CHAR_WIDTH*BEST_LENGTH,(BEST_CHAR_WIDTH)*2}; hud_best.add_component(size_best, FONT,Text::Data{ .world_space = false, - .text_color = Color::WHITE, - }, TOP_LEFT+FONTOFFSET+BEST_OFFSET, BEST); + .text_color = Color::GREY, + }, TOP_LEFT+FONTOFFSET+BEST_OFFSET + vec2{BEST_LENGTH * BEST_CHAR_WIDTH/2,0}, BEST); // Coins GameObject hud_coin = scn.new_object(HUD_COINS); - crepe::vec2 size = {COINS_WIDTH,(COINS_WIDTH/COINS_LENGTH)*2}; + crepe::vec2 size = {COINS_CHAR_WIDTH*COINS_LENGTH,(COINS_CHAR_WIDTH)*2}; hud_coin.add_component(size, FONT,Text::Data{ .world_space = false, - .text_color = Color::WHITE, - }, TOP_LEFT+FONTOFFSET+COINS_OFFSET, COINS); + .text_color = Color::YELLOW, + }, TOP_LEFT+FONTOFFSET+COINS_OFFSET + vec2{COINS_LENGTH * COINS_CHAR_WIDTH/2,0}, COINS); } diff --git a/game/hud/SpeedScript.cpp b/game/hud/SpeedScript.cpp new file mode 100644 index 0000000..c0d927c --- /dev/null +++ b/game/hud/SpeedScript.cpp @@ -0,0 +1,28 @@ +#include "SpeedScript.h" +#include "api/KeyCodes.h" +#include "manager/LoopTimerManager.h" + +using namespace crepe; +using namespace std; + +void SpeedScript::fixed_update(crepe::duration_t dt){ + LoopTimerManager & lp = this->get_loop_timer(); + if(this->get_key_state(Keycode::HOME)){ + if(toggle) + { + this->timescale = lp.get_time_scale(); + lp.set_time_scale(0); + toggle = false; + } + else { + lp.set_time_scale(this->timescale); + toggle = true; + } + } + if(this->get_key_state(Keycode::PAGE_UP)){ + lp.set_time_scale(lp.get_time_scale()+0.1); + } + if(this->get_key_state(Keycode::PAGE_DOWN)){ + lp.set_time_scale(lp.get_time_scale()-0.1); + } +} diff --git a/game/hud/SpeedScript.h b/game/hud/SpeedScript.h new file mode 100644 index 0000000..1cc4368 --- /dev/null +++ b/game/hud/SpeedScript.h @@ -0,0 +1,13 @@ +#pragma once + +#include "api/Script.h" +#include "manager/SaveManager.h" + +class SpeedScript : public crepe::Script { +public: + void fixed_update(crepe::duration_t dt) override; +private: + crepe::SaveManager* savemgr; + bool toggle = true; + float timescale = 1; +}; -- cgit v1.2.3 From 126c402548281f3a97e3a9e0ef60c45147c87fa0 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Mon, 6 Jan 2025 20:52:39 +0100 Subject: endgamesubscene finished --- game/CMakeLists.txt | 1 + game/GameScene.cpp | 5 + game/coins/CoinSubScene.cpp | 3 - game/coins/CoinSystemScript.cpp | 6 +- game/menus/ButtonSubScene.cpp | 38 +++++-- game/menus/ButtonSubScene.h | 4 +- game/menus/FloatingWindowSubScene.cpp | 178 +++++++++++++++++++++++++++++ game/menus/FloatingWindowSubScene.h | 16 +++ game/menus/MenusConfig.h | 2 +- game/menus/endgame/EndGameSubScene.cpp | 199 ++++++++------------------------- game/menus/endgame/EndGameSubScene.h | 7 +- 11 files changed, 284 insertions(+), 175 deletions(-) create mode 100644 game/menus/FloatingWindowSubScene.cpp create mode 100644 game/menus/FloatingWindowSubScene.h (limited to 'game/GameScene.cpp') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 4c5bd53..9886973 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -27,6 +27,7 @@ add_executable(main menus/IButtonScript.cpp menus/ButtonSetShopScript.cpp menus/ButtonSetMainMenuScript.cpp + menus/FloatingWindowSubScene.cpp menus/shop/ShopMenuScene.cpp menus/mainmenu/ButtonTransitionPreviewScript.cpp menus/mainmenu/ITransitionScript.cpp diff --git a/game/GameScene.cpp b/game/GameScene.cpp index bd12d50..24b4287 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -10,6 +10,7 @@ #include "hud/HudScript.h" #include "hud/HudSubScene.h" #include "hud/SpeedScript.h" +#include "menus/endgame/EndGameSubScene.h" #include "player/PlayerSubScene.h" #include @@ -133,6 +134,10 @@ void GameScene::load_scene() { .collision_layer = COLL_LAY_MISSILE, }); missile.add_component(vec2(100, 100)); + + + EndGameSubScene test; + test.create(*this); } string GameScene::get_name() const { return "scene1"; } diff --git a/game/coins/CoinSubScene.cpp b/game/coins/CoinSubScene.cpp index 604af78..3914921 100644 --- a/game/coins/CoinSubScene.cpp +++ b/game/coins/CoinSubScene.cpp @@ -5,8 +5,6 @@ #include "api/Rigidbody.h" #include "api/Scene.h" #include "api/AudioSource.h" -#include -#include #include "CoinScript.h" #include "../Config.h" @@ -18,7 +16,6 @@ int CoinSubScene::create(Scene & scn){ static int coin_counter = 0; string unique_name = "coin_" + to_string(coin_counter++); - cout << "new coin: "<< unique_name << endl; GameObject coin = scn.new_object(unique_name.c_str(),"coin",vec2{650,0},0,1); coin.add_component(Rigidbody::Data{ diff --git a/game/coins/CoinSystemScript.cpp b/game/coins/CoinSystemScript.cpp index b77c597..c9c301e 100644 --- a/game/coins/CoinSystemScript.cpp +++ b/game/coins/CoinSystemScript.cpp @@ -5,7 +5,6 @@ #include "api/Sprite.h" #include "api/Transform.h" #include -#include "iostream" using namespace crepe; using namespace std; @@ -239,10 +238,7 @@ void CoinSystemScript::generate_locations(){ std::uniform_real_distribution space_dist(SPAWN_SPACING_MIN, SPAWN_SPACING_MAX); float spacing = space_dist(engine); - - - cout << "selected " << selected_index << std::endl; - cout << "spacing " << spacing << std::endl; + // Call the corresponding function and return the new x position this->system_position += functions[selected_index]({this->system_position,0}); this->system_position += spacing; diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index d735d08..8574b9b 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -56,7 +56,7 @@ void ButtonSubScene::set_icon(crepe::GameObject & button_object,const Data & dat switch (data.icon_type) { case IconSelect::SHOP: button_object.add_component(Asset("asset/ui/buttonCoinsSmall.png"),Sprite::Data{ - .sorting_in_layer = STARTING_SORTING_IN_LAYER+3, + .sorting_in_layer = STARTING_SORTING_IN_LAYER+3 + data.sorting_layer_offset, .size = ICON_SIZE, .position_offset = data.icon_offset, .world_space = data.worldspace, @@ -64,7 +64,7 @@ void ButtonSubScene::set_icon(crepe::GameObject & button_object,const Data & dat break; case IconSelect::COINS: button_object.add_component(Asset("asset/ui/buttonCoinsSmall.png"),Sprite::Data{ - .sorting_in_layer = STARTING_SORTING_IN_LAYER+3, + .sorting_in_layer = STARTING_SORTING_IN_LAYER+3 + data.sorting_layer_offset, .size = ICON_SIZE, .position_offset = data.icon_offset, .world_space = data.worldspace, @@ -81,17 +81,17 @@ void ButtonSubScene::set_button_overlay(crepe::GameObject & button_object,const this->large_btn_overlay(button_object,data); break; case ButtonSelect::BACK: - this->small_btn_overlay(button_object,data); + this->back_btn_overlay(button_object,data); break; case ButtonSelect::NEXT: - this->small_btn_overlay(button_object,data); + this->next_btn_overlay(button_object,data); break; } } void ButtonSubScene::large_btn_overlay(crepe::GameObject & button_object,const Data & data){ button_object.add_component(Asset("asset/ui/buttonBacking.png"),Sprite::Data{ - .sorting_in_layer = STARTING_SORTING_IN_LAYER+1, + .sorting_in_layer = STARTING_SORTING_IN_LAYER+1 + data.sorting_layer_offset, .size = LARGE_OVERLAY_SIZE, .world_space = data.worldspace, }); @@ -100,15 +100,15 @@ void ButtonSubScene::large_btn_overlay(crepe::GameObject & button_object,const D this->btn_color_side(button_object,SIDE_PANEL_OFFSET,data); } -void ButtonSubScene::small_btn_overlay(crepe::GameObject & button_object,const Data & data){ +void ButtonSubScene::back_btn_overlay(crepe::GameObject & button_object,const Data & data){ button_object.add_component(Asset("asset/ui/backbuttonright.png"),Sprite::Data{ - .sorting_in_layer = STARTING_SORTING_IN_LAYER+1, + .sorting_in_layer = STARTING_SORTING_IN_LAYER+1+ data.sorting_layer_offset, .size = SMALL_OVERLAY_SIZE_RIGHT, .position_offset = {20,0}, .world_space = data.worldspace, }); button_object.add_component(Asset("asset/ui/backbuttonleft.png"),Sprite::Data{ - .sorting_in_layer = STARTING_SORTING_IN_LAYER+1, + .sorting_in_layer = STARTING_SORTING_IN_LAYER+1+ data.sorting_layer_offset, .size = SMALL_OVERLAY_SIZE_LEFT, .position_offset = {-80,0}, .world_space = data.worldspace, @@ -116,16 +116,34 @@ void ButtonSubScene::small_btn_overlay(crepe::GameObject & button_object,const D button_object.add_component