From: Elias Fleckenstein Date: Sun, 13 Jun 2021 18:15:29 +0000 (+0200) Subject: Limit fireballs X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=5077aabd093476e66604175ff6a810db3a024fbf;p=dungeon_game.git Limit fireballs --- diff --git a/plugins/fireball/Makefile b/plugins/fireball/Makefile index a7fe4cd..117c092 100644 --- a/plugins/fireball/Makefile +++ b/plugins/fireball/Makefile @@ -1,4 +1,4 @@ -plugins/fireball/fireball.so: plugins/fireball/fireball.c plugins/game/game.h plugins/movement/movement.h +plugins/fireball/fireball.so: plugins/fireball/fireball.c plugins/game/game.h plugins/movement/movement.h plugins/inventory/inventory.h cc -g -shared -fpic -o plugins/fireball/fireball.so plugins/fireball/fireball.c PLUGINS := ${PLUGINS} plugins/fireball/fireball.so diff --git a/plugins/fireball/dependencies.txt b/plugins/fireball/dependencies.txt index facbb95..b19003b 100644 --- a/plugins/fireball/dependencies.txt +++ b/plugins/fireball/dependencies.txt @@ -1,2 +1,3 @@ game movement +inventory diff --git a/plugins/fireball/fireball.c b/plugins/fireball/fireball.c index 30ea754..fcb1ac1 100644 --- a/plugins/fireball/fireball.c +++ b/plugins/fireball/fireball.c @@ -2,6 +2,7 @@ #include #include "../game/game.h" #include "../movement/movement.h" +#include "../inventory/inventory.h" struct fireball_data { @@ -39,7 +40,7 @@ static void fireball_collide(struct entity *self, int x, int y) static void fireball_collide_with_entity(struct entity *self, struct entity *other) { - add_health(other, -(1 + rand() % 3)); + add_health(other, -(3 + rand() % 3)); self->remove = true; } @@ -79,12 +80,40 @@ static void shoot_fireball() }); } +static bool shoot_fireball_item(struct itemstack *stack) +{ + (void) stack; + + shoot_fireball(); + return true; +} + +static struct item fireball_item = { + .name = "Fireball", + .stackable = true, + + .on_use = &shoot_fireball_item, + .on_destroy = NULL, +}; + +static void shoot_if_has_fireball() +{ + if (inventory_remove(&player_inventory, &fireball_item)) + shoot_fireball(); +} + __attribute__((constructor)) static void init() { fireball_entity.color = get_color("#FF6611"); register_input_handler(' ', (struct input_handler) { .run_if_dead = false, - .callback = &shoot_fireball, + .callback = &shoot_if_has_fireball, + }); + + inventory_add(&player_inventory, (struct itemstack) { + .item = &fireball_item, + .count = 7, + .meta = NULL, }); }