3 #include "../game/game.h"
4 #include "../score/score.h"
11 static void monster_spawn(struct entity *self, void *data)
13 self->meta = malloc(sizeof(struct monster_data));
14 ((struct monster_data *) self->meta)->timer = 0.5;
17 static void monster_step(struct entity *self, struct entity_step_data stepdata)
19 struct monster_data *data = self->meta;
21 if (stepdata.visible && (data->timer -= stepdata.dtime) <= 0.0) {
24 (stepdata.dx && move(self, stepdata.dx > 0 ? -1 : 1, 0)) || (stepdata.dy && move(self, 0, stepdata.dy > 0 ? -1 : 1));
28 static void monster_collide_with_entity(struct entity *self, struct entity *other)
31 add_health(other, -1);
34 static void monster_death(struct entity *self)
40 static struct entity monster_entity = {
51 .collide_with_entities = true,
53 .on_step = &monster_step,
55 .on_collide_with_entity = &monster_collide_with_entity,
56 .on_spawn = &monster_spawn,
58 .on_death = &monster_death,
63 static void spawn_monster(int x, int y, enum mg_context ctx)
65 spawn(monster_entity, x, y, NULL);
68 __attribute__((constructor)) static void init()
70 register_air_function((struct generator_function) {
71 .corridor_chance = 50,
73 .callback = &spawn_monster,