diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-06-09 20:26:57 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-06-09 20:26:57 +0200 |
commit | 149848dbfa136f828b09253f402de59c00a5a1cf (patch) | |
tree | 1b18fe1c8611e40fb19d7828dcb45ccc22808464 /plugins/fireball/fireball.c | |
parent | 98e09a9f519c2943fab1bee4884e66b83951c867 (diff) | |
download | dungeon_game-149848dbfa136f828b09253f402de59c00a5a1cf.tar.xz |
Shoot fireballs into last movement direction
Diffstat (limited to 'plugins/fireball/fireball.c')
-rw-r--r-- | plugins/fireball/fireball.c | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/plugins/fireball/fireball.c b/plugins/fireball/fireball.c index 3da29a4..f2e8479 100644 --- a/plugins/fireball/fireball.c +++ b/plugins/fireball/fireball.c @@ -1,6 +1,7 @@ #include <stdlib.h> #include <stddef.h> #include "../game/game.h" +#include "../movement/movement.h" static struct entity fireball; @@ -44,37 +45,20 @@ static void fireball_collide_with_entity(struct entity *self, struct entity *oth self->remove = true; } -static bool try_shoot(int x, int y, int vx, int vy) +static void shoot_fireball() { - x += vx; - y += vy; + int vx, vy; + vx = vy = 0; + + dir_to_xy(last_player_move, &vx, &vy); - return spawn(fireball, x, y, & (struct fireball_data) { + spawn(fireball, player.x + vx, player.y + vy, & (struct fireball_data) { .timer = 0.1, .vx = vx, .vy = vy, }); } -static void shoot_fireball() -{ - int x, y; - - x = player.x; - y = player.y; - - for (int tries = 10; tries > 0; tries--) { - int vx, vy; - - vx = vy = 0; - - dir_to_xy(rand() % 4, &vx, &vy); - - if (try_shoot(x, y, vx, vy)) - return; - } -} - __attribute__((constructor)) static void init() { fireball = (struct entity) { |