summaryrefslogtreecommitdiff
path: root/src/trigger.c
blob: 86a39be47beca7494dc250654e23ffb06621620e (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
NAME(trigger);
PARENT(tile);

static u8 strtobyte(const char *s) {
	const char buf[3] = {s[0], s[1], '\0'};
	return strtol(buf, nullptr, 16);
}

INIT {
	super("init");
	this->on = propertyb("on");
	this->multi = propertyb("multi");
	this->leave = propertyb("leave");
	this->do_x = propertyb("flip x") || propertyb("x");
	this->do_y = propertyb("flip y") || propertyb("y");
	this->color_group = propertyi_default("color group", 0);
	this->fade_in = propertyi_default("fade in", 0);

	const auto color = propertyc("color");
	if (color != nullptr && strlen(color) > 8) {
		this->color.r = strtobyte(color + 3) / 255.;
		this->color.g = strtobyte(color + 5) / 255.;
		this->color.b = strtobyte(color + 7) / 255.;
	} else {
		this->color.r = 0;
		this->color.g = 0;
		this->color.b = 0;
	}
}

IMPL(target) {
	this->target = propertyi("target") + 1;
}

IMPL(enter) {}
IMPL(leave) {}

UPDATE {
	if (!this->visible)
		return;
	if (place_meeting(v2_zero(), "player", false)) {
		if (!this->air) {
			method("enter");
			this->air = true;
			if (!this->leave && !this->multi)
				method("deinit");
		}
	} else {
		if (this->air) {
			method("leave");
			this->air = false;
			if (!this->multi)
				method("deinit");
			if (!this->multi)
				method("deinit");
		}
	}
}

DRAW {
	if (this->animation > 4)
		return;
	super("draw");
}