aboutsummaryrefslogtreecommitdiff
path: root/player.c
diff options
context:
space:
mode:
Diffstat (limited to 'player.c')
-rw-r--r--player.c36
1 files changed, 35 insertions, 1 deletions
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) {