From 42cbef630ccaf3e841459d364edade1a3c72a525 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Tue, 7 Jan 2025 12:06:05 +0100 Subject: coin update --- game/coins/CoinScript.cpp | 20 +++++++++++++------- game/coins/CoinScript.h | 3 +++ 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'game') diff --git a/game/coins/CoinScript.cpp b/game/coins/CoinScript.cpp index e40f658..5d4e8fe 100644 --- a/game/coins/CoinScript.cpp +++ b/game/coins/CoinScript.cpp @@ -3,21 +3,27 @@ #include "api/Sprite.h" #include "manager/SaveManager.h" #include "../Config.h" +#include "../Events.h" using namespace crepe; using namespace std; bool CoinScript::on_collision(const CollisionEvent & collisionData){ - if(collisionData.info.other.metadata.name != PLAYER_NAME) return true; - this->get_component().active = false; - this->get_component().active = false; - SaveManager & savemgr = this->get_save_manager(); - int amount = savemgr.get(TOTAL_COINS_RUN,0).get() + 1; - savemgr.set(TOTAL_COINS_RUN, amount); + if(collisionData.info.other.metadata.tag != "coin") return true; + this->get_components_by_name("").front().get().active = false; + this->get_components_by_name("").front().get().active = false; + this->amount++; return true; } void CoinScript::init(){ - subscribe([this](const CollisionEvent & ev) -> bool { return this->on_collision(ev); }); + this->subscribe([this](const CollisionEvent & ev) -> bool { return this->on_collision(ev); }); + this->subscribe([this](const EndGameEvent e)-> bool { return this->save(); }); } +bool CoinScript::save(){ + SaveManager & savemgr = this->get_save_manager(); + savemgr.set(TOTAL_COINS_RUN, this->amount); + this->amount = 0; + return false; +} diff --git a/game/coins/CoinScript.h b/game/coins/CoinScript.h index 96e54fa..e88a860 100644 --- a/game/coins/CoinScript.h +++ b/game/coins/CoinScript.h @@ -6,4 +6,7 @@ class CoinScript : public crepe::Script { public: void init() override; bool on_collision(const crepe::CollisionEvent & collisionData); + bool save(); +private: + int amount = 0; }; -- cgit v1.2.3