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