]> git.lizzy.rs Git - dungeon_game.git/blob - plugins/apple/apple.c
795800d48ae47c5edd88a0879c77f6b9fb0f7723
[dungeon_game.git] / plugins / apple / apple.c
1 #include <stddef.h>
2 #include <stdlib.h>
3 #include "../game/game.h"
4 #include "../score/score.h"
5
6 static void apple_step(struct entity *self, struct entity_step_data stepdata)
7 {
8         if (stepdata.dx == 0 && stepdata.dy == 0) {
9                 add_score(1);
10                 add_health(&player, 1);
11                 self->remove = true;
12         }
13 }
14
15 static struct entity apple_entity = {
16         .name = "apple",
17         .x = 0,
18         .y = 0,
19         .color = {0},
20         .use_color = false,
21         .texture = "🍎",
22         .remove = false,
23         .meta = NULL,
24         .health = 1,
25         .max_health = 1,
26         .collide_with_entities = false,
27
28         .on_step = &apple_step,
29         .on_collide = NULL,
30         .on_collide_with_entity = NULL,
31         .on_spawn = NULL,
32         .on_remove = NULL,
33         .on_death = NULL,
34         .on_damage = NULL,
35 };
36
37 static void spawn_apple(int x, int y)
38 {
39         spawn(apple_entity, x, y, NULL);
40 }
41
42 __attribute__((constructor)) static void init()
43 {
44         register_air_function((struct generator_function) {
45                 .chance = 25,
46                 .callback = &spawn_apple,
47         });
48 }
49