Skip to content

Commit

Permalink
Addressed comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pheazant committed Apr 15, 2024
1 parent 5fa56ea commit 026f960
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/smw/gamemodes/Star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void CGM_Star::playerextraguy(CPlayer &player, short iType)
}
}

bool CGM_Star::isplayerstar(CPlayer * player)
bool CGM_Star::isplayerstar(const CPlayer * player)
{
for (short iPlayer = 0; iPlayer < list_players_cnt - 1; iPlayer++) {
if (starPlayer[iPlayer] == player)
Expand Down
2 changes: 1 addition & 1 deletion src/smw/gamemodes/Star.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CGM_Star : public CGM_TimeLimit
PlayerKillType playerkilledself(CPlayer &player, KillStyle style);
void playerextraguy(CPlayer &player, short iType);

bool isplayerstar(CPlayer * player);
bool isplayerstar(const CPlayer * player);
CPlayer * swapplayer(short id, CPlayer * player);
CPlayer * getstarplayer(short id) {
return starPlayer[id];
Expand Down
7 changes: 2 additions & 5 deletions src/smw/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,10 +858,10 @@ void CPlayer::update_usePowerup()
triggerPowerup();
}

PlayerPalette CPlayer::getPlayerPalette()
PlayerPalette CPlayer::getPlayerPalette() const
{
if (isInvincible()) {
return static_cast<PlayerPalette>(animationstate);
return invincibility.getPlayerPalette();
}
if (game_values.gamemode->gamemode == game_mode_star) {
CGM_Star * starmode = (CGM_Star*) game_values.gamemode;
Expand Down Expand Up @@ -1720,9 +1720,6 @@ void CPlayer::SetupNewPlayer()
frozen = false;
frozentimer = 0;

animationstate = 0;
animationtimer = 0;

killsinrow = 0;
killsinrowinair = 0;
extrajumps = 0;
Expand Down
4 changes: 1 addition & 3 deletions src/smw/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class CPlayer
short getGlobalID() const { return globalID; }
short getTeamID() const { return teamID; }
short getColorID() const { return colorID; }
PlayerPalette getPlayerPalette();
PlayerPalette getPlayerPalette() const;

short leftX() const { return ix; }
short rightX() const { return ix + PW; }
Expand Down Expand Up @@ -314,8 +314,6 @@ class CPlayer
CPlayerAI * pPlayerAI;

gfxSprite *sprites[PGFX_LAST];
short animationstate;
short animationtimer;

uint8_t sprite_state;
short sprswitch;
Expand Down
24 changes: 10 additions & 14 deletions src/smw/player_components/PlayerInvincibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ void PlayerInvincibility::turn_on(CPlayer& player)
{
invincible = true;
timer = 0;
player.animationstate = 0;
player.animationtimer = 0;
player.shield.abort();

//Stop the invincible music if a player is already invincible
Expand All @@ -42,21 +40,19 @@ bool PlayerInvincibility::is_on() const
void PlayerInvincibility::update(CPlayer& player)
{
if (invincible) {
player.animationtimer++;

if ((player.animationtimer > 3 && timer < 480) || player.animationtimer > 6) {
player.animationtimer = 0;

player.animationstate++;
if (player.animationstate > 3)
player.animationstate = 0;
}

if (++timer > 580) {
player.animationstate = 0;
player.animationtimer = 0;
timer = 0;
invincible = false;
}
}
}

PlayerPalette PlayerInvincibility::getPlayerPalette() const
{
PlayerPalette invincibility_animation_states[4] = {normal, invincibility_1, invincibility_2, invincibility_3};
if (timer < 480) {
return invincibility_animation_states[(timer / 4) % 4];
} else {
return invincibility_animation_states[((timer - 4) / 7) % 4];
}
}
3 changes: 3 additions & 0 deletions src/smw/player_components/PlayerInvincibility.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef PLAYER_INVINCIBILITY
#define PLAYER_INVINCIBILITY

#include "gfx.h"

class CPlayer;

class PlayerInvincibility
Expand All @@ -10,6 +12,7 @@ class PlayerInvincibility
void update(CPlayer& player);

bool is_on() const;
PlayerPalette getPlayerPalette() const;
void turn_on(CPlayer& player);

private:
Expand Down

0 comments on commit 026f960

Please sign in to comment.