aboutsummaryrefslogtreecommitdiff
path: root/game/coins
diff options
context:
space:
mode:
Diffstat (limited to 'game/coins')
-rw-r--r--game/coins/CoinPool.cpp3
-rw-r--r--game/coins/CoinScript.cpp11
-rw-r--r--game/coins/CoinScript.h1
-rw-r--r--game/coins/CoinSubScene.cpp1
4 files changed, 13 insertions, 3 deletions
diff --git a/game/coins/CoinPool.cpp b/game/coins/CoinPool.cpp
index 5720c2f..59b987c 100644
--- a/game/coins/CoinPool.cpp
+++ b/game/coins/CoinPool.cpp
@@ -1,5 +1,8 @@
#include "CoinPool.h"
+#include "CoinScript.h"
#include "CoinSubScene.h"
+#include "api/BehaviorScript.h"
+#include "api/GameObject.h"
using namespace crepe;
using namespace std;
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);
diff --git a/game/coins/CoinScript.h b/game/coins/CoinScript.h
index e88a860..6fcb64e 100644
--- a/game/coins/CoinScript.h
+++ b/game/coins/CoinScript.h
@@ -5,6 +5,7 @@
class CoinScript : public crepe::Script {
public:
void init() override;
+ void fixed_update(crepe::duration_t dt) override;
bool on_collision(const crepe::CollisionEvent & collisionData);
bool save();
private:
diff --git a/game/coins/CoinSubScene.cpp b/game/coins/CoinSubScene.cpp
index 3914921..72319ca 100644
--- a/game/coins/CoinSubScene.cpp
+++ b/game/coins/CoinSubScene.cpp
@@ -36,6 +36,5 @@ int CoinSubScene::create(Scene & scn){
.looping = true,
});
coin.add_component<AudioSource>(Asset{"asset/sfx/coin_pickup_1.ogg"});
- coin.add_component<BehaviorScript>().set_script<CoinScript>();
return coin_counter;
}