diff options
author | quou <quou@disroot.org> | 2023-05-04 14:10:41 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2023-05-04 14:10:50 +1000 |
commit | d61dcdcc384249ec7ea60c9cc18aab9df1f80577 (patch) | |
tree | 563e985e6a1f480461177f2c341d70ce5dd1498d /player.c | |
parent | c4ac81cffcf925963acb0c02584ab22626427a73 (diff) |
Add shooting.
Diffstat (limited to 'player.c')
-rw-r--r-- | player.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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--; } |