From 5d0c8c6e70115feb7f46b7aab11112cdc0f9f696 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 9 Jun 2021 17:10:36 +0200 Subject: Add plugins --- plugins/apple/apple.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 plugins/apple/apple.c (limited to 'plugins/apple/apple.c') diff --git a/plugins/apple/apple.c b/plugins/apple/apple.c new file mode 100644 index 0000000..7c2de77 --- /dev/null +++ b/plugins/apple/apple.c @@ -0,0 +1,48 @@ +#include +#include +#include "dungeon.h" + +static struct entity apple; + +static void apple_step(struct entity *self, struct entity_step_data stepdata) +{ + if (stepdata.dx == 0 && stepdata.dy == 0) { + add_score(1); + add_health(&player, 1); + self->remove = true; + } +} + +static void spawn_apple(int x, int y) +{ + spawn(apple, x, y); +} + +__attribute__((constructor)) static void init() +{ + apple = (struct entity) { + .name = "apple", + .x = 0, + .y = 0, + .color = get_color("#FF2A53"), + .texture = "🍎", + .remove = false, + .meta = NULL, + .health = 1, + .max_health = 1, + .collide_with_entities = false, + + .on_step = &apple_step, + .on_collide = NULL, + .on_collide_with_entity = NULL, + .on_spawn = NULL, + .on_remove = NULL, + .on_death = NULL, + }; + + register_air_function((struct generator_function) { + .chance = 25, + .callback = &spawn_apple, + }); +} + -- cgit v1.2.3