aboutsummaryrefslogtreecommitdiff
path: root/game/workers/CollisionScript.cpp
blob: baa058b0b2828ee2771c1831f036871e5774b835 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "CollisionScript.h"

#include <crepe/api/Animator.h>

using namespace crepe;
using namespace std;

void CollisionScript::init() {
	subscribe<CollisionEvent>([this](const CollisionEvent & ev) -> bool {
		return this->on_collision(ev);
	});
}

bool CollisionScript::on_collision(const CollisionEvent & ev) {
	RefVector<Animator> animators = this->get_components<Animator>();

	if (ev.info.other.metadata.tag == "zapper") {
		for (Animator & anim : animators) {
			anim.active = true;
			anim.set_anim(4);
			anim.data.looping = true;
		}

		return true;
	} else if (ev.info.other.metadata.tag == "laser") {
		for (Animator & anim : animators) {
			anim.active = true;
			anim.set_anim(4);
			anim.data.looping = true;
		}

		return true;
	} else if (ev.info.other.metadata.tag == "missile") {
		for (Animator & anim : animators) {
			anim.active = true;
			anim.set_anim(5);
			anim.data.looping = true;
		}

		return true;
	}

	return false;
}