3 #include "../game/game.h"
4 #include "../score/score.h"
11 static void monster_spawn(struct entity *self, void *data)
15 self->meta = malloc(sizeof(struct monster_data));
16 ((struct monster_data *) self->meta)->timer = 0.5;
19 static void monster_step(struct entity *self, struct entity_step_data stepdata)
21 struct monster_data *data = self->meta;
23 if (stepdata.visible && (data->timer -= stepdata.dtime) <= 0.0) {
26 (stepdata.dx && move(self, stepdata.dx > 0 ? -1 : 1, 0)) || (stepdata.dy && move(self, 0, stepdata.dy > 0 ? -1 : 1));
30 static void monster_collide_with_entity(struct entity *self, struct entity *other)
33 add_health(other, -1);
36 static void monster_death(struct entity *self)
42 static struct entity monster_entity = {
53 .collide_with_entities = true,
55 .on_step = &monster_step,
57 .on_collide_with_entity = &monster_collide_with_entity,
58 .on_spawn = &monster_spawn,
60 .on_death = &monster_death,
65 static void spawn_monster(int x, int y)
67 spawn(monster_entity, x, y, NULL);
70 __attribute__((constructor)) static void init()
72 register_air_function((struct generator_function) {
74 .callback = &spawn_monster,