]> git.lizzy.rs Git - dungeon_game.git/commitdiff
Limit fireballs
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 13 Jun 2021 18:15:29 +0000 (20:15 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 13 Jun 2021 18:15:29 +0000 (20:15 +0200)
plugins/fireball/Makefile
plugins/fireball/dependencies.txt
plugins/fireball/fireball.c

index a7fe4cd4874e5e3d282c3ae351899b9400816041..117c092c248a46af33dcd084a52fb2b4dd5260f8 100644 (file)
@@ -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
index facbb959c3c9557b0e3c91b8153cdc918fdc603b..b19003bde03be8102a4864e0d05aea6178d989b0 100644 (file)
@@ -1,2 +1,3 @@
 game
 movement
+inventory
index 30ea754c018a5f723a1ddf23b2b4fee1c5e319ca..fcb1ac19a2a62e26f4f6d238aa80b4ce826f33a1 100644 (file)
@@ -2,6 +2,7 @@
 #include <stddef.h>
 #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,
        });
 }