aboutsummaryrefslogtreecommitdiff
path: root/plugins/fireball
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/fireball')
-rw-r--r--plugins/fireball/dependencies.txt1
-rw-r--r--plugins/fireball/fireball.c30
2 files changed, 8 insertions, 23 deletions
diff --git a/plugins/fireball/dependencies.txt b/plugins/fireball/dependencies.txt
index dc22e61..facbb95 100644
--- a/plugins/fireball/dependencies.txt
+++ b/plugins/fireball/dependencies.txt
@@ -1 +1,2 @@
game
+movement
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) {