From 8a9e46bbc358049f1299eb6bd3bfe3a52dd880c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Mustoha?= Date: Thu, 18 Apr 2024 10:25:20 +0200 Subject: [PATCH] Replaced the raw shell type number with an enum --- src/smw/GSGameplay.cpp | 8 ++++---- src/smw/objectgame.cpp | 8 ++++---- src/smw/objects/carriable/CO_Shell.cpp | 8 ++++---- src/smw/objects/carriable/CO_Shell.h | 13 +++++++++++-- src/smw/objects/moving/MO_BuzzyBeetle.cpp | 2 +- src/smw/objects/moving/MO_FrenzyCard.cpp | 8 ++++---- src/smw/objects/moving/MO_Koopa.cpp | 4 ++-- src/smw/objects/moving/MO_Spiny.cpp | 2 +- src/smw/player.cpp | 8 ++++---- 9 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/smw/GSGameplay.cpp b/src/smw/GSGameplay.cpp index d804d17d..b2a2c09f 100644 --- a/src/smw/GSGameplay.cpp +++ b/src/smw/GSGameplay.cpp @@ -2146,28 +2146,28 @@ void GameplayState::handleInput() if (event.key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) objectcontainer[0].add(new PU_Tanooki(list_players[0]->leftX() + 32, list_players[0]->topY())); else if (event.key.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) - objectcontainer[1].add(new CO_Shell(0, list_players[0]->leftX() + 32, list_players[0]->topY(), true, true, true, false)); + objectcontainer[1].add(new CO_Shell(ShellType::Green, list_players[0]->leftX() + 32, list_players[0]->topY(), true, true, true, false)); else objectcontainer[0].add(new PU_ExtraGuyPowerup(&rm->spr_3uppowerup, list_players[0]->leftX() + 32, list_players[0]->topY(), 1, true, 0, 30, 30, 1, 1, 3)); } else if (event.key.keysym.sym == SDLK_5) { if (event.key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) objectcontainer[0].add(new PU_PWingsPowerup(&rm->spr_pwingspowerup, list_players[0]->leftX() + 32, list_players[0]->topY())); else if (event.key.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) - objectcontainer[1].add(new CO_Shell(1, list_players[0]->leftX() + 32, list_players[0]->topY(), false, true, true, false)); + objectcontainer[1].add(new CO_Shell(ShellType::Red, list_players[0]->leftX() + 32, list_players[0]->topY(), false, true, true, false)); else objectcontainer[0].add(new PU_ExtraGuyPowerup(&rm->spr_5uppowerup, list_players[0]->leftX() + 32, list_players[0]->topY(), 1, true, 0, 30, 30, 1, 1, 5)); } else if (event.key.keysym.sym == SDLK_6) { if (event.key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) objectcontainer[1].add(new CO_Spring(&rm->spr_spring, list_players[0]->leftX() + 32, list_players[0]->topY(), true)); else if (event.key.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) - objectcontainer[1].add(new CO_Shell(2, list_players[0]->leftX() + 32, list_players[0]->topY(), false, false, true, true)); + objectcontainer[1].add(new CO_Shell(ShellType::Spiny, list_players[0]->leftX() + 32, list_players[0]->topY(), false, false, true, true)); else objectcontainer[0].add(new PU_FirePowerup(&rm->spr_firepowerup, list_players[0]->leftX() + 32, list_players[0]->topY(), 1, true, 0, 30, 30, 1, 1)); } else if (event.key.keysym.sym == SDLK_7) { if (event.key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) objectcontainer[1].add(new CO_ThrowBox(&rm->spr_throwbox, list_players[0]->leftX() + 32, list_players[0]->topY(), (RANDOM_INT(NUM_POWERUPS) + 3) - 3)); else if (event.key.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) - objectcontainer[1].add(new CO_Shell(3, list_players[0]->leftX() + 32, list_players[0]->topY(), false, true, false, false)); + objectcontainer[1].add(new CO_Shell(ShellType::Buzzy, list_players[0]->leftX() + 32, list_players[0]->topY(), false, true, false, false)); else objectcontainer[0].add(new PU_HammerPowerup(&rm->spr_hammerpowerup, list_players[0]->leftX() + 32, list_players[0]->topY(), 1, true, 0, 30, 30, 1, 1)); } else if (event.key.keysym.sym == SDLK_8) { diff --git a/src/smw/objectgame.cpp b/src/smw/objectgame.cpp index 93de3fc8..f64f6dc5 100644 --- a/src/smw/objectgame.cpp +++ b/src/smw/objectgame.cpp @@ -188,19 +188,19 @@ IO_MovingObject * createpowerup(short iType, short ix, short iy, bool side, bool break; } case 12: { - shell = new CO_Shell(0, iSpawnX, iSpawnY, true, true, true, false); + shell = new CO_Shell(ShellType::Green, iSpawnX, iSpawnY, true, true, true, false); break; } case 13: { - shell = new CO_Shell(1, iSpawnX, iSpawnY, false, true, true, false); + shell = new CO_Shell(ShellType::Red, iSpawnX, iSpawnY, false, true, true, false); break; } case 14: { - shell = new CO_Shell(2, iSpawnX, iSpawnY, false, false, true, true); + shell = new CO_Shell(ShellType::Spiny, iSpawnX, iSpawnY, false, false, true, true); break; } case 15: { - shell = new CO_Shell(3, iSpawnX, iSpawnY, false, true, false, false); + shell = new CO_Shell(ShellType::Buzzy, iSpawnX, iSpawnY, false, true, false, false); break; } case 16: { diff --git a/src/smw/objects/carriable/CO_Shell.cpp b/src/smw/objects/carriable/CO_Shell.cpp index 2a23d149..305321ed 100644 --- a/src/smw/objects/carriable/CO_Shell.cpp +++ b/src/smw/objects/carriable/CO_Shell.cpp @@ -24,8 +24,8 @@ extern CResourceManager* rm; // state 1: Shell is moving // state 2: Shell is waiting to be picked up // state 3: Shell is being held -CO_Shell::CO_Shell(short type, short x, short y, bool dieOnMovingPlayerCollision, bool dieOnHoldingPlayerCollision, bool dieOnFire, bool killBouncePlayer) - : MO_CarriedObject(&rm->spr_shell, x, y, 4, 4, 30, 20, 1, 11, 0, type * 32, 32, 32) +CO_Shell::CO_Shell(ShellType type, short x, short y, bool dieOnMovingPlayerCollision, bool dieOnHoldingPlayerCollision, bool dieOnFire, bool killBouncePlayer) + : MO_CarriedObject(&rm->spr_shell, x, y, 4, 4, 30, 20, 1, 11, 0, static_cast(type) * 32, 32, 32) { iShellType = type; @@ -48,7 +48,7 @@ CO_Shell::CO_Shell(short type, short x, short y, bool dieOnMovingPlayerCollision iDestY = iy - collisionHeight; fy = iDestY + 32.0f; - iColorOffsetY = type * 32; + iColorOffsetY = static_cast(type) * 32; iKillCounter = 0; iNoOwnerKillTime = 0; @@ -474,7 +474,7 @@ void CO_Shell::Die() return; } - eyecandy[2].add(new EC_FallingObject(&rm->spr_shelldead, ix, iy, -velx / 4.0f, -VELJUMP / 2.0f, 1, 0, iShellType * 32, 0, 32, 32)); + eyecandy[2].add(new EC_FallingObject(&rm->spr_shelldead, ix, iy, -velx / 4.0f, -VELJUMP / 2.0f, 1, 0, static_cast(iShellType) * 32, 0, 32, 32)); dead = true; ifSoundOnPlay(rm->sfx_kicksound); iKillCounter = 0; diff --git a/src/smw/objects/carriable/CO_Shell.h b/src/smw/objects/carriable/CO_Shell.h index 2ab08416..addfaf53 100644 --- a/src/smw/objects/carriable/CO_Shell.h +++ b/src/smw/objects/carriable/CO_Shell.h @@ -6,9 +6,18 @@ class CPlayer; class gfxSprite; class Spotlight; + +enum class ShellType : unsigned char { + Green, + Red, + Spiny, + Buzzy, +}; + + class CO_Shell : public MO_CarriedObject { public: - CO_Shell(short type, short x, short y, bool dieOnMovingPlayerCollision, bool dieOnHoldingPlayerCollision, bool dieOnFire, bool killBouncePlayer); + CO_Shell(ShellType type, short x, short y, bool dieOnMovingPlayerCollision, bool dieOnHoldingPlayerCollision, bool dieOnFire, bool killBouncePlayer); void update() override; void draw() override; @@ -43,7 +52,7 @@ class CO_Shell : public MO_CarriedObject { private: void Stop(); - short iShellType; + ShellType iShellType; short iIgnoreBounceTimer; short iDestY; diff --git a/src/smw/objects/moving/MO_BuzzyBeetle.cpp b/src/smw/objects/moving/MO_BuzzyBeetle.cpp index d571a6d4..0eda7398 100644 --- a/src/smw/objects/moving/MO_BuzzyBeetle.cpp +++ b/src/smw/objects/moving/MO_BuzzyBeetle.cpp @@ -68,7 +68,7 @@ void MO_BuzzyBeetle::Die() void MO_BuzzyBeetle::DropShell(bool fBounce, bool fFlip) { // Give the shell a state 2 so it is already spawned but sitting - CO_Shell* shell = new CO_Shell(3, ix - 1, iy, false, true, false, false); + CO_Shell* shell = new CO_Shell(ShellType::Buzzy, ix - 1, iy, false, true, false, false); shell->nospawn(iy, fBounce); if (fFlip) diff --git a/src/smw/objects/moving/MO_FrenzyCard.cpp b/src/smw/objects/moving/MO_FrenzyCard.cpp index 01558a75..f8e1f3a0 100644 --- a/src/smw/objects/moving/MO_FrenzyCard.cpp +++ b/src/smw/objects/moving/MO_FrenzyCard.cpp @@ -44,25 +44,25 @@ bool MO_FrenzyCard::collide(CPlayer* player) } else { switch (type) { case 14: { - CO_Shell* shell = new CO_Shell(0, 0, 0, true, true, true, false); + CO_Shell* shell = new CO_Shell(ShellType::Green, 0, 0, true, true, true, false); if (objectcontainer[1].add(shell)) shell->UsedAsStoredPowerup(player); break; } case 15: { - CO_Shell* shell = new CO_Shell(1, 0, 0, false, true, true, false); + CO_Shell* shell = new CO_Shell(ShellType::Red, 0, 0, false, true, true, false); if (objectcontainer[1].add(shell)) shell->UsedAsStoredPowerup(player); break; } case 16: { - CO_Shell* shell = new CO_Shell(2, 0, 0, false, false, true, true); + CO_Shell* shell = new CO_Shell(ShellType::Spiny, 0, 0, false, false, true, true); if (objectcontainer[1].add(shell)) shell->UsedAsStoredPowerup(player); break; } case 17: { - CO_Shell* shell = new CO_Shell(3, 0, 0, false, true, false, false); + CO_Shell* shell = new CO_Shell(ShellType::Buzzy, 0, 0, false, true, false, false); if (objectcontainer[1].add(shell)) shell->UsedAsStoredPowerup(player); break; diff --git a/src/smw/objects/moving/MO_Koopa.cpp b/src/smw/objects/moving/MO_Koopa.cpp index e7a705f4..5bc4f2cb 100644 --- a/src/smw/objects/moving/MO_Koopa.cpp +++ b/src/smw/objects/moving/MO_Koopa.cpp @@ -94,9 +94,9 @@ void MO_Koopa::DropShell(bool fBounce, bool fFlip) CO_Shell* shell; if (fRed) - shell = new CO_Shell(1, ix - 1, iy + 8, false, true, true, false); + shell = new CO_Shell(ShellType::Red, ix - 1, iy + 8, false, true, true, false); else - shell = new CO_Shell(0, ix - 1, iy + 8, true, true, true, false); + shell = new CO_Shell(ShellType::Green, ix - 1, iy + 8, true, true, true, false); shell->nospawn(iy + 8, fBounce); diff --git a/src/smw/objects/moving/MO_Spiny.cpp b/src/smw/objects/moving/MO_Spiny.cpp index faa24dbc..5de27645 100644 --- a/src/smw/objects/moving/MO_Spiny.cpp +++ b/src/smw/objects/moving/MO_Spiny.cpp @@ -75,7 +75,7 @@ void MO_Spiny::Die() void MO_Spiny::DropShell(bool fBounce, bool fFlip) { // Give the shell a state 2 so it is already spawned but sitting - CO_Shell* shell = new CO_Shell(2, ix - 1, iy, false, true, false, false); + CO_Shell* shell = new CO_Shell(ShellType::Spiny, ix - 1, iy, false, true, false, false); shell->nospawn(iy, fBounce); if (fFlip) diff --git a/src/smw/player.cpp b/src/smw/player.cpp index df08e4b6..68498dc3 100644 --- a/src/smw/player.cpp +++ b/src/smw/player.cpp @@ -758,25 +758,25 @@ void CPlayer::triggerPowerup() break; } case 12: { - CO_Shell * shell = new CO_Shell(0, 0, 0, true, true, true, false); + CO_Shell * shell = new CO_Shell(ShellType::Green, 0, 0, true, true, true, false); if (objectcontainer[1].add(shell)) shell->UsedAsStoredPowerup(this); break; } case 13: { - CO_Shell * shell = new CO_Shell(1, 0, 0, false, true, true, false); + CO_Shell * shell = new CO_Shell(ShellType::Red, 0, 0, false, true, true, false); if (objectcontainer[1].add(shell)) shell->UsedAsStoredPowerup(this); break; } case 14: { - CO_Shell * shell = new CO_Shell(2, 0, 0, false, false, true, true); + CO_Shell * shell = new CO_Shell(ShellType::Spiny, 0, 0, false, false, true, true); if (objectcontainer[1].add(shell)) shell->UsedAsStoredPowerup(this); break; } case 15: { - CO_Shell * shell = new CO_Shell(3, 0, 0, false, true, false, false); + CO_Shell * shell = new CO_Shell(ShellType::Buzzy, 0, 0, false, true, false, false); if (objectcontainer[1].add(shell)) shell->UsedAsStoredPowerup(this); break;