Hurt player

This commit is contained in:
Miloslav Číž 2019-10-24 23:20:35 +02:00
parent 98dc694ba3
commit 2a7528cad0
2 changed files with 30 additions and 3 deletions

View File

@ -89,6 +89,11 @@
*/
#define SFG_EXPLOSION_DISTANCE 2048
/**
How much damage explosion causes in its range.
*/
#define SFG_EXPLOSION_DAMAGE 18
/**
Time, in ms, after which shotgun can be fired again.
*/
@ -99,4 +104,9 @@
*/
#define SFG_PLAYER_MAX_HEALTH 100
/**
At which value health indicator shows a warning (red color).
*/
#define SFG_PLAYER_HEALTH_WARNING_LEVEL 20
#endif // guard

23
main.c
View File

@ -1387,6 +1387,21 @@ RCL_Vector2D SFG_resolveCollisionWithElement(
return moveOffset;
}
/**
Adds or substracts player's health, which either hurts him (negative value)
or heals him (positive value).
*/
void SFG_playerChangeHealth(int8_t healthAdd)
{
int16_t health = SFG_player.health;
health += healthAdd;
health = RCL_clamp(health,0,SFG_PLAYER_MAX_HEALTH);
SFG_player.health = health;
}
void SFG_createExplosion(RCL_Unit x, RCL_Unit y, RCL_Unit z)
{
SFG_ProjectileRecord explostion;
@ -1405,6 +1420,8 @@ void SFG_createExplosion(RCL_Unit x, RCL_Unit y, RCL_Unit z)
SFG_createProjectile(explostion);
SFG_playerChangeHealth(-1 * SFG_EXPLOSION_DAMAGE);
SFG_pushPlayerAway(x,y,SFG_EXPLOSION_DISTANCE);
}
@ -2343,15 +2360,15 @@ void SFG_draw()
// draw the HUD:
SFG_drawNumber(
SFG_drawNumber( // health
SFG_player.health,
SFG_HUD_MARGIN,
SFG_GAME_RESOLUTION_Y - SFG_HUD_MARGIN -
SFG_FONT_CHARACTER_SIZE * SFG_FONT_SIZE_MEDIUM,
SFG_FONT_SIZE_MEDIUM,
7);
SFG_player.health > SFG_PLAYER_HEALTH_WARNING_LEVEL ? 7 : 175);
SFG_drawNumber(
SFG_drawNumber( // ammo
20,
SFG_GAME_RESOLUTION_X - SFG_HUD_MARGIN -
SFG_FONT_CHARACTER_SIZE * SFG_FONT_SIZE_MEDIUM * 3,