aboutsummaryrefslogtreecommitdiff
path: root/game/coins/CoinScript.cpp
blob: e40f658234143aebba7de9178e95ef207101b7af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#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;
	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); });
}