diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-06-13 20:44:45 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-06-13 20:44:45 +0200 |
commit | 8797437f992bd76521465db4bf63665be30d5671 (patch) | |
tree | 2b8b09a6c93f1f7054c571156955b93b35d06fe2 /plugins | |
parent | 178089f47710ff90f71a8a2a553ed0700b198ed3 (diff) | |
download | dungeon_game-8797437f992bd76521465db4bf63665be30d5671.tar.xz |
Add sword
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/sword/Makefile | 4 | ||||
-rw-r--r-- | plugins/sword/dependencies.txt | 3 | ||||
-rw-r--r-- | plugins/sword/sword.c | 59 |
3 files changed, 66 insertions, 0 deletions
diff --git a/plugins/sword/Makefile b/plugins/sword/Makefile new file mode 100644 index 0000000..ee28952 --- /dev/null +++ b/plugins/sword/Makefile @@ -0,0 +1,4 @@ +plugins/sword/sword.so: plugins/sword/sword.c plugins/game/game.h plugins/movement/movement.h plugins/inventory/inventory.h + cc -g -shared -fpic -o plugins/sword/sword.so plugins/sword/sword.c + +PLUGINS := ${PLUGINS} plugins/sword/sword.so diff --git a/plugins/sword/dependencies.txt b/plugins/sword/dependencies.txt new file mode 100644 index 0000000..b19003b --- /dev/null +++ b/plugins/sword/dependencies.txt @@ -0,0 +1,3 @@ +game +movement +inventory diff --git a/plugins/sword/sword.c b/plugins/sword/sword.c new file mode 100644 index 0000000..f399150 --- /dev/null +++ b/plugins/sword/sword.c @@ -0,0 +1,59 @@ +#include <stdlib.h> +#include <stddef.h> +#include "../game/game.h" +#include "../movement/movement.h" +#include "../inventory/inventory.h" + +static bool use_broken_sword(struct itemstack *stack) +{ + (void) stack; + + return true; +} + +static struct item broken_sword = { + .name = "Broken Sword", + .stackable = false, + + .on_use = &use_broken_sword, + .on_destroy = NULL, + .on_create = NULL, +}; + +static bool use_sword(struct itemstack *stack) +{ + int x, y; + x = player.x; + y = player.y; + + dir_to_xy(last_player_move, &x, &y); + + struct entity *entity = entity_collision_map[x][y]; + + if (entity) { + add_health(entity, -1); + + if (rand() % 100 == 0) + stack->item = &broken_sword; + } + + return false; +} + +static struct item sword = { + .name = "Sword", + .stackable = false, + + .on_use = &use_sword, + .on_destroy = NULL, + .on_create = NULL, +}; + +__attribute__((constructor)) static void init() +{ + inventory_add(&player_inventory, (struct itemstack) { + .item = &sword, + .count = 1, + .meta = NULL, + }); +} |