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