aboutsummaryrefslogtreecommitdiff
path: root/player.c
diff options
context:
space:
mode:
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--;
}