diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-06-09 17:10:36 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-06-09 17:10:36 +0200 |
commit | 5d0c8c6e70115feb7f46b7aab11112cdc0f9f696 (patch) | |
tree | 6a0501272c0deb9a1cb6b0ca6f4a634c16d56302 /plugins/apple | |
parent | 1d8435550691a199945e03f66130e901b9808fab (diff) | |
download | dungeon_game-5d0c8c6e70115feb7f46b7aab11112cdc0f9f696.tar.xz |
Add plugins
Diffstat (limited to 'plugins/apple')
-rw-r--r-- | plugins/apple/Makefile | 2 | ||||
-rw-r--r-- | plugins/apple/apple.c | 48 |
2 files changed, 50 insertions, 0 deletions
diff --git a/plugins/apple/Makefile b/plugins/apple/Makefile new file mode 100644 index 0000000..8e3ccca --- /dev/null +++ b/plugins/apple/Makefile @@ -0,0 +1,2 @@ +apple.so: apple.c ../game/game.h + cc -g -shared -fpic -o apple.so 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 <stddef.h> +#include <stdlib.h> +#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, + }); +} + |