Jazz2::Actors::Enemies::EnemyBase class

Base class of an enemy.

Base for hostile creatures that hurt the player on contact. It provides the behavior shared by all enemies: collisions with the player and player shots, taking damage, freezing, awarding score, dropping random collectibles on death, and the white-mask hit-blinking effect.

Base classes

class Jazz2::Actors::ActorBase
Base class of an object.

Derived classes

class Jazz2::Actors::Bosses::BossBase
Base class of an enemy boss.
class Jazz2::Actors::Bosses::Robot
Robot (boss).
class Bat
Bat.
class Bee
Bee.
class Caterpillar
Caterpillar.
class Crab
Crab.
class Demon
Demon.
class Doggy
Doggy.
class Dragon
Dragon.
class Dragonfly
Dragonfly.
class FatChick
Fat chick.
class Fencer
Fencer.
class Fish
Fish.
class Helmut
Helmut.
class LabRat
Lab rat.
class Lizard
Lizard.
class LizardFloat
Floating lizard.
class MadderHatter
Madder hatter.
class Monkey
Monkey.
class Rapier
Rapier.
class Raven
Raven.
class Skeleton
Skeleton.
class Sparks
Sparks.
class Sucker
Sucker.
class SuckerFloat
Floating sucker.
class Turtle
Turtle.
class TurtleShell
Turtle shell.
class TurtleTough
Tough turtle.
class TurtleTube
Tube turtle.
class Witch
Witch.
class Jazz2::Actors::Environment::RollingRock
Rolling rock.
class Jazz2::Actors::Solid::SpikeBall
Spike ball.

Constructors, destructors, conversion operators

EnemyBase()
Creates a new instance.

Public functions

auto OnHandleCollision(ActorBase* other) -> bool override
Called when the object collides with another object.
auto CanCauseDamage(ActorBase* collider) -> bool override
Called to check whether collider can cause damage to the object.
auto GetContactThrowSpeed() const -> Vector2f virtual
Returns the speed a player it hurts is thrown with, zero for a plain hit.
auto TakesSingleBlastDamage() const -> bool virtual
Returns true if a TNT blast takes only one point of health however close it is.
auto CanHurtPlayer() const -> bool
Whether the enemy can hurt player.
auto GetScoreValue() const -> std::uint32_t
Returns the score awarded for destroying the enemy.
void SetScoreValue(std::uint32_t value)
Sets the score awarded for destroying the enemy.

Public variables

bool CanCollideWithShots
Whether the enemy should collide with player shots.

Protected static functions

static auto Sin1024(std::int32_t angle) -> float
Returns the sine of an angle in 1024 steps per turn, as the original's table.

Protected functions

void OnUpdate(float timeMult) override
Called every frame to update the object state.
void OnHealthChanged(ActorBase* collider) override
Called when health of the object changed.
auto OnPerish(ActorBase* collider) -> bool override
Called when the object has no health left and should perish.
void OnSerializeState(Stream& dest) override
Serializes the live state of the object to a level state snapshot.
void OnDeserializeState(Stream& src) override
Restores the live state of the object from a level state snapshot.
void AddScoreToCollider(ActorBase* collider)
Awards the enemy's score value to the collider (or its owner).
void SetHealthByDifficulty(std::int32_t health) virtual
Sets the enemy's health scaled by the current game difficulty.
void PlaceOnGround()
Snaps the enemy onto the ground below it.
auto CanMoveToPosition(float x, float y) -> bool
Returns whether the enemy can move to the specified relative offset.
auto StopsAtStopEnemy() const -> bool virtual
Returns true if the enemy turns around at EventType::AreaStopEnemy, as measured in JJ2+.
auto GetTurnLookAhead() const -> float virtual
Returns the distance in front of the enemy's middle where the floor and EventType::AreaStopEnemy are checked.
auto FindNearestPlayer(float maxDistanceSqr, float* distanceSqr = nullptr) const -> Player*
Returns the nearest living player within the squared distance or nullptr, optionally with its squared distance.
auto GetDifficultyIndex() const -> std::int32_t
Returns the difficulty as a number, 0 for Easy, 1 for Normal and 2 for Hard.
auto GetElapsedTicks() const -> std::int32_t
Returns the original's ticks elapsed in the level, the same for every actor.
auto ClampAboveWater(Vector2f pos) const -> Vector2f
Returns pos kept above the water surface, for an enemy that can't fly into the water.
void TryGenerateRandomDrop()
Randomly spawns a drop (collectible) at the enemy's position.
void StartBlinking()
Starts the white-mask blinking effect.
void HandleBlinking(float timeMult)
Advances the blinking effect.

Protected static variables

static float TicksPerFrame constexpr
Number of original 70 Hz game ticks in one 60 Hz frame, converts measured per-tick values.
static float DefaultTurnLookAhead constexpr
Default distance in front of the enemy's middle where it checks for a reason to turn.

Function documentation

void Jazz2::Actors::Enemies::EnemyBase::OnSerializeState(Stream& dest) override protected

Serializes the live state of the object to a level state snapshot.

State set from the event parameters needn't be stored, the object is spawned again with them. Derived classes call the base first and read the data back in the same order.

void Jazz2::Actors::Enemies::EnemyBase::OnDeserializeState(Stream& src) override protected

Restores the live state of the object from a level state snapshot.

Called after OnActivatedAsync(), before the object is added to the level. Running transitions aren't restored, so the restored state must not wait for a transition callback.