3 #include "../game/game.h"
5 static struct entity monster;
12 static void monster_spawn(struct entity *self, void *data)
16 self->meta = malloc(sizeof(struct monster_data));
17 ((struct monster_data *) self->meta)->timer = 0.5;
20 static void monster_step(struct entity *self, struct entity_step_data stepdata)
22 struct monster_data *data = self->meta;
24 if (stepdata.visible && (data->timer -= stepdata.dtime) <= 0.0) {
27 (stepdata.dx && move(self, stepdata.dx > 0 ? -1 : 1, 0)) || (stepdata.dy && move(self, 0, stepdata.dy > 0 ? -1 : 1));
31 static void monster_collide_with_entity(struct entity *self, struct entity *other)
34 add_health(other, -1);
37 static void monster_death(struct entity *self)
43 static void spawn_monster(int x, int y)
45 spawn(monster, x, y, NULL);
48 __attribute__((constructor)) static void init()
50 monster = (struct entity) {
54 .color = get_color("#FF00F6"),
60 .collide_with_entities = true,
62 .on_step = &monster_step,
64 .on_collide_with_entity = &monster_collide_with_entity,
65 .on_spawn = &monster_spawn,
67 .on_death = &monster_death,
71 register_air_function((struct generator_function) {
73 .callback = &spawn_monster,