Player class
#include <Jazz2/Actors/Player.h>
Represents a controllable player.
The player-controlled rabbit character (Jazz, Spaz or Lori in JJ2) that runs, jumps, fires weapons, collects items and takes damage. Each character has its own special move (e.g., buttstomp, uppercut or sidekick), can enter a temporary Sugar Rush and may be morphed into other forms such as the Frog.
Base classes
- class ActorBase
- Base class of an object.
Derived classes
- class MpPlayer
- Player in online session.
Public types
-
enum class Modifier : std::
uint8_t { None, Airboard, Copter, LizardCopter } - Modifier.
-
enum class SpecialMoveType : std::
uint8_t { None, Buttstomp, Uppercut, Sidekick } - Special move type.
- enum class InvulnerableType { Transient, Blinking, Shielded }
- Type of invulnerability.
Public static functions
-
static void DrawShield(RenderQueue& renderQueue,
ShieldType shieldType,
float shieldTime,
Metadata* metadata,
float elapsedFrames,
Vector2f pos,
std::
uint16_t baseLayer, std:: unique_ptr<RenderCommand>(&shieldRenderCommands)[2]) - Draws the active shield decoration around a position.
Constructors, destructors, conversion operators
Public functions
-
auto GetPlayerIndex() const -> std::
uint8_t - Returns player index.
- auto GetPlayerType() const -> PlayerType
- Returns player type.
-
auto GetEffectiveFurColor() const -> std::
uint32_t - Returns the fur color to actually use for this player.
-
auto GetPaletteOffset() const -> std::
int32_t - Returns this player's flat offset into the shared palette texture (for the palette-aware shader).
- auto GetSpecialMove() const -> SpecialMoveType
- Returns current special move.
-
auto GetWeaponAmmo() const -> ArrayView<const std::
uint16_t> - Return weapon ammo.
-
auto GetWeaponUpgrades() const -> ArrayView<const std::
uint8_t> - Returns weapon upgrades.
- auto HasSugarRush() const -> bool
- Returns
trueif sugar rush is active. - auto CanJump() const -> bool
- Returns
trueif the player can jump. - auto CanBreakSolidObjects() const -> bool
- Returns
trueif the player can bread solid objects. - auto CanMoveVertically() const -> bool
- Returns
trueif the player can move vertically, i.e. not affected by gravity. - auto IsContinuousJumpAllowed() const -> bool virtual
- Returns
trueif continuous jump is allowed. - auto IsLedgeClimbAllowed() const -> bool virtual
- Returns
trueif ledge climbing is allowed. -
auto OnLevelChanging(Actors::
ActorBase* initiator, ExitType exitType) -> bool virtual - Called when the level is about to change.
- void ReceiveLevelCarryOver(ExitType exitType, const PlayerCarryOver& carryOver) virtual
- Called at the beginning of the next level to reveive carry over information.
- auto PrepareLevelCarryOver() -> PlayerCarryOver virtual
- Returns current carry over information.
-
void InitializeFromStream(ILevelHandler* levelHandler,
Stream& src,
std::
uint16_t version) - Initializes player state from a stream.
- void SerializeResumableToStream(Stream& dest)
- Serializes player state to a stream.
- auto Respawn(Vector2f pos) -> bool virtual
- Respawns the player.
- void WarpToPosition(Vector2f pos, WarpFlags flags) virtual
- Warps to a given position.
- void WarpToCheckpoint()
- Warps to the last checkpoint.
- auto GetModifier() const -> Modifier
- Returns current modifier.
-
auto SetModifier(Modifier modifier,
const std::
shared_ptr<ActorBase>& decor = nullptr) -> bool virtual - Sets current modifier.
-
auto TakeDamage(std::
int32_t amount, float pushForce = 0.0f, bool ignoreInvulnerable = false) -> bool virtual - Takes damage.
- auto Freeze(float timeLeft) -> bool virtual
- Freezes the player for specified time.
- void SetInvulnerability(float timeLeft, InvulnerableType type) virtual
- Sets invulnerability.
-
auto GetScore() const -> std::
int32_t - Returns score.
-
void AddScore(std::
int32_t amount) virtual - Adds score.
-
auto AddHealth(std::
int32_t amount) -> bool virtual - Adds health.
-
auto GetLives() const -> std::
int32_t - Returns lives.
-
auto AddLives(std::
int32_t count) -> bool virtual - Adds lives.
-
auto GetCoins() const -> std::
int32_t - Returns coins.
-
void AddCoins(std::
int32_t count) - Adds coins.
-
void AddCoinsInternal(std::
int32_t count) - Adds coins without notification (internal use only).
-
auto GetGems(std::
uint8_t gemType) const -> std:: int32_t - Returns gems.
-
void AddGems(std::
uint8_t gemType, std:: int32_t count) - Adds gems.
-
auto GetConsumedFood() const -> std::
int32_t - Returns food eaten.
- void ConsumeFood(bool isDrinkable)
- Consumes food.
- void ActivateSugarRush(float duration)
- Activates sugar rush.
-
auto AddAmmo(WeaponType weaponType,
std::
int16_t count) -> bool virtual - Adds weapon ammo.
-
void AddWeaponUpgrade(WeaponType weaponType,
std::
uint8_t upgrade) virtual - Adds weapon upgrade.
-
auto AddFastFire(std::
int32_t count) -> bool - Adds fast fire.
- auto MorphTo(PlayerType type) -> bool virtual
- Morphs to a given player type.
- void MorphRevert()
- Reverts morpth to the original player type.
- auto SetDizzy(float timeLeft) -> bool virtual
- Sets duration of dizziness.
- auto GetActiveShield() const -> ShieldType
- Returns active shield.
- auto SetShield(ShieldType shieldType, float timeLeft) -> bool virtual
- Sets active shield.
- auto IncreaseShieldTime(float timeLeft) -> bool virtual
- Increases active shield time.
-
auto SpawnBird(std::
uint8_t type, Vector2f pos) -> bool - Spawns bird companion.
- auto DisableControllable(float timeout) -> bool
- Disables controls for specified time.
- void SetCheckpoint(Vector2f pos, float ambientLight)
- Sets checkpoint.
- auto GetCarryingObject() const -> ActorBase*
- Returns carrying object.
- void CancelCarryingObject(ActorBase* expectedActor = nullptr)
- Cancels carrying object.
-
void UpdateCarryingObject(ActorBase* actor,
SuspendType suspendType = SuspendType::
None) - Updates carrying object.
-
void SwitchToWeaponByIndex(std::
uint32_t weaponIndex) - Switches current weapon to a given index.
- void GetFirePointAndAngle(Vector3i& initialPos, Vector2f& gunspotPos, float& angle)
- Returns weapon fire point and angle.
Protected types
- enum class LevelExitingState { None, Waiting, WaitingForWarp, Transition, Ready }
- State of level exiting.
- enum class WeaponWheelState { Hidden, Opening, Visible, Closing }
- State of HUD weapon wheel.
- enum class SetCurrentWeaponReason { Unknown, User, Rollback, AddAmmo, AddUpgrade, Shield }
- Reason the current weapon was changed.
Protected functions
- auto OnActivatedAsync(const ActorActivationDetails& details) -> Task<bool> override
- Called when the object is created and activated.
- auto OnTileDeactivated() -> bool override
- Called when corresponding tile should be deactivated.
- auto OnPerish(ActorBase* collider) -> bool override
- Called when the object has no health left and should perish.
- void OnUpdate(float timeMult) override
- Called every frame to update the object state.
- void OnUpdateHitbox() override
- Called when the hitbox needs to be updated.
- auto OnDraw(RenderQueue& renderQueue) -> bool override
- Called when the object needs to be drawn.
- void OnEmitLights(SmallVectorImpl<LightEmitter>& lights) override
- Called when emitting lights.
- auto OnHandleCollision(ActorBase* other) -> bool override
- Called when the object collides with another object.
- void OnHitFloor(float timeMult) override
- Called when the object hits a floor.
- void OnHitCeiling(float timeMult) override
- Called when the object hits a ceiling.
- void OnHitWall(float timeMult) override
- Called when the object hits a wall.
- auto GetGravityModifier(float baseGravity, bool isRising) const -> float override
- Returns the gravity applied this frame, allowing it to be direction-dependent (e.g., the player's asymmetric jump arc).
- auto ApplyPlayerBump(Player& other, bool stackingEnabled) -> bool
- Keeps this player and
otherfrom overlapping (so they can't pass through) and bumps them apart. - void UpdatePlayerStacking(float timeMult, bool snap)
- Resolves this player standing on top of another player as a one-way platform.
- void DecreaseShieldTime(float time) virtual
- Reduces remaining shield time when a hit is absorbed (only if more than
timeremains). - void OnPushSolidObject(float timeMult, float pushSpeedX) virtual
- Called when a solid object is pushed.
- void OnHitSpring(Vector2f pos, Vector2f force, bool keepSpeedX, bool keepSpeedY, bool& removeSpecialMove) virtual
- Called when a spring is hit.
- void OnWaterSplash(Vector2f pos, bool inwards) virtual
- Called when water should splash.
-
auto PlayPlayerSfx(StringView identifier,
float gain = 1.0f,
float pitch = 1.0f) -> std::
shared_ptr<AudioBufferPlayer> - Plays a sound effect for the player.
- auto SetPlayerTransition(AnimState state, bool cancellable, bool removeControl, SpecialMoveType specialMove, Function<void()>&& callback = {}) -> bool
- Starts a player animation transition.
- auto CanFreefall() -> bool
- Returns
trueif the player should freefall. - void EndDamagingMove()
- Ends active damaging move.
- auto FireCurrentWeapon(WeaponType weaponType) -> bool virtual
- Fires currently equipped weapon.
- void EmitWeaponFlare() virtual
- Emits weapon flare after firing.
- void SetCurrentWeapon(WeaponType weaponType, SetCurrentWeaponReason reason) virtual
- Sets current weapon.
Constants
- static float MaxDashingSpeed protected constexpr
- Maximum horizontal speed while dashing.
- static float MaxRunningSpeed protected constexpr
- Maximum horizontal speed while running.
- static float MaxVineSpeed protected constexpr
- Maximum speed while climbing a vine.
- static float MaxDizzySpeed protected constexpr
- Maximum horizontal speed while dizzy.
- static float MaxShallowWaterSpeed protected constexpr
- Maximum horizontal speed in shallow water.
- static float Acceleration protected constexpr
- Horizontal acceleration.
- static float Deceleration protected constexpr
- Horizontal deceleration.
- static float MaxPushingSpeed protected constexpr
- Speed above which the player is no longer considered to be pushing.
- static float LegacyFrameRateScale protected constexpr
- Velocity scale that maps original JJ2 (70 Hz) per-tick values onto this engine's 60 Hz timeMult baseline.
- static float LegacyFrameRateScaleSqr protected constexpr
- Acceleration scale for the 70->60 Hz mapping, squared because position is the double integral of acceleration.
- static float LegacyGroundSpeedScale protected constexpr
- Non-Reforged ground max-speed scale.
- static float LegacyGroundAccelScale protected constexpr
- Non-Reforged ground acceleration/braking scale.
- static float LegacyRunBrakeScale protected constexpr
- Non-Reforged coast factor when reversing at running speed - low so pressing the opposite way keeps momentum noticeably longer than just releasing the key (which stops quickly).
- static float LegacyWalkBrakeScale protected constexpr
- Non-Reforged braking factor at walking speed - gentler than before so the player coasts longer before stopping/turning.
- static float LegacyReleaseBrakeScale protected constexpr
- Non-Reforged deceleration multiplier when the direction key is released - gentle so the player coasts to a stop.
- static float LegacyVerticalSpeedScale protected constexpr
- Non-Reforged vertical velocity scale.
- static float LegacyVerticalGravityScale protected constexpr
- Non-Reforged rising-gravity scale; the vertical tune is squared so jump height is preserved.
- static float LegacyFallGravityScale protected constexpr
- Non-Reforged falling-gravity scale; the original drops a touch faster than the rise, so less slow-down here.
- static float LegacyRiseSpeedCap protected constexpr
- Non-Reforged applied upward-speed cap (original JJ2 clamps applied vertical movement to 8 px/tick).
- static float LegacySpecialMoveScale protected constexpr
- Non-Reforged launch scale for vertical special moves (uppercut).
- static const char* WeaponNames protected constexpr
- Display names of all weapons.
Enum documentation
enum class Jazz2:: Actors:: Player:: Modifier : std:: uint8_t
Modifier.
| Enumerators | |
|---|---|
| None |
No modifier |
| Airboard |
Riding an airboard |
| Copter |
Using a copter |
| LizardCopter |
Using a lizard copter |
enum class Jazz2:: Actors:: Player:: SpecialMoveType : std:: uint8_t
Special move type.
| Enumerators | |
|---|---|
| None |
No special move |
| Buttstomp |
Buttstomp |
| Uppercut |
Uppercut |
| Sidekick |
Sidekick |
enum class Jazz2:: Actors:: Player:: InvulnerableType
Type of invulnerability.
| Enumerators | |
|---|---|
| Transient |
Invulnerable without any visual effect |
| Blinking |
Invulnerable with blinking effect |
| Shielded |
Invulnerable due to an active shield |
enum class Jazz2:: Actors:: Player:: LevelExitingState protected
State of level exiting.
| Enumerators | |
|---|---|
| None |
Not exiting |
| Waiting |
Waiting before exiting |
| WaitingForWarp |
Waiting for a warp to complete |
| Transition |
Playing the exit transition |
| Ready |
Ready to exit |
enum class Jazz2:: Actors:: Player:: WeaponWheelState protected
State of HUD weapon wheel.
| Enumerators | |
|---|---|
| Hidden |
Hidden |
| Opening |
Opening |
| Visible |
Visible |
| Closing |
Closing |
enum class Jazz2:: Actors:: Player:: SetCurrentWeaponReason protected
Reason the current weapon was changed.
| Enumerators | |
|---|---|
| Unknown |
Unspecified |
| User |
Set by the user |
| Rollback |
Set due to rollback |
| AddAmmo |
Set because an ammo for a new weapon was collected |
| AddUpgrade |
Set because a new upgrade for a weapon was collected |
| Shield |
Set because a shield was activated |
Function documentation
static void Jazz2:: Actors:: Player:: DrawShield(RenderQueue& renderQueue,
ShieldType shieldType,
float shieldTime,
Metadata* metadata,
float elapsedFrames,
Vector2f pos,
std:: uint16_t baseLayer,
std:: unique_ptr<RenderCommand>(&shieldRenderCommands)[2])
Draws the active shield decoration around a position.
| Parameters | |
|---|---|
| renderQueue | Render queue the shield draw commands are added to |
| shieldType | Active shield type |
| shieldTime | Remaining shield time, in frames (drives the fade-in/out alpha and scale) |
| metadata | Metadata holding the shield animations (the player's metadata) |
| elapsedFrames | Elapsed level frames, used to animate the shield |
| pos | World position the shield is centered on |
| baseLayer | Base render layer; the shield is drawn just behind and in front of it |
| shieldRenderCommands | Render commands owned by the caller, reused across frames |
Shared by the locally-controlled Player and by remote players (rendered as Actors::
std:: uint32_t Jazz2:: Actors:: Player:: GetEffectiveFurColor() const
Returns the fur color to actually use for this player.
The configured color, or 0 = none when the "Apply Colors" preference disables recoloring in the current session (or for this player index).
std:: int32_t Jazz2:: Actors:: Player:: GetPaletteOffset() const
Returns this player's flat offset into the shared palette texture (for the palette-aware shader).
Returns -1 if the player is not being recolored.
bool Jazz2:: Actors:: Player:: ApplyPlayerBump(Player& other,
bool stackingEnabled) protected
Keeps this player and other from overlapping (so they can't pass through) and bumps them apart.
| Parameters | |
|---|---|
| other | The other player in contact |
| stackingEnabled | When true, vertical overlap is left to UpdatePlayerStacking instead of bumped |
| Returns | true if the players were separated (a bump was applied) |
Equal-mass elastic separation along the axis of least penetration. Shared by local splitscreen co-op and online sessions (where Multiplayer::
void Jazz2:: Actors:: Player:: UpdatePlayerStacking(float timeMult,
bool snap) protected
Resolves this player standing on top of another player as a one-way platform.
| Parameters | |
|---|---|
| timeMult | Frame time multiplier |
| snap | Whether to reposition our feet onto the player below (the side that simulates this player); false only grounds it (the server's shadow of a remote player, whose position comes from its client) |
Carrying makes CanJump() return true (so the player can jump off) and zeroes vertical speed so it rests instead of falling through. Call before the physics update so jump input sees it. Shared by local splitscreen co-op and online sessions.
Variable documentation
static float Jazz2:: Actors:: Player:: MaxPushingSpeed protected constexpr
Speed above which the player is no longer considered to be pushing.
While genuinely pushing, the player is held to a slow speed (a wall pins it to 0, a movable object to roughly PushSpeed times 1.2). Once they break free and accelerate past this, the push animation ends even if the push grace timer (_pushFramesLeft) hasn't expired, so it doesn't linger while walking in open space.