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/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 +++ 8 files changed, 351 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/shop') 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