From 30974f588816aa03652002111c6a946b138e3bc5 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 8 Jan 2025 19:47:31 +0100 Subject: replay in preview scene --- game/menus/ButtonSubScene.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'game/menus/ButtonSubScene.h') diff --git a/game/menus/ButtonSubScene.h b/game/menus/ButtonSubScene.h index 74f9464..29287b6 100644 --- a/game/menus/ButtonSubScene.h +++ b/game/menus/ButtonSubScene.h @@ -19,6 +19,9 @@ public: REPLAY, CREDITS_SHOW, CREDITS_BACK, + PREVIEW_START, + PREVIEW_STOP, + PREVIEW_REPLAY, NONE, }; //icon enum -- cgit v1.2.3 From 0a57018881fc530e18695ed3331482f432bb7750 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 8 Jan 2025 19:57:34 +0100 Subject: added color to button --- game/PreviewScene.cpp | 3 +++ game/menus/ButtonSubScene.cpp | 28 ++++++++++++++++++++++++++-- game/menus/ButtonSubScene.h | 9 +++++++++ game/menus/mainmenu/MainMenuScene.cpp | 3 +++ 4 files changed, 41 insertions(+), 2 deletions(-) (limited to 'game/menus/ButtonSubScene.h') diff --git a/game/PreviewScene.cpp b/game/PreviewScene.cpp index 0812c0d..6871961 100644 --- a/game/PreviewScene.cpp +++ b/game/PreviewScene.cpp @@ -124,6 +124,7 @@ void PreviewScene::load_scene() { .worldspace = false, .tag = "Next button", .sorting_layer_offset = 20, + .btn_side_color = ButtonSubScene::ButtonSideColor::YELLOW, } ); @@ -139,6 +140,7 @@ void PreviewScene::load_scene() { .worldspace = false, .tag = "Next button", .sorting_layer_offset = 20, + .btn_side_color = ButtonSubScene::ButtonSideColor::BLUE, } ); @@ -154,6 +156,7 @@ void PreviewScene::load_scene() { .worldspace = false, .tag = "Next button", .sorting_layer_offset = 20, + .btn_side_color = ButtonSubScene::ButtonSideColor::ORANGE, } ); diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index 2c912b7..436ff5f 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -10,6 +10,7 @@ #include "../preview/PreviewReplaySubScript.h" #include "../preview/PreviewStartRecSubScript.h" #include "../preview/PreviewStopRecSubScript.h" +#include "api/Asset.h" #include "mainmenu/ButtonTransitionPreviewSubScript.h" #include "../Config.h" @@ -211,8 +212,31 @@ void ButtonSubScene::next_btn_overlay(crepe::GameObject & button_object, const D void ButtonSubScene::btn_color_side( crepe::GameObject & button_object, const vec2 & offset, const Data & data ) { + Asset * selected; + Asset blue = Asset("asset/ui/buttonSmallBlue.png"); + Asset orange = Asset("asset/ui/buttonSmallOrange.png"); + Asset purple = Asset("asset/ui/buttonSmallPurple.png"); + Asset yellow = Asset("asset/ui/buttonSmallYellow.png"); + switch (data.btn_side_color) { + case ButtonSideColor::BLUE: + selected = &blue; + break; + case ButtonSideColor::ORANGE: + selected = &orange; + break; + case ButtonSideColor::PURPLE: + selected = &purple; + break; + case ButtonSideColor::YELLOW: + selected = &yellow; + break; + case ButtonSideColor::NONE: + selected = &blue; + break; + } + button_object.add_component( - Asset("asset/ui/buttonSmallBlue.png"), + *selected, Sprite::Data { .sorting_in_layer = STARTING_SORTING_IN_LAYER + 2 + data.sorting_layer_offset, .size = SIDE_PANEL_SIZE, @@ -221,7 +245,7 @@ void ButtonSubScene::btn_color_side( } ); button_object.add_component( - Asset("asset/ui/buttonSmallBlue.png"), + *selected, Sprite::Data { .flip = {true, false}, .sorting_in_layer = STARTING_SORTING_IN_LAYER + 2 + data.sorting_layer_offset, diff --git a/game/menus/ButtonSubScene.h b/game/menus/ButtonSubScene.h index 29287b6..8f086f0 100644 --- a/game/menus/ButtonSubScene.h +++ b/game/menus/ButtonSubScene.h @@ -36,6 +36,14 @@ public: NEXT, LARGE, }; + + enum class ButtonSideColor { + BLUE, + ORANGE, + PURPLE, + YELLOW, + NONE, + }; //data struct struct Data { const std::string & text = "NODATA"; @@ -51,6 +59,7 @@ public: const bool color_side = true; const std::string & tag = ""; const int sorting_layer_offset = 0; + const ButtonSideColor btn_side_color = ButtonSideColor::NONE; }; public: diff --git a/game/menus/mainmenu/MainMenuScene.cpp b/game/menus/mainmenu/MainMenuScene.cpp index fba90ac..ff94e74 100644 --- a/game/menus/mainmenu/MainMenuScene.cpp +++ b/game/menus/mainmenu/MainMenuScene.cpp @@ -55,6 +55,7 @@ void MainMenuScene::load_scene() { .text_width = 200, .position = pos_btn, .script_type = ButtonSubScene::ScriptSelect::PREVIEW, + .btn_side_color = ButtonSubScene::ButtonSideColor::PURPLE, } ); @@ -70,6 +71,7 @@ void MainMenuScene::load_scene() { .icon_type = ButtonSubScene::IconSelect::SHOP, .position = pos_btn, .script_type = ButtonSubScene::ScriptSelect::SHOP, + .btn_side_color = ButtonSubScene::ButtonSideColor::ORANGE, } ); @@ -83,6 +85,7 @@ void MainMenuScene::load_scene() { .text_width = 200, .position = pos_btn, .script_type = ButtonSubScene::ScriptSelect::CREDITS_SHOW, + .btn_side_color = ButtonSubScene::ButtonSideColor::BLUE, } ); -- cgit v1.2.3 From f6683fa71fa670cfbe6aa6233fafb869295da11a Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Thu, 9 Jan 2025 21:14:35 +0100 Subject: added shop functionality --- game/CMakeLists.txt | 3 + game/menus/ButtonSubScene.cpp | 10 ++ game/menus/ButtonSubScene.h | 2 + game/menus/shop/ButtonBuySelectBubbleScript.cpp | 36 +++++++ game/menus/shop/ButtonBuySelectBubbleScript.h | 14 +++ game/menus/shop/ButtonBuySelectBulletScript.cpp | 36 +++++++ game/menus/shop/ButtonBuySelectBulletScript.h | 14 +++ game/menus/shop/ShopLoadScript.cpp | 131 ++++++++++++++++++++++++ game/menus/shop/ShopLoadScript.h | 10 ++ game/menus/shop/ShopMenuScene.cpp | 103 +++++++++++++++++-- game/menus/shop/Shopconfig.h | 16 +++ 11 files changed, 366 insertions(+), 9 deletions(-) create mode 100644 game/menus/shop/ButtonBuySelectBubbleScript.cpp create mode 100644 game/menus/shop/ButtonBuySelectBubbleScript.h create mode 100644 game/menus/shop/ButtonBuySelectBulletScript.cpp create mode 100644 game/menus/shop/ButtonBuySelectBulletScript.h create mode 100644 game/menus/shop/ShopLoadScript.cpp create mode 100644 game/menus/shop/ShopLoadScript.h create mode 100644 game/menus/shop/Shopconfig.h (limited to 'game/menus/ButtonSubScene.h') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 9dfd2b4..1a03b20 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -33,6 +33,9 @@ target_sources(main PUBLIC # mainscenes GameScene.cpp menus/shop/ShopMenuScene.cpp + menus/shop/ShopLoadScript.cpp + menus/shop/ButtonBuySelectBubbleScript.cpp + menus/shop/ButtonBuySelectBulletScript.cpp menus/mainmenu/MainMenuScene.cpp PreviewScene.cpp main.cpp diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index 436ff5f..baf154c 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -15,6 +15,8 @@ #include "../Config.h" #include "mainmenu/CreditsSubScript.h" +#include "menus/shop/ButtonBuySelectBubbleScript.h" +#include "menus/shop/ButtonBuySelectBulletScript.h" #include #include @@ -88,6 +90,14 @@ void ButtonSubScene::set_script(crepe::GameObject & button_object, const Data & button_object.add_component() .set_script(); break; + case ScriptSelect::SHOP_BULLET: + button_object.add_component() + .set_script(); + break; + case ScriptSelect::SHOP_BUBBLE: + button_object.add_component() + .set_script(); + break; case ScriptSelect::NONE: button_object.add_component().set_script(); break; diff --git a/game/menus/ButtonSubScene.h b/game/menus/ButtonSubScene.h index 8f086f0..d4c7223 100644 --- a/game/menus/ButtonSubScene.h +++ b/game/menus/ButtonSubScene.h @@ -22,6 +22,8 @@ public: PREVIEW_START, PREVIEW_STOP, PREVIEW_REPLAY, + SHOP_BULLET, + SHOP_BUBBLE, NONE, }; //icon enum diff --git a/game/menus/shop/ButtonBuySelectBubbleScript.cpp b/game/menus/shop/ButtonBuySelectBubbleScript.cpp new file mode 100644 index 0000000..21dbe1a --- /dev/null +++ b/game/menus/shop/ButtonBuySelectBubbleScript.cpp @@ -0,0 +1,36 @@ +#include "ButtonBuySelectBubbleScript.h" +#include "../MenusConfig.h" +#include "Config.h" +#include "ValueBroker.h" +#include "manager/SaveManager.h" +#include "menus/shop/Shopconfig.h" + +using namespace crepe; +using namespace std; + +void ButtonBuySelectBubbleScript::init() { + IButtonScript::init(); + this->subscribe([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); +} + +bool ButtonBuySelectBubbleScript::on_button_press(const ButtonPressEvent & e) { + SaveManager & save = this->get_save_manager(); + ValueBroker buy_bullet = save.get(BUY_BUBBLE_SAVE,0); + if(!buy_bullet.get()){ + ValueBroker coins = save.get(TOTAL_COINS_GAME,0); + if(coins.get() >= 1000) + { + int coin = coins.get(); + coin -= 1000; + save.set(TOTAL_COINS_GAME,coin); + save.set(BUY_BUBBLE_SAVE,1); + } + } + else { + save.set(JETPACK_PARTICLES,1); + } + this->trigger_event(); + return false; +} diff --git a/game/menus/shop/ButtonBuySelectBubbleScript.h b/game/menus/shop/ButtonBuySelectBubbleScript.h new file mode 100644 index 0000000..ce276ef --- /dev/null +++ b/game/menus/shop/ButtonBuySelectBubbleScript.h @@ -0,0 +1,14 @@ +#pragma once + +#include "../IButtonScript.h" + +#include + +class ButtonBuySelectBubbleScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); + +protected: + bool transition = false; +}; diff --git a/game/menus/shop/ButtonBuySelectBulletScript.cpp b/game/menus/shop/ButtonBuySelectBulletScript.cpp new file mode 100644 index 0000000..71d8b76 --- /dev/null +++ b/game/menus/shop/ButtonBuySelectBulletScript.cpp @@ -0,0 +1,36 @@ +#include "ButtonBuySelectBulletScript.h" +#include "../MenusConfig.h" +#include "Config.h" +#include "ValueBroker.h" +#include "manager/SaveManager.h" +#include "menus/shop/Shopconfig.h" + +using namespace crepe; +using namespace std; + +void ButtonBuySelectBulletScript::init() { + IButtonScript::init(); + this->subscribe([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); +} + +bool ButtonBuySelectBulletScript::on_button_press(const ButtonPressEvent & e) { + SaveManager & save = this->get_save_manager(); + ValueBroker buy_bullet = save.get(BUY_BULLET_SAVE,0); + if(!buy_bullet.get()){ + ValueBroker coins = save.get(TOTAL_COINS_GAME,0); + if(coins.get() >= 0) + { + int coin = coins.get(); + coin -= 0; + save.set(TOTAL_COINS_GAME,coin); + save.set(BUY_BULLET_SAVE,1); + } + } + else { + save.set(JETPACK_PARTICLES,0); + } + this->trigger_event(); + return false; +} diff --git a/game/menus/shop/ButtonBuySelectBulletScript.h b/game/menus/shop/ButtonBuySelectBulletScript.h new file mode 100644 index 0000000..86de0ac --- /dev/null +++ b/game/menus/shop/ButtonBuySelectBulletScript.h @@ -0,0 +1,14 @@ +#pragma once + +#include "../IButtonScript.h" + +#include + +class ButtonBuySelectBulletScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); + +protected: + bool transition = false; +}; diff --git a/game/menus/shop/ShopLoadScript.cpp b/game/menus/shop/ShopLoadScript.cpp new file mode 100644 index 0000000..a9f9bfe --- /dev/null +++ b/game/menus/shop/ShopLoadScript.cpp @@ -0,0 +1,131 @@ +#include "ShopLoadScript.h" +#include +#include "api/Button.h" +#include "api/Sprite.h" +#include "Shopconfig.h" +#include "api/Text.h" +#include "manager/SaveManager.h" + +using namespace crepe; +using namespace std; + +void ShopLoadScript::init() { + this->update(); + this->subscribe([this](const ShopUpdate e) { + return this->update(); + }); +} + +bool ShopLoadScript::update(){ + SaveManager & save = this->get_save_manager(); + ValueBroker buy_bullet = save.get(BUY_BULLET_SAVE,0); + ValueBroker buy_bubble = save.get(BUY_BUBBLE_SAVE,0); + + + if(buy_bullet.get()){ + auto sprites = this->get_components_by_tag(BUY_BULLET); + for(auto sprite : sprites){ + sprite.get().active = false; + } + auto buttons = this->get_components_by_tag