aboutsummaryrefslogtreecommitdiff
path: root/plugins/apple/apple.c
blob: d100e45bd0381303f1e8442faba0566a6d1d5b53 (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
#include <stddef.h>
#include <stdlib.h>
#include "../game/game.h"

static struct entity apple;

static void apple_step(struct entity *self, struct entity_step_data stepdata)
{
	if (stepdata.dx == 0 && stepdata.dy == 0) {
		add_score(1);
		add_health(&player, 1);
		self->remove = true;
	}
}

static void spawn_apple(int x, int y)
{
	spawn(apple, x, y, NULL);
}

__attribute__((constructor)) static void init()
{
	apple = (struct entity) {
		.name = "apple",
		.x = 0,
		.y = 0,
		.color = get_color("#FF2A53"),
		.texture = "🍎",
		.remove = false,
		.meta = NULL,
		.health = 1,
		.max_health = 1,
		.collide_with_entities = false,

		.on_step = &apple_step,
		.on_collide = NULL,
		.on_collide_with_entity = NULL,
		.on_spawn = NULL,
		.on_remove = NULL,
		.on_death = NULL,
		.on_damage = NULL,
	};

	register_air_function((struct generator_function) {
		.chance = 25,
		.callback = &spawn_apple,
	});
}