3 #include "../game/game.h"
4 #include "../score/score.h"
6 static struct entity monster;
13 static void monster_spawn(struct entity *self, void *data)
17 self->meta = malloc(sizeof(struct monster_data));
18 ((struct monster_data *) self->meta)->timer = 0.5;
21 static void monster_step(struct entity *self, struct entity_step_data stepdata)
23 struct monster_data *data = self->meta;
25 if (stepdata.visible && (data->timer -= stepdata.dtime) <= 0.0) {
28 (stepdata.dx && move(self, stepdata.dx > 0 ? -1 : 1, 0)) || (stepdata.dy && move(self, 0, stepdata.dy > 0 ? -1 : 1));
32 static void monster_collide_with_entity(struct entity *self, struct entity *other)
35 add_health(other, -1);
38 static void monster_death(struct entity *self)
44 static void spawn_monster(int x, int y)
46 spawn(monster, x, y, NULL);
49 __attribute__((constructor)) static void init()
51 monster = (struct entity) {
55 .color = get_color("#FF00F6"),
61 .collide_with_entities = true,
63 .on_step = &monster_step,
65 .on_collide_with_entity = &monster_collide_with_entity,
66 .on_spawn = &monster_spawn,
68 .on_death = &monster_death,
72 register_air_function((struct generator_function) {
74 .callback = &spawn_monster,