From 40eb179043b77f011fb1048c386ee187f64569d0 Mon Sep 17 00:00:00 2001 From: quou Date: Sun, 7 May 2023 09:37:45 +1000 Subject: Add waves and some more polish. --- player.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'player.c') diff --git a/player.c b/player.c index 7135557..ff3f53b 100644 --- a/player.c +++ b/player.c @@ -1,6 +1,7 @@ #include "animation.h" #include "bullet.h" #include "components.h" +#include "fx.h" #include "game.h" #include "game_config.h" #include "input.h" @@ -129,6 +130,22 @@ void update_player(Player* player, World* world) { player->shoot_countdown = player->shoot_cooldown; } + if (player->invul) { + player->invul--; + player->invul_counter++; + + if (player->invul_counter > 3) { + if (world->bitmask[e] & ctype_sprite) { + world->bitmask[e] &= ~ctype_sprite; + } else { + world->bitmask[e] |= ctype_sprite; + } + player->invul_counter = 0; + } + } else { + world->bitmask[e] |= ctype_sprite; + } + if (player->hp <= 0) { world->oom = 0; game_change_state(&game, game_state_dead); @@ -137,8 +154,25 @@ void update_player(Player* player, World* world) { player->shoot_countdown--; } -void player_take_damage(Player* player, int dmg) { +void player_take_damage( + World* world, + Player* player, + int dmg +) { + const CPosition* pos; + + pos = &world->positions[player->entity]; + + if (player->invul) { return; } + player->hp -= dmg; + player->invul = player_invul_frames; + player->invul_counter = 0; + new_heart_break( + world, + pos->x + (4 << fbits), + pos->y - (8 << fbits) + ); } void update_camera(Player* player, World* world) { -- cgit v1.2.3-54-g00ecf