aboutsummaryrefslogtreecommitdiff
path: root/game/coins/CoinScript.cpp
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2025-01-07 13:20:50 +0100
committerJAROWMR <jarorutjes07@gmail.com>2025-01-07 13:20:50 +0100
commitbc66e7195c80facca244f933b882011e5e81fa3c (patch)
treea9417c19a7f9cecb09130ac7becfbba059b1ec5b /game/coins/CoinScript.cpp
parent42cbef630ccaf3e841459d364edade1a3c72a525 (diff)
coins use events
Diffstat (limited to 'game/coins/CoinScript.cpp')
-rw-r--r--game/coins/CoinScript.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/game/coins/CoinScript.cpp b/game/coins/CoinScript.cpp
index 5d4e8fe..5960446 100644
--- a/game/coins/CoinScript.cpp
+++ b/game/coins/CoinScript.cpp
@@ -4,14 +4,15 @@
#include "manager/SaveManager.h"
#include "../Config.h"
#include "../Events.h"
+#include "../hud/HudScript.h"
using namespace crepe;
using namespace std;
bool CoinScript::on_collision(const CollisionEvent & collisionData){
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->get_components_by_name<Sprite>(collisionData.info.other.metadata.name).front().get().active = false;
+ this->get_components_by_name<CircleCollider>(collisionData.info.other.metadata.name).front().get().active = false;
this->amount++;
return true;
}
@@ -21,6 +22,12 @@ void CoinScript::init(){
this->subscribe<EndGameEvent>([this](const EndGameEvent e)-> bool { return this->save(); });
}
+void CoinScript::fixed_update(crepe::duration_t dt) {
+ this->trigger_event(GetCoinEvent{
+ .amount_of_coins = this->amount,
+ });
+}
+
bool CoinScript::save(){
SaveManager & savemgr = this->get_save_manager();
savemgr.set(TOTAL_COINS_RUN, this->amount);