Jazz2::Actors::Weapons::Thunderbolt class

Thunderbolt (shot).

Lightning weapon that strikes instantly as a beam spanning from the gun muzzle to a far point, damaging everything along its length and passing through solid tiles. The bolt follows the player's aim until they stop firing or change facing, then fades out.

Base classes

class ShotBase
Base class of a shot from a player's weapon.

Public static variables

static float BeamDistance constexpr
How far the beam extends from the muzzle.
static float LightProgressSpeed constexpr
How fast the beam lifetime progress advances per frame.
static std::uint32_t InitialShotAnimOffset constexpr
Offset added to the animation state of the first bolt of a burst.

Public static functions

static void CreateSparks(ILevelHandler* levelHandler, Metadata* metadata, Vector2f pos, Vector2f farPoint, std::uint16_t layer, float timeMult)
Occasionally spawns a spark discharging off the beam, shared with the remote representation.
static void EmitBeamLights(SmallVectorImpl<LightEmitter>& lights, Vector2f pos, Vector2f farPoint, float lightProgress, bool muzzleFlash)
Emits the beam lights, with a brief intense muzzle flash on the first bolt of a burst; shared with the remote representation.

Constructors, destructors, conversion operators

Thunderbolt()
Creates a new instance.

Public functions

void OnFire(const std::shared_ptr<ActorBase>& owner, Vector2f gunspotPos, Vector2f speed, float angle, bool isFacingLeft)
Called when the shot is fired.
auto OnHandleCollision(ActorBase* other) -> bool override
Called when the object collides with another object.
auto GetWeaponType() -> WeaponType override
Returns weapon type.

Protected functions

auto OnActivatedAsync(const ActorActivationDetails& details) -> Task<bool> override
Called when the object is created and activated.
void OnUpdate(float timeMult) override
Called every frame to update the object state.
void OnUpdateHitbox() override
Called when the hitbox needs to be updated.
void OnEmitLights(SmallVectorImpl<LightEmitter>& lights) override
Called when emitting lights.
void OnEmitRemotedLights(SmallVectorImpl<LightEmitter>& lights) override
Called when emitting lights that have to be replicated to remote peers.
void OnAnimationFinished() override
Called when an animation finished.
void OnHitWall(float timeMult) override
Called when the object hits a wall.
void OnRicochet() override
Called on shot ricochet.

Function documentation

void Jazz2::Actors::Weapons::Thunderbolt::OnEmitRemotedLights(SmallVectorImpl<LightEmitter>& lights) override protected

Called when emitting lights that have to be replicated to remote peers.

An object simulated on a multiplayer server is drawn on the clients by a stand-in that runs none of its logic, so the lights it emits have to be described to them explicitly. This defaults to OnEmitLights(), which is right for anything whose lighting belongs to the object itself.

Overriding it describes only the part that every observer must see. Lights that a client already produces on its own — decoration driven by a local preference, or an object whose stand-in replays the whole effect — are left out, so they aren't sent (and applied) twice.

Variable documentation

static std::uint32_t Jazz2::Actors::Weapons::Thunderbolt::InitialShotAnimOffset constexpr

Offset added to the animation state of the first bolt of a burst.

The bolt respawns every few frames while the trigger is held, but the muzzle flash should play only when the player starts shooting. The first bolt uses states 3/4 (aliases of the same beam graphics), carrying the distinction to remote clients over the existing animation synchronization.