Jazz2::Actors::Player class

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.

Constructors, destructors, conversion operators

Player()
Creates a new instance.
~Player()

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 true if sugar rush is active.
auto CanJump() const -> bool
Returns true if the player can jump.
auto CanBreakSolidObjects() const -> bool
Returns true if the player can bread solid objects.
auto CanMoveVertically() const -> bool
Returns true if the player can move vertically, i.e. not affected by gravity.
auto IsContinuousJumpAllowed() const -> bool virtual
Returns true if continuous jump is allowed.
auto IsLedgeClimbAllowed() const -> bool virtual
Returns true if 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.
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 true if 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 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

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.