aboutsummaryrefslogtreecommitdiff
path: root/game/coins/CoinScript.cpp
diff options
context:
space:
mode:
authorJaro <59013720+JaroWMR@users.noreply.github.com>2025-01-08 09:31:14 +0100
committerGitHub <noreply@github.com>2025-01-08 09:31:14 +0100
commite75ca1c947f3cde19bebf15049732bc069c6e913 (patch)
treecdaa7a2c06ffc7f41366d4106e16f254e3b9cdc5 /game/coins/CoinScript.cpp
parentf31bd86ae5d7df21b788a273d4f2e530136ec184 (diff)
parent0d087f23affbdf5bcfb238bc9b9d3fc05b314c44 (diff)
Merge pull request #101 from lonkaars/jaro/main-menu
Jaro/main menu
Diffstat (limited to 'game/coins/CoinScript.cpp')
-rw-r--r--game/coins/CoinScript.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/game/coins/CoinScript.cpp b/game/coins/CoinScript.cpp
new file mode 100644
index 0000000..90150b6
--- /dev/null
+++ b/game/coins/CoinScript.cpp
@@ -0,0 +1,51 @@
+#include "CoinScript.h"
+
+#include "manager/SaveManager.h"
+
+#include "../Config.h"
+#include "../hud/HudScript.h"
+
+#include <crepe/api/CircleCollider.h>
+#include <crepe/api/Sprite.h>
+
+using namespace crepe;
+using namespace std;
+
+bool CoinScript::on_collision(const CollisionEvent & collisionData) {
+ if (collisionData.info.other.metadata.tag != "coin") return false;
+ if (!this->get_components_by_name<Sprite>(collisionData.info.other.metadata.name)
+ .front()
+ .get()
+ .active)
+ return 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 false;
+}
+
+void CoinScript::init() {
+ this->subscribe<CollisionEvent>([this](const CollisionEvent & ev) -> bool {
+ return this->on_collision(ev);
+ });
+}
+
+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);
+ return false;
+}