aboutsummaryrefslogtreecommitdiff
path: root/player.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2023-05-04 14:10:41 +1000
committerquou <quou@disroot.org>2023-05-04 14:10:50 +1000
commitd61dcdcc384249ec7ea60c9cc18aab9df1f80577 (patch)
tree563e985e6a1f480461177f2c341d70ce5dd1498d /player.c
parentc4ac81cffcf925963acb0c02584ab22626427a73 (diff)
Add shooting.
Diffstat (limited to 'player.c')
-rw-r--r--player.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/player.c b/player.c
index 801dc33..cadb0dc 100644
--- a/player.c
+++ b/player.c
@@ -5,6 +5,7 @@
#include "player.h"
#include "standard.h"
#include "world.h"
+#include "bullet.h"
void init_player(Player* player, World* world) {
CSprite* sprite;
@@ -36,6 +37,8 @@ void init_player(Player* player, World* world) {
animated->timer = 0;
player->face = 0;
+ player->shoot_cooldown = 15;
+ player->shoot_countdown = 0;
}
void update_player(Player* player, World* world) {
@@ -78,6 +81,9 @@ void update_player(Player* player, World* world) {
pos->x += (dx * player_move_speed) >> fbits;
pos->y += (dy * player_move_speed) >> fbits;
+ player->ldx = dx;
+ player->ldy = dy;
+
moving = 1;
}
@@ -95,4 +101,19 @@ void update_player(Player* player, World* world) {
animation_player_walk_right :
animation_player_walk_left;
}
+
+ if (button_pressed(btn_shoot) && player->shoot_countdown <= 0) {
+ new_player_bullet(
+ world,
+ pos->x,
+ pos->y,
+ (player->ldx * player_bullet_speed) >> fbits,
+ (player->ldy * player_bullet_speed) >> fbits,
+ 100
+ );
+
+ player->shoot_countdown = player->shoot_cooldown;
+ }
+
+ player->shoot_countdown--;
}