From 70f7f72a80f92fcfec9761678ad5f7829f93e0e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Mon, 13 Jan 2020 18:59:36 +0100 Subject: [PATCH] Take ammo --- constants.h | 12 ++++++++++++ main.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/constants.h b/constants.h index 28976b5..193d523 100644 --- a/constants.h +++ b/constants.h @@ -132,6 +132,18 @@ #define SFG_MAX_DOORS 32 +#define SFG_AMMO_BULLETS 0 +#define SFG_AMMO_ROCKETS 1 +#define SFG_AMMO_PLASMA 2 + +#define SFG_AMMO_INCREASE_BULLETS 10 +#define SFG_AMMO_INCREASE_ROCKETS 5 +#define SFG_AMMO_INCREASE_PLASMA 8 + +#define SFG_AMMO_TOTAL 3 + +#define SFG_AMMO_NONE SFG_AMMO_TOTAL + // ---------------------------- // derived constants diff --git a/main.c b/main.c index 7a2f0a6..12dcb3a 100755 --- a/main.c +++ b/main.c @@ -212,14 +212,16 @@ struct for determining whether player is in the air. */ uint16_t headBobFrame; - uint8_t weapon; ///< currently selected weapon + uint8_t weapon; ///< currently selected weapon - uint8_t health; + uint8_t health; uint32_t weaponCooldownStartFrame; /**< frame from which weapon cooldown is counted */ uint32_t lastHurtFrame; uint32_t lastItemTakenFrame; + + uint8_t ammo[SFG_AMMO_TOTAL]; } SFG_player; RCL_RayConstraints SFG_rayConstraints; @@ -345,6 +347,22 @@ uint8_t SFG_getDamageValue(uint8_t attackType) return value; } +/** + Returns ammo type for given weapon. +*/ +uint8_t SFG_weaponAmmo(uint8_t weapon) +{ + if (weapon == SFG_WEAPON_KNIFE) + return SFG_AMMO_NONE; + if (weapon == SFG_WEAPON_MACHINE_GUN || + weapon == SFG_WEAPON_SHOTGUN) + return SFG_AMMO_BULLETS; + else if (weapon == SFG_WEAPON_ROCKET_LAUNCHER) + return SFG_AMMO_ROCKETS; + else + return SFG_AMMO_PLASMA; +} + RCL_Unit SFG_taxicabDistance( RCL_Unit x0, RCL_Unit y0, RCL_Unit z0, RCL_Unit x1, RCL_Unit y1, RCL_Unit z1) { @@ -909,6 +927,9 @@ void SFG_initPlayer() SFG_player.lastItemTakenFrame = SFG_gameFrame; SFG_player.health = SFG_PLAYER_MAX_HEALTH; + + for (uint8_t i = 0; i < SFG_AMMO_TOTAL; ++i) + SFG_player.ammo[i] = 0; } RCL_Unit SFG_ceilingHeightAt(int16_t x, int16_t y) @@ -2029,12 +2050,15 @@ void SFG_gameStep() break; case SFG_LEVEL_ELEMENT_BULLETS: + SFG_player.ammo[SFG_AMMO_BULLETS] += SFG_AMMO_INCREASE_BULLETS; break; case SFG_LEVEL_ELEMENT_ROCKETS: + SFG_player.ammo[SFG_AMMO_ROCKETS] += SFG_AMMO_INCREASE_ROCKETS; break; case SFG_LEVEL_ELEMENT_PLASMA: + SFG_player.ammo[SFG_AMMO_PLASMA] += SFG_AMMO_INCREASE_PLASMA; break; default: @@ -2042,7 +2066,7 @@ void SFG_gameStep() break; } - if (eliminate) + if (eliminate) // take the item { SFG_removeItem(i); SFG_player.lastItemTakenFrame = SFG_gameFrame; @@ -2850,7 +2874,7 @@ void SFG_draw() SFG_player.health > SFG_PLAYER_HEALTH_WARNING_LEVEL ? 4 : 175); SFG_drawNumber( // ammo - 20, + SFG_player.ammo[SFG_weaponAmmo(SFG_player.weapon)], SFG_GAME_RESOLUTION_X - SFG_HUD_MARGIN - SFG_FONT_CHARACTER_SIZE * SFG_FONT_SIZE_MEDIUM * 3, SFG_GAME_RESOLUTION_Y - SFG_HUD_MARGIN -