From cc2c4fccadf7089176cde2f20a3646ae3a8e417d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Mustoha?= Date: Fri, 19 Apr 2024 15:57:31 +0200 Subject: [PATCH] Turned the coin powerup color into an enum --- src/smw/objectgame.cpp | 11 ++++++----- src/smw/objects/powerup/PU_CoinPowerup.cpp | 4 ++-- src/smw/objects/powerup/PU_CoinPowerup.h | 10 +++++++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/smw/objectgame.cpp b/src/smw/objectgame.cpp index 04ce9a53..4fd6ecff 100644 --- a/src/smw/objectgame.cpp +++ b/src/smw/objectgame.cpp @@ -86,19 +86,20 @@ IO_MovingObject* spawnSpecialPowerup(short type, short spawnX, short spawnY) case JAIL_KEY_POWERUP: return new PU_JailKeyPowerup(&rm->spr_jailkeypowerup, spawnX, spawnY); case COIN_POWERUP: { short iRandCoin = RANDOM_INT(9); - short iCoin = 2; + CoinColor color = CoinColor::Yellow; if (iRandCoin == 8) - iCoin = 3; + color = CoinColor::Blue; else if (iRandCoin >= 6) - iCoin = 1; + color = CoinColor::Green; else if (iRandCoin >= 3) - iCoin = 0; + color = CoinColor::Red; static short iCoinValue[4] = {3, 5, 2, 10}; static short iGreedValue[4] = {10, 15, 5, 20}; + const size_t colorIdx = static_cast(color); - return new PU_CoinPowerup(&rm->spr_coin, spawnX, spawnY, iCoin, game_values.gamemode->gamemode == game_mode_greed ? iGreedValue[iCoin] : iCoinValue[iCoin]); + return new PU_CoinPowerup(&rm->spr_coin, spawnX, spawnY, color, game_values.gamemode->gamemode == game_mode_greed ? iGreedValue[colorIdx] : iCoinValue[colorIdx]); } case MINIGAME_COIN: return new MO_Coin(&rm->spr_coin, 0.0f, -VELJUMP / 2.0, spawnX, spawnY, 2, -1, 2, 0, false); case SECRET1_POWERUP: return new PU_SecretPowerup(&rm->spr_secret1, spawnX, spawnY, 0); diff --git a/src/smw/objects/powerup/PU_CoinPowerup.cpp b/src/smw/objects/powerup/PU_CoinPowerup.cpp index 6f963c10..0ad2ca03 100644 --- a/src/smw/objects/powerup/PU_CoinPowerup.cpp +++ b/src/smw/objects/powerup/PU_CoinPowerup.cpp @@ -12,9 +12,9 @@ extern CResourceManager* rm; //------------------------------------------------------------------------------ // class special extra coin powerup for coin or greed mode //------------------------------------------------------------------------------ -PU_CoinPowerup::PU_CoinPowerup(gfxSprite* nspr, short x, short y, short color, short value) +PU_CoinPowerup::PU_CoinPowerup(gfxSprite* nspr, short x, short y, CoinColor color, short value) : MO_Powerup(nspr, x, y, 4, 8, 30, 30, 1, 1) - , iColorOffsetY(color * 32) + , iColorOffsetY(static_cast(color) * 32) , iValue(value) { velx = 0.0f; diff --git a/src/smw/objects/powerup/PU_CoinPowerup.h b/src/smw/objects/powerup/PU_CoinPowerup.h index 44a874fa..c862d170 100644 --- a/src/smw/objects/powerup/PU_CoinPowerup.h +++ b/src/smw/objects/powerup/PU_CoinPowerup.h @@ -6,9 +6,17 @@ class CPlayer; class gfxSprite; +enum class CoinColor : unsigned char { + Red, + Green, + Yellow, + Blue, +}; + + class PU_CoinPowerup : public MO_Powerup { public: - PU_CoinPowerup(gfxSprite* nspr, short x, short y, short color, short value); + PU_CoinPowerup(gfxSprite* nspr, short x, short y, CoinColor color, short value); void update() override; void draw() override;