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/ButtonBuySelectBulletScript.cpp | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 game/menus/shop/ButtonBuySelectBulletScript.cpp (limited to 'game/menus/shop/ButtonBuySelectBulletScript.cpp') 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; +} -- cgit v1.2.3