Skip to content

Commit

Permalink
Turned the coin powerup color into an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyas committed Apr 19, 2024
1 parent fb4d3f4 commit cc2c4fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/smw/objectgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(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);
Expand Down
4 changes: 2 additions & 2 deletions src/smw/objects/powerup/PU_CoinPowerup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(color) * 32)
, iValue(value)
{
velx = 0.0f;
Expand Down
10 changes: 9 additions & 1 deletion src/smw/objects/powerup/PU_CoinPowerup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cc2c4fc

Please sign in to comment.