]> git.lizzy.rs Git - dungeon_game.git/commitdiff
Add sword attack key
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 14 Jun 2021 09:25:23 +0000 (11:25 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 14 Jun 2021 09:25:23 +0000 (11:25 +0200)
doc/GAMEPLAY.md
plugins/sword/sword.c

index 03842066385a4d3b88780d77c1d9f8da23ee71a4..bdcc1bb4d5ffff91b349bca38eab02cd9a0bcd77 100644 (file)
@@ -5,7 +5,7 @@
 You are in a pixely dungeon. There is no exit, the goal of the game is to survive and to collect XP (score). There are monsters and items in the world; you have to collect things and defeat monsters.
 
 ## Controls
-You can use WASD to move up / left / down / right. Use Q to quit and Space to shoot fireballs if you have them in your inventory.
+You can use WASD to move up / left / down / right. Use Q to quit and Space to shoot fireballs if you have them in your inventory. Use E to use your sword if you have one in your inventory.
 To navigate the inventory, use the arrow keys (up and down) to select an item and then press enter to use it.
 
 ## The map
index 653692fcf58950a8d66f312f1a77d056d8fce8ea..dc1118d2445f87bd3a6a0236c2fe21a58a0afa7c 100644 (file)
@@ -55,6 +55,14 @@ static struct item sword = {
        .on_create = NULL,
 };
 
+static void handle_e()
+{
+       struct itemstack *stack = inventory_find(&player_inventory, &sword);
+
+       if (stack)
+               use_sword(stack);
+}
+
 __attribute__((constructor)) static void init()
 {
        inventory_add(&player_inventory, (struct itemstack) {
@@ -62,4 +70,9 @@ __attribute__((constructor)) static void init()
                .count = 1,
                .meta = NULL,
        });
+
+       register_input_handler('e', (struct input_handler) {
+               .run_if_dead = false,
+               .callback = &handle_e,
+       });
 }