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.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/game/coins/CoinScript.cpp b/game/coins/CoinScript.cpp
new file mode 100644
index 0000000..5a1e922
--- /dev/null
+++ b/game/coins/CoinScript.cpp
@@ -0,0 +1,24 @@
+#include "CoinScript.h"
+#include "api/CircleCollider.h"
+#include "api/Sprite.h"
+#include "manager/SaveManager.h"
+#include "../Config.h"
+
+using namespace crepe;
+using namespace std;
+
+bool CoinScript::on_collision(const CollisionEvent & collisionData){
+ if(collisionData.info.other.metadata.name != PLAYER_NAME) return true;
+ //collide with player
+ 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);
+ return true;
+}
+
+void CoinScript::init(){
+ subscribe<CollisionEvent>([this](const CollisionEvent & ev) -> bool { return this->on_collision(ev); });
+}
+