aboutsummaryrefslogtreecommitdiff
path: root/game/coins/CoinScript.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'game/coins/CoinScript.cpp')
-rw-r--r--game/coins/CoinScript.cpp20
1 files changed, 13 insertions, 7 deletions
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<Sprite>().active = false;
- this->get_component<CircleCollider>().active = false;
- SaveManager & savemgr = this->get_save_manager();
- int amount = savemgr.get<int>(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<Sprite>("").front().get().active = false;
+ this->get_components_by_name<CircleCollider>("").front().get().active = false;
+ this->amount++;
return true;
}
void CoinScript::init(){
- subscribe<CollisionEvent>([this](const CollisionEvent & ev) -> bool { return this->on_collision(ev); });
+ this->subscribe<CollisionEvent>([this](const CollisionEvent & ev) -> bool { return this->on_collision(ev); });
+ this->subscribe<EndGameEvent>([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;
+}