3 #include "../game/game.h"
5 static struct entity monster;
12 static void monster_spawn(struct entity *self)
14 self->meta = malloc(sizeof(struct monster_data));
15 ((struct monster_data *) self->meta)->timer = 0.5;
18 static void monster_step(struct entity *self, struct entity_step_data stepdata)
20 struct monster_data *data = self->meta;
22 if (stepdata.visible && (data->timer -= stepdata.dtime) <= 0.0) {
25 (stepdata.dx && move(self, stepdata.dx > 0 ? -1 : 1, 0)) || (stepdata.dy && move(self, 0, stepdata.dy > 0 ? -1 : 1));
29 static void monster_on_collide_with_entity(struct entity *self, struct entity *other)
32 add_health(other, -1);
35 static void monster_death(struct entity *self)
41 static void spawn_monster(int x, int y)
46 __attribute__((constructor)) static void init()
48 monster = (struct entity) {
52 .color = get_color("#FF00F6"),
58 .collide_with_entities = true,
60 .on_step = &monster_step,
62 .on_collide_with_entity = &monster_on_collide_with_entity,
63 .on_spawn = &monster_spawn,
65 .on_death = &monster_death,
68 register_air_function((struct generator_function) {
70 .callback = &spawn_monster,