Skip to content

Commit

Permalink
Reworked Bubba, changed layer of some objects, fixed OnHit... callbac…
Browse files Browse the repository at this point in the history
…ks, tweaked `TexturedBackgroundFs`
  • Loading branch information
deathkiller committed Nov 19, 2024
1 parent 2514611 commit df2ba12
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 39 deletions.
5 changes: 4 additions & 1 deletion Sources/Jazz2/Actors/ActorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ namespace Jazz2::Actors
}

// Then, try the same vertically
bool hitCalled = false;
maxDiff = std::abs(effectiveSpeedY);
float yDiff = maxDiff;
for (; yDiff > std::numeric_limits<float>::epsilon(); yDiff -= CollisionCheckStep) {
Expand All @@ -314,10 +315,12 @@ namespace Jazz2::Actors
_internalForceY = 0.0f;
}
OnHitCeiling(timeMult);
hitCalled = true;
}
} else if (effectiveSpeedY > 0.0f && yDiff < effectiveSpeedY && currentGravity <= 0.0f) {
// If there is no gravity and actor is touching floor, the callback wouldn't be called otherwise
OnHitFloor(timeMult);
hitCalled = true;
}

// If the actor didn't move all the way horizontally, it hit a wall (or was already touching it)
Expand All @@ -328,7 +331,7 @@ namespace Jazz2::Actors
}

// Don't call OnHitWall() if OnHitFloor() or OnHitCeiling() was called this step
if (yDiff >= std::abs(effectiveSpeedY)) {
if (!hitCalled) {
OnHitWall(timeMult);
}
}
Expand Down
93 changes: 67 additions & 26 deletions Sources/Jazz2/Actors/Enemies/Bosses/Bubba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Jazz2::Actors::Bosses
{
Bubba::Bubba()
: _state(StateWaiting), _stateTime(0.0f), _endText(0)
: _state(State::Waiting), _stateTime(0.0f), _tornadoCooldown(120.0f), _endText(0)
{
}

Expand Down Expand Up @@ -43,6 +43,10 @@ namespace Jazz2::Actors::Bosses
{
BossBase::OnUpdate(timeMult);

if (_tornadoCooldown > 0.0f) {
_tornadoCooldown -= timeMult;
}

// Process level bounds
Recti levelBounds = _levelHandler->LevelBounds();
if (_pos.X < levelBounds.X) {
Expand All @@ -56,24 +60,24 @@ namespace Jazz2::Actors::Bosses
}

switch (_state) {
case StateJumping: {
if (_speed.Y > 0.0f) {
_state = StateFalling;
case State::Jumping: {
if (_speed.Y >= 0.0f) {
_state = State::Falling;
SetAnimation(AnimState::Fall);
}
break;
}

case StateFalling: {
case State::Falling: {
if (GetState(ActorState::CanJump)) {
_speed.Y = 0.0f;
_speed.X = 0.0f;

_state = StateTransition;
_state = State::Transition;
SetTransition(AnimState::TransitionFallToIdle, false, [this]() {
float rand = Random().NextFloat();
bool spewFileball = (rand < 0.35f);
bool tornado = (rand < 0.65f);
bool tornado = (rand < 0.65f && _tornadoCooldown <= 0.0f);
if (spewFileball) {
PlaySfx("Sneeze"_s);

Expand Down Expand Up @@ -104,13 +108,31 @@ namespace Jazz2::Actors::Bosses
break;
}

case StateTornado: {
case State::Tornado: {
if (_stateTime <= 0.0f) {
_state = StateTransition;
float cooldownMin, cooldownMax;
switch (_levelHandler->Difficulty()) {
case GameDifficulty::Easy:
cooldownMin = 600.0f;
cooldownMax = 1200.0f;
break;
default:
case GameDifficulty::Normal:
cooldownMin = 300.0f;
cooldownMax = 600.0f;
break;
case GameDifficulty::Hard:
cooldownMin = 60.0f;
cooldownMax = 480.0f;
break;
}

_tornadoCooldown = Random().NextFloat(cooldownMin, cooldownMax);
_state = State::Transition;
SetTransition((AnimState)1073741832, false, [this]() {
SetState(ActorState::CollideWithTilesetReduced | ActorState::ApplyGravitation, true);

_state = StateFalling;
_state = State::Falling;

if (_tornadoNoise != nullptr) {
_tornadoNoise->stop();
Expand All @@ -123,7 +145,7 @@ namespace Jazz2::Actors::Bosses
break;
}

case StateDying: {
case State::Dying: {
float time = (_renderer.AnimTime / _renderer.AnimDuration);
_renderer.setColor(Colorf(1.0f, 1.0f, 1.0f, 1.0f - (time * time * time * time)));
break;
Expand Down Expand Up @@ -160,37 +182,56 @@ namespace Jazz2::Actors::Bosses

SetState(ActorState::CollideWithTileset | ActorState::CollideWithTilesetReduced | ActorState::CollideWithOtherActors | ActorState::ApplyGravitation, false);

_state = StateDying;
_state = State::Dying;
SetTransition(AnimState::TransitionDeath, false, [this, collider]() {
BossBase::OnPerish(collider);
});

return false;
}

void Bubba::OnHitWall(float timeMult)
{
if (_state == State::Tornado && _stateTime > 1.0f) {
_stateTime = 1.0f;
}
}

void Bubba::FollowNearestPlayer()
{
bool found = false;
Vector2f targetPos = Vector2f(FLT_MAX, FLT_MAX);
bool isFacingLeft = false;

auto players = _levelHandler->GetPlayers();
for (auto* player : players) {
Vector2f newPos = player->GetPos();
if ((_pos - newPos).Length() < (_pos - targetPos).Length()) {
targetPos = newPos;
found = true;
float randomValue = Random().NextFloat();

if (randomValue < 0.1f) {
found = true;
isFacingLeft = true;
} else if (randomValue > 0.9f) {
found = true;
isFacingLeft = false;
} else {
Vector2f targetPos = Vector2f(FLT_MAX, FLT_MAX);
auto players = _levelHandler->GetPlayers();
for (auto* player : players) {
Vector2f newPos = player->GetPos();
if ((_pos - newPos).Length() < (_pos - targetPos).Length()) {
targetPos = newPos;
found = true;
}
}
isFacingLeft = (targetPos.X < _pos.X);
}

if (found) {
_state = StateJumping;
_state = State::Jumping;
_stateTime = 26;

SetFacingLeft(targetPos.X < _pos.X);

_speed.X = (IsFacingLeft() ? -1.3f : 1.3f);
SetFacingLeft(isFacingLeft);

_internalForceY = -1.27f;
_speed.X = (isFacingLeft ? -1.3f : 1.3f);
_speed.Y = -5.5f;
_internalForceY = -0.8f;

PlaySfx("Jump"_s);

Expand All @@ -214,7 +255,7 @@ namespace Jazz2::Actors::Bosses
}

if (found) {
_state = StateTornado;
_state = State::Tornado;
_stateTime = 60.0f;

SetState(ActorState::CollideWithTilesetReduced | ActorState::ApplyGravitation, false);
Expand Down Expand Up @@ -288,7 +329,7 @@ namespace Jazz2::Actors::Bosses

bool Bubba::Fireball::OnPerish(ActorBase* collider)
{
Explosion::Create(_levelHandler, Vector3i((int)(_pos.X + _speed.X), (int)(_pos.Y + _speed.Y), _renderer.layer() + 2), Explosion::Type::RF);
Explosion::Create(_levelHandler, Vector3i((std::int32_t)(_pos.X + _speed.X), (std::int32_t)(_pos.Y + _speed.Y), _renderer.layer() + 2), Explosion::Type::RF);

return EnemyBase::OnPerish(collider);
}
Expand Down
20 changes: 12 additions & 8 deletions Sources/Jazz2/Actors/Enemies/Bosses/Bubba.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ namespace Jazz2::Actors::Bosses
void OnUpdate(float timeMult) override;
void OnUpdateHitbox() override;
bool OnPerish(ActorBase* collider) override;
void OnHitWall(float timeMult) override;

private:
static constexpr int StateTransition = -1;
static constexpr int StateWaiting = 0;
static constexpr int StateJumping = 1;
static constexpr int StateFalling = 2;
static constexpr int StateTornado = 3;
static constexpr int StateDying = 4;
enum class State {
Transition = -1,
Waiting = 0,
Jumping = 1,
Falling = 2,
Tornado = 3,
Dying = 4
};

class Fireball : public EnemyBase
{
Expand All @@ -44,9 +47,10 @@ namespace Jazz2::Actors::Bosses
float _timeLeft;
};

int _state;
State _state;
float _stateTime;
uint8_t _endText;
float _tornadoCooldown;
std::uint8_t _endText;
std::shared_ptr<AudioBufferPlayer> _tornadoNoise;

void FollowNearestPlayer();
Expand Down
1 change: 1 addition & 0 deletions Sources/Jazz2/Actors/Environment/Checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace Jazz2::Actors::Environment
break;
}

_renderer.setLayer(_renderer.layer() - 40);
SetAnimation((AnimState)(_activated ? 1 : 0));

if (GetState(ActorState::ApplyGravitation)) {
Expand Down
1 change: 1 addition & 0 deletions Sources/Jazz2/Actors/Environment/Spring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace Jazz2::Actors::Environment

// Red starts at 1 in "Object/Spring"
SetAnimation((AnimState)(((_type + 1) << 10) | (orientationBit << 12)));
_renderer.setLayer(_renderer.layer() - 8);

if (_orientation == Orientation::Right || _orientation == Orientation::Left) {
// Horizontal springs all seem to have the same strength.
Expand Down
8 changes: 4 additions & 4 deletions Sources/Jazz2/ContentResolver.Shaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Jazz2::Shaders
{
constexpr std::uint64_t Version = 4;
constexpr std::uint64_t Version = 5;

constexpr char LightingVs[] = "#line " DEATH_LINE_STRING "\n" R"(
uniform mat4 uProjectionMatrix;
Expand Down Expand Up @@ -531,18 +531,18 @@ float addStarField(vec2 samplePosition, float threshold) {
void main() {
// Distance to center of screen from top or bottom (1: center of screen, 0: edge of screen)
float distance = 1.3 - abs(2.0 * vTexCoords.y - 1.0);
float horizonDepth = pow(distance, 2.0);
float horizonDepth = pow(distance, 1.4);
float yShift = (vTexCoords.y > 0.5 ? 1.0 : 0.0);
float correction = ((uViewSize.x * 9.0) / (uViewSize.y * 16.0));
vec2 texturePos = vec2(
(uShift.x / 256.0) + (vTexCoords.x - 0.5 ) * (0.5 + (1.5 * horizonDepth)) * correction,
(uShift.y / 256.0) + (vTexCoords.y - yShift) * 2.0 * distance
(uShift.y / 256.0) + (vTexCoords.y - yShift) * 1.4 * distance
);
vec4 texColor = texture(uTexture, texturePos);
float horizonOpacity = clamp(pow(distance, 1.8) - 0.4, 0.0, 1.0);
float horizonOpacity = clamp(pow(distance, 1.5) - 0.3, 0.0, 1.0);
vec4 horizonColorWithStars = vec4(uHorizonColor.xyz, 1.0);
if (uHorizonColor.w > 0.0) {
Expand Down

0 comments on commit df2ba12

Please sign in to comment.