This commit is contained in:
Miloslav Číž 2019-11-09 22:01:19 +01:00
parent 16dbf392fc
commit 5eae4f8f29

30
main.c
View File

@ -347,7 +347,7 @@ typedef struct
#define SFG_WEAPON_SHOTGUN_COOLDOWN_FRAMES \ #define SFG_WEAPON_SHOTGUN_COOLDOWN_FRAMES \
(SFG_WEAPON_SHOTGUN_COOLDOWN / SFG_MS_PER_FRAME) (SFG_WEAPON_SHOTGUN_COOLDOWN / SFG_MS_PER_FRAME)
#define SFG_HUD_MARGIN (SFG_GAME_RESOLUTION_X / 20) #define SFG_HUD_MARGIN (SFG_GAME_RESOLUTION_X / 40)
#define SFG_HUD_HEALTH_INDICATOR_WIDTH_PIXELS \ #define SFG_HUD_HEALTH_INDICATOR_WIDTH_PIXELS \
(SFG_GAME_RESOLUTION_Y / SFG_HUD_HEALTH_INDICATOR_WIDTH) (SFG_GAME_RESOLUTION_Y / SFG_HUD_HEALTH_INDICATOR_WIDTH)
@ -359,6 +359,9 @@ typedef struct
#define SFG_HUD_HEALTH_INDICATOR_DURATION_FRAMES 1 #define SFG_HUD_HEALTH_INDICATOR_DURATION_FRAMES 1
#endif #endif
#define SFG_HUD_BAR_HEIGHT \
(SFG_FONT_CHARACTER_SIZE * SFG_FONT_SIZE_MEDIUM + SFG_HUD_MARGIN * 2 + 1)
/* /*
GLOBAL VARIABLES GLOBAL VARIABLES
=============================================================================== ===============================================================================
@ -603,7 +606,7 @@ void SFG_initPlayer()
SFG_player.camera.resolution.x = SFG_player.camera.resolution.x =
SFG_GAME_RESOLUTION_X / SFG_RAYCASTING_SUBSAMPLE; SFG_GAME_RESOLUTION_X / SFG_RAYCASTING_SUBSAMPLE;
SFG_player.camera.resolution.y = SFG_GAME_RESOLUTION_Y; SFG_player.camera.resolution.y = SFG_GAME_RESOLUTION_Y - SFG_HUD_BAR_HEIGHT;
SFG_player.camera.height = RCL_UNITS_PER_SQUARE * 12; SFG_player.camera.height = RCL_UNITS_PER_SQUARE * 12;
SFG_player.camera.position.x = RCL_UNITS_PER_SQUARE * 15; SFG_player.camera.position.x = RCL_UNITS_PER_SQUARE * 15;
@ -2323,6 +2326,8 @@ void SFG_drawWeapon(int16_t bobOffset)
uint32_t animationLength = SFG_WEAPON_SHOTGUN_COOLDOWN_FRAMES; uint32_t animationLength = SFG_WEAPON_SHOTGUN_COOLDOWN_FRAMES;
bobOffset -= SFG_HUD_BAR_HEIGHT;
if (shotAnimationFrame < animationLength) if (shotAnimationFrame < animationLength)
{ {
if (SFG_player.weapon == SFG_WEAPON_KNIFE) if (SFG_player.weapon == SFG_WEAPON_KNIFE)
@ -2502,15 +2507,30 @@ void SFG_draw()
SFG_player.camera.height -= headBobOffset; SFG_player.camera.height -= headBobOffset;
#endif #endif
SFG_drawWeapon(weaponBobOffset);
// draw the HUD: // draw the HUD:
// bar
uint8_t color = 5;
for (uint16_t j = SFG_GAME_RESOLUTION_Y - SFG_HUD_BAR_HEIGHT;
j < SFG_GAME_RESOLUTION_Y; ++j)
{
for (uint16_t i = 0; i < SFG_GAME_RESOLUTION_X; ++i)
SFG_setGamePixel(i,j,color);
color = 2;
}
SFG_drawNumber( // health SFG_drawNumber( // health
SFG_player.health, SFG_player.health,
SFG_HUD_MARGIN, SFG_HUD_MARGIN,
SFG_GAME_RESOLUTION_Y - SFG_HUD_MARGIN - SFG_GAME_RESOLUTION_Y - SFG_HUD_MARGIN -
SFG_FONT_CHARACTER_SIZE * SFG_FONT_SIZE_MEDIUM, SFG_FONT_CHARACTER_SIZE * SFG_FONT_SIZE_MEDIUM,
SFG_FONT_SIZE_MEDIUM, SFG_FONT_SIZE_MEDIUM,
SFG_player.health > SFG_PLAYER_HEALTH_WARNING_LEVEL ? 7 : 175); SFG_player.health > SFG_PLAYER_HEALTH_WARNING_LEVEL ? 4 : 175);
SFG_drawNumber( // ammo SFG_drawNumber( // ammo
20, 20,
@ -2519,9 +2539,7 @@ void SFG_draw()
SFG_GAME_RESOLUTION_Y - SFG_HUD_MARGIN - SFG_GAME_RESOLUTION_Y - SFG_HUD_MARGIN -
SFG_FONT_CHARACTER_SIZE * SFG_FONT_SIZE_MEDIUM, SFG_FONT_CHARACTER_SIZE * SFG_FONT_SIZE_MEDIUM,
SFG_FONT_SIZE_MEDIUM, SFG_FONT_SIZE_MEDIUM,
7); 4);
SFG_drawWeapon(weaponBobOffset);
if (SFG_gameFrame - SFG_player.lastHurtFrame if (SFG_gameFrame - SFG_player.lastHurtFrame
<= SFG_HUD_HEALTH_INDICATOR_DURATION_FRAMES) <= SFG_HUD_HEALTH_INDICATOR_DURATION_FRAMES)