From d61dcdcc384249ec7ea60c9cc18aab9df1f80577 Mon Sep 17 00:00:00 2001 From: quou Date: Thu, 4 May 2023 14:10:41 +1000 Subject: Add shooting. --- player.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'player.c') 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--; } -- cgit v1.2.3-54-g00ecf