]> git.lizzy.rs Git - dungeon_game.git/blobdiff - plugins/monster/monster.c
Separate air_function chances for rooms and corridors
[dungeon_game.git] / plugins / monster / monster.c
index 167de88ed262eb6f4af0bfc6a26048d1d824ed26..d140005dbddac22831cf5263681d0cef32c2d98d 100644 (file)
@@ -1,15 +1,14 @@
 #include <stdlib.h>
 #include <stddef.h>
-#include "dungeon.h"
-
-static struct entity monster;
+#include "../game/game.h"
+#include "../score/score.h"
 
 struct monster_data
 {
        double timer;
 };
 
-static void monster_spawn(struct entity *self)
+static void monster_spawn(struct entity *self, void *data)
 {
        self->meta = malloc(sizeof(struct monster_data));
        ((struct monster_data *) self->meta)->timer = 0.5;
@@ -26,7 +25,7 @@ static void monster_step(struct entity *self, struct entity_step_data stepdata)
        }
 }
 
-static void monster_on_collide_with_entity(struct entity *self, struct entity *other)
+static void monster_collide_with_entity(struct entity *self, struct entity *other)
 {
        if (other == &player)
                add_health(other, -1);
@@ -38,35 +37,39 @@ static void monster_death(struct entity *self)
        self->remove = true;
 }
 
-static void spawn_monster(int x, int y)
+static struct entity monster_entity = {
+       .name = "monster",
+       .x = 0,
+       .y = 0,
+       .color = {0},
+       .use_color = false,
+       .texture = "👾",
+       .remove = false,
+       .meta = NULL,
+       .health = 5,
+       .max_health = 5,
+       .collide_with_entities = true,
+
+       .on_step = &monster_step,
+       .on_collide = NULL,
+       .on_collide_with_entity = &monster_collide_with_entity,
+       .on_spawn = &monster_spawn,
+       .on_remove = NULL,
+       .on_death = &monster_death,
+       .on_damage = NULL,
+};
+
+
+static void spawn_monster(int x, int y, enum mg_context ctx)
 {
-       spawn(monster, x, y);
+       spawn(monster_entity, x, y, NULL);
 }
 
 __attribute__((constructor)) static void init()
 {
-       monster = (struct entity) {
-               .name = "monster",
-               .x = 0,
-               .y = 0,
-               .color = get_color("#FF00F6"),
-               .texture = "👾",
-               .remove = false,
-               .meta = NULL,
-               .health = 5,
-               .max_health = 5,
-               .collide_with_entities = true,
-
-               .on_step = &monster_step,
-               .on_collide = NULL,
-               .on_collide_with_entity = &monster_on_collide_with_entity,
-               .on_spawn = &monster_spawn,
-               .on_remove = NULL,
-               .on_death = &monster_death,
-       };
-
        register_air_function((struct generator_function) {
-               .chance = 50,
+               .corridor_chance = 50,
+               .room_chance = 200,
                .callback = &spawn_monster,
        });
 }