From f18635b6c73f753bd38343684134430a5ce9b22c Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 3 Jan 2025 16:12:14 +0100 Subject: added coins random and menu banner update --- game/coins/CoinScript.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 game/coins/CoinScript.cpp (limited to 'game/coins/CoinScript.cpp') diff --git a/game/coins/CoinScript.cpp b/game/coins/CoinScript.cpp new file mode 100644 index 0000000..f067f04 --- /dev/null +++ b/game/coins/CoinScript.cpp @@ -0,0 +1,19 @@ +#include "CoinScript.h" +#include "api/CircleCollider.h" +#include "api/Sprite.h" + +using namespace crepe; +using namespace std; + +bool CoinScript::on_collision(const CollisionEvent & collisionData){ + if(collisionData.info.other.metadata.name != PLAYER_NAME) return true; + //collide with player + this->get_component().active = false; + this->get_component().active = false; + return true; +} + +void CoinScript::init(){ + subscribe([this](const CollisionEvent & ev) -> bool { return this->on_collision(ev); }); +} + -- cgit v1.2.3 From d65e0ff31a75230fd1c18eaeab9cb25ab2b9c82a Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 3 Jan 2025 16:36:43 +0100 Subject: save amount of coins --- game/coins/CoinScript.cpp | 4 ++++ game/coins/CoinScript.h | 1 + 2 files changed, 5 insertions(+) (limited to 'game/coins/CoinScript.cpp') diff --git a/game/coins/CoinScript.cpp b/game/coins/CoinScript.cpp index f067f04..862e7f9 100644 --- a/game/coins/CoinScript.cpp +++ b/game/coins/CoinScript.cpp @@ -1,6 +1,7 @@ #include "CoinScript.h" #include "api/CircleCollider.h" #include "api/Sprite.h" +#include "manager/SaveManager.h" using namespace crepe; using namespace std; @@ -10,6 +11,9 @@ bool CoinScript::on_collision(const CollisionEvent & collisionData){ //collide with player 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); return true; } diff --git a/game/coins/CoinScript.h b/game/coins/CoinScript.h index 6c52733..3fcee6d 100644 --- a/game/coins/CoinScript.h +++ b/game/coins/CoinScript.h @@ -7,4 +7,5 @@ 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"; }; -- 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/coins/CoinScript.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 07615060da6c211e08a3d7f2e1bb9e99ffc05364 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Mon, 6 Jan 2025 17:49:39 +0100 Subject: moved and updated files --- game/CMakeLists.txt | 20 ++-- game/coins/CoinData.h | 11 -- game/coins/CoinScript.cpp | 1 - game/coins/CoinSystemScript.cpp | 2 +- game/coins/CoinSystemScript.h | 10 +- game/main.cpp | 5 +- game/mainmenu/BannerSubScene.cpp | 42 ------- game/mainmenu/BannerSubScene.h | 19 --- game/mainmenu/ButtonSetMainMenuScript.cpp | 19 --- game/mainmenu/ButtonSetMainMenuScript.h | 14 --- game/mainmenu/ButtonSetShopScript.cpp | 19 --- game/mainmenu/ButtonSetShopScript.h | 14 --- game/mainmenu/ButtonSubScene.cpp | 128 --------------------- game/mainmenu/ButtonSubScene.h | 58 ---------- game/mainmenu/ButtonTransitionPreviewScript.cpp | 24 ---- game/mainmenu/ButtonTransitionPreviewScript.h | 11 -- game/mainmenu/IButtonScript.cpp | 33 ------ game/mainmenu/IButtonScript.h | 12 -- game/mainmenu/ITransitionScript.cpp | 31 ----- game/mainmenu/ITransitionScript.h | 13 --- game/mainmenu/MainMenuConfig.h | 39 ------- game/mainmenu/MainMenuScene.cpp | 98 ---------------- game/mainmenu/MainMenuScene.h | 11 -- game/mainmenu/ShopMenuScene.cpp | 44 ------- game/mainmenu/ShopMenuScene.h | 11 -- game/mainmenu/TransitionStartScript.cpp | 21 ---- game/mainmenu/TransitionStartScript.h | 10 -- game/menus/BannerSubScene.cpp | 42 +++++++ game/menus/BannerSubScene.h | 19 +++ game/menus/ButtonSetMainMenuScript.cpp | 19 +++ game/menus/ButtonSetMainMenuScript.h | 14 +++ game/menus/ButtonSetShopScript.cpp | 19 +++ game/menus/ButtonSetShopScript.h | 14 +++ game/menus/ButtonSubScene.cpp | 128 +++++++++++++++++++++ game/menus/ButtonSubScene.h | 57 +++++++++ game/menus/IButtonScript.cpp | 33 ++++++ game/menus/IButtonScript.h | 12 ++ game/menus/MenusConfig.h | 18 +++ .../mainmenu/ButtonTransitionPreviewScript.cpp | 24 ++++ .../menus/mainmenu/ButtonTransitionPreviewScript.h | 11 ++ game/menus/mainmenu/ITransitionScript.cpp | 30 +++++ game/menus/mainmenu/ITransitionScript.h | 13 +++ game/menus/mainmenu/MainMenuConfig.h | 22 ++++ game/menus/mainmenu/MainMenuScene.cpp | 99 ++++++++++++++++ game/menus/mainmenu/MainMenuScene.h | 11 ++ game/menus/mainmenu/TransitionStartScript.cpp | 20 ++++ game/menus/mainmenu/TransitionStartScript.h | 10 ++ game/menus/shop/ShopMenuScene.cpp | 44 +++++++ game/menus/shop/ShopMenuScene.h | 11 ++ 49 files changed, 693 insertions(+), 697 deletions(-) delete mode 100644 game/coins/CoinData.h delete mode 100644 game/mainmenu/BannerSubScene.cpp delete mode 100644 game/mainmenu/BannerSubScene.h delete mode 100644 game/mainmenu/ButtonSetMainMenuScript.cpp delete mode 100644 game/mainmenu/ButtonSetMainMenuScript.h delete mode 100644 game/mainmenu/ButtonSetShopScript.cpp delete mode 100644 game/mainmenu/ButtonSetShopScript.h delete mode 100644 game/mainmenu/ButtonSubScene.cpp delete mode 100644 game/mainmenu/ButtonSubScene.h delete mode 100644 game/mainmenu/ButtonTransitionPreviewScript.cpp delete mode 100644 game/mainmenu/ButtonTransitionPreviewScript.h delete mode 100644 game/mainmenu/IButtonScript.cpp delete mode 100644 game/mainmenu/IButtonScript.h delete mode 100644 game/mainmenu/ITransitionScript.cpp delete mode 100644 game/mainmenu/ITransitionScript.h delete mode 100644 game/mainmenu/MainMenuConfig.h delete mode 100644 game/mainmenu/MainMenuScene.cpp delete mode 100644 game/mainmenu/MainMenuScene.h delete mode 100644 game/mainmenu/ShopMenuScene.cpp delete mode 100644 game/mainmenu/ShopMenuScene.h delete mode 100644 game/mainmenu/TransitionStartScript.cpp delete mode 100644 game/mainmenu/TransitionStartScript.h create mode 100644 game/menus/BannerSubScene.cpp create mode 100644 game/menus/BannerSubScene.h create mode 100644 game/menus/ButtonSetMainMenuScript.cpp create mode 100644 game/menus/ButtonSetMainMenuScript.h create mode 100644 game/menus/ButtonSetShopScript.cpp create mode 100644 game/menus/ButtonSetShopScript.h create mode 100644 game/menus/ButtonSubScene.cpp create mode 100644 game/menus/ButtonSubScene.h create mode 100644 game/menus/IButtonScript.cpp create mode 100644 game/menus/IButtonScript.h create mode 100644 game/menus/MenusConfig.h create mode 100644 game/menus/mainmenu/ButtonTransitionPreviewScript.cpp create mode 100644 game/menus/mainmenu/ButtonTransitionPreviewScript.h create mode 100644 game/menus/mainmenu/ITransitionScript.cpp create mode 100644 game/menus/mainmenu/ITransitionScript.h create mode 100644 game/menus/mainmenu/MainMenuConfig.h create mode 100644 game/menus/mainmenu/MainMenuScene.cpp create mode 100644 game/menus/mainmenu/MainMenuScene.h create mode 100644 game/menus/mainmenu/TransitionStartScript.cpp create mode 100644 game/menus/mainmenu/TransitionStartScript.h create mode 100644 game/menus/shop/ShopMenuScene.cpp create mode 100644 game/menus/shop/ShopMenuScene.h (limited to 'game/coins/CoinScript.cpp') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index edc8a93..949312f 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -22,16 +22,16 @@ add_executable(main player/PlayerEndScript.cpp background/StartSubScene.cpp main.cpp - mainmenu/IButtonScript.cpp - mainmenu/ButtonSubScene.cpp - mainmenu/MainMenuScene.cpp - mainmenu/ITransitionScript.cpp - mainmenu/TransitionStartScript.cpp - mainmenu/ButtonTransitionPreviewScript.cpp - mainmenu/ShopMenuScene.cpp - mainmenu/BannerSubScene.cpp - mainmenu/ButtonSetShopScript.cpp - mainmenu/ButtonSetMainMenuScript.cpp + menus/BannerSubScene.cpp + menus/ButtonSubScene.cpp + menus/IButtonScript.cpp + menus/ButtonSetShopScript.cpp + menus/ButtonSetMainMenuScript.cpp + menus/shop/ShopMenuScene.cpp + menus/mainmenu/ButtonTransitionPreviewScript.cpp + menus/mainmenu/ITransitionScript.cpp + menus/mainmenu/MainMenuScene.cpp + menus/mainmenu/TransitionStartScript.cpp coins/CoinSubScene.cpp coins/CoinPool.cpp coins/CoinSystemScript.cpp diff --git a/game/coins/CoinData.h b/game/coins/CoinData.h deleted file mode 100644 index 09b3448..0000000 --- a/game/coins/CoinData.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "types.h" -#include - -struct CoinData{ - crepe::vec2 start_location = {0,0}; - std::string name = ""; - bool active = false; - CoinData(crepe::vec2 start_location) : start_location(start_location),name(""), active(false) {} -}; diff --git a/game/coins/CoinScript.cpp b/game/coins/CoinScript.cpp index 5a1e922..e40f658 100644 --- a/game/coins/CoinScript.cpp +++ b/game/coins/CoinScript.cpp @@ -9,7 +9,6 @@ using namespace std; bool CoinScript::on_collision(const CollisionEvent & collisionData){ if(collisionData.info.other.metadata.name != PLAYER_NAME) return true; - //collide with player this->get_component().active = false; this->get_component().active = false; SaveManager & savemgr = this->get_save_manager(); diff --git a/game/coins/CoinSystemScript.cpp b/game/coins/CoinSystemScript.cpp index 41b1d3d..b77c597 100644 --- a/game/coins/CoinSystemScript.cpp +++ b/game/coins/CoinSystemScript.cpp @@ -10,7 +10,7 @@ using namespace crepe; using namespace std; -std::vector CoinSystemScript::coin_locations; +std::vector CoinSystemScript::coin_locations; void CoinSystemScript::init() { engine.seed(rd()); diff --git a/game/coins/CoinSystemScript.h b/game/coins/CoinSystemScript.h index 4bafa01..f558f08 100644 --- a/game/coins/CoinSystemScript.h +++ b/game/coins/CoinSystemScript.h @@ -1,6 +1,7 @@ #pragma once -#include "CoinData.h" +#include "types.h" +#include #include "api/CircleCollider.h" #include "api/Script.h" #include "api/Sprite.h" @@ -8,6 +9,13 @@ #include class CoinSystemScript : public crepe::Script { +private: + struct CoinData{ + crepe::vec2 start_location = {0,0}; + std::string name = ""; + bool active = false; + CoinData(crepe::vec2 start_location) : start_location(start_location),name(""), active(false) {} + }; public: CoinSystemScript() {}; void init() override; diff --git a/game/main.cpp b/game/main.cpp index ddc596d..b9bebfb 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -2,8 +2,9 @@ #include #include "GameScene.h" -#include "mainmenu/MainMenuScene.h" -#include "mainmenu/ShopMenuScene.h" +#include "menus/mainmenu/MainMenuScene.h" +#include "menus/shop/ShopMenuScene.h" + using namespace crepe; diff --git a/game/mainmenu/BannerSubScene.cpp b/game/mainmenu/BannerSubScene.cpp deleted file mode 100644 index 0659d96..0000000 --- a/game/mainmenu/BannerSubScene.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "BannerSubScene.h" -#include "MainMenuConfig.h" -#include "../Config.h" - - -#include -#include -#include - -using namespace crepe; -using namespace std; - -void BannerSubScene::create(Scene & scn,const Data & data){ - GameObject menu_banner = scn.new_object("menu_banner","", {0,-414}); - menu_banner.add_component( - Asset("asset/ui/settings_container/top_middle_setting.png"), - Sprite::Data{ - .sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+1, - .size = {1100,88}, - }); - menu_banner.add_component( - Asset("asset/ui/settings_container/top_2_middle_setting.png"), - Sprite::Data{ - .sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+1, - .size = {1100,66}, - .position_offset {0,77}, - }); - menu_banner.add_component( - Asset("asset/ui/settings_container/banner_bottom.png"), - Sprite::Data{ - .sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+1, - .size = {1100,7}, - .position_offset {0,113}, - }); - crepe::vec2 size = {data.banner_title_width,(data.banner_title_width/data.banner_title.size())*2}; - - menu_banner.add_component( size, FONT, Text::Data{ - .world_space = true, - .text_color = Color::WHITE, - }, data.banner_title_offset + FONTOFFSET, data.banner_title); - -} diff --git a/game/mainmenu/BannerSubScene.h b/game/mainmenu/BannerSubScene.h deleted file mode 100644 index 341943d..0000000 --- a/game/mainmenu/BannerSubScene.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "types.h" -#include - -namespace crepe { -class Scene; -} - -class BannerSubScene { -public: -struct Data{ - const std::string & banner_title = "NODATA"; - const float banner_title_width = 100; - const crepe::vec2 & banner_title_offset = {0,0}; - }; -public: - void create(crepe::Scene & scn,const Data & data); -}; diff --git a/game/mainmenu/ButtonSetMainMenuScript.cpp b/game/mainmenu/ButtonSetMainMenuScript.cpp deleted file mode 100644 index 808d8a2..0000000 --- a/game/mainmenu/ButtonSetMainMenuScript.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "ButtonSetMainMenuScript.h" -#include "MainMenuConfig.h" -#include "iostream" - -using namespace crepe; -using namespace std; - -void ButtonSetMainMenuScript::init(){ - cout << "script init" << endl; - IButtonScript::init(); - this->subscribe([this](const ButtonPressEvent& e) { return this->on_button_press(e); }); -} - -bool ButtonSetMainMenuScript::on_button_press(const ButtonPressEvent& e){ - this->set_next_scene(MainMenuConfig::MAINMENU_SCENE); - cout << "Start triggered:" << e.metadata.game_object_id << std::endl; - return false; -} - diff --git a/game/mainmenu/ButtonSetMainMenuScript.h b/game/mainmenu/ButtonSetMainMenuScript.h deleted file mode 100644 index 44c21aa..0000000 --- a/game/mainmenu/ButtonSetMainMenuScript.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "IButtonScript.h" -#include - -class ButtonSetMainMenuScript : public IButtonScript { -public: - void init() override; - bool on_button_press(const crepe::ButtonPressEvent& e); -private: - float velocity = 20; -protected: - bool transition = false; -}; diff --git a/game/mainmenu/ButtonSetShopScript.cpp b/game/mainmenu/ButtonSetShopScript.cpp deleted file mode 100644 index 0c855ec..0000000 --- a/game/mainmenu/ButtonSetShopScript.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "ButtonSetShopScript.h" -#include "MainMenuConfig.h" -#include "iostream" - -using namespace crepe; -using namespace std; - -void ButtonSetShopScript::init(){ - cout << "script init" << endl; - IButtonScript::init(); - this->subscribe([this](const ButtonPressEvent& e) { return this->on_button_press(e); }); -} - -bool ButtonSetShopScript::on_button_press(const ButtonPressEvent& e){ - this->set_next_scene(MainMenuConfig::SHOP_SCENE); - cout << "Start triggered:" << e.metadata.game_object_id << std::endl; - return false; -} - diff --git a/game/mainmenu/ButtonSetShopScript.h b/game/mainmenu/ButtonSetShopScript.h deleted file mode 100644 index 51db928..0000000 --- a/game/mainmenu/ButtonSetShopScript.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "IButtonScript.h" -#include - -class ButtonSetShopScript : public IButtonScript { -public: - void init() override; - bool on_button_press(const crepe::ButtonPressEvent& e); -private: - float velocity = 20; -protected: - bool transition = false; -}; diff --git a/game/mainmenu/ButtonSubScene.cpp b/game/mainmenu/ButtonSubScene.cpp deleted file mode 100644 index 760fc0d..0000000 --- a/game/mainmenu/ButtonSubScene.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "ButtonSubScene.h" -#include "ButtonSetMainMenuScript.h" -#include "ButtonSetShopScript.h" -#include "ButtonTransitionPreviewScript.h" -#include "IButtonScript.h" -#include "MainMenuConfig.h" -#include "../Config.h" -#include "api/Color.h" - -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -void ButtonSubScene::create(Scene & scn,const Data & data){ - GameObject button_object = scn.new_object("button",data.tag,data.position,0,data.scale); - this->set_button_overlay(button_object,data); - this->btn_text(button_object,data); - this->set_script(button_object,data); - this->set_icon(button_object,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, FONT,Text::Data{ - .world_space = data.worldspace, - .text_color = Color::WHITE, - }, data.text_offset+FONTOFFSET, data.text); -} - -void ButtonSubScene::set_script(crepe::GameObject & button_object,const Data & data){ - switch (data.script_type) { - case ScriptSelect::PREVIEW: - button_object.add_component().set_script(); - break; - case ScriptSelect::SHOP: - button_object.add_component().set_script(); - break; - case ScriptSelect::MAINMENU: - button_object.add_component().set_script(); - break; - case ScriptSelect::NONE: - button_object.add_component().set_script(); - break; - } -} - -void ButtonSubScene::set_icon(crepe::GameObject & button_object,const Data & data){ - switch (data.icon_type) { - case IconSelect::SHOP: - button_object.add_component(Asset("asset/ui/buttonCoinsSmall.png"),Sprite::Data{ - .sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+3, - .size = MainMenuConfig::ICON_SIZE, - .position_offset = data.icon_offset, - .world_space = data.worldspace, - }); - break; - case IconSelect::COINS: - button_object.add_component(Asset("asset/ui/buttonCoinsSmall.png"),Sprite::Data{ - .sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+3, - .size = MainMenuConfig::ICON_SIZE, - .position_offset = data.icon_offset, - .world_space = data.worldspace, - }); - break; - case IconSelect::NONE: - break; - } -} - -void ButtonSubScene::set_button_overlay(crepe::GameObject & button_object,const Data & data){ - switch (data.button_type) { - case ButtonSelect::LARGE: - this->large_btn_overlay(button_object,data); - break; - case ButtonSelect::SMALL: - this->small_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 = MainMenuConfig::STARTING_SORTING_IN_LAYER+1, - .size = MainMenuConfig::LARGE_OVERLAY_SIZE, - .world_space = data.worldspace, - }); - button_object.add_component