1711 lines
77 KiB
C++
1711 lines
77 KiB
C++
#include "boss_final.h"
|
|
#include "beam_renderer.h"
|
|
#include "boss_ai.h"
|
|
#include "camera.h"
|
|
#include "capsule.h"
|
|
#include "deathmatch_manager.h"
|
|
#include "entity_combat.h"
|
|
#include "entity_config.h"
|
|
#include "entity_effect.h"
|
|
#include "entity_laser.h"
|
|
#include "entity_pickup.h"
|
|
#include "entity_player.h"
|
|
#include "entity_projectile.h"
|
|
#include "entity_tear.h"
|
|
#include "fx_layers.h"
|
|
#include "manager.h"
|
|
#include "music_manager.h"
|
|
#include "npc_alt.h"
|
|
#include "player_manager.h"
|
|
#include "room_grid.h"
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
// The Beast's states: idle, crossing the screen, diving into the lava (from the background, or to switch sides),
|
|
// surfacing, its suction and blast, its double shot, switching sides, calling souls, and the background phase of
|
|
// the ultra horsemen.
|
|
constexpr int BEAST_IDLE = NPC_STATE_IDLE;
|
|
constexpr int BEAST_MOVE = NPC_STATE_MOVE;
|
|
constexpr int BEAST_DIVE_TRANSITION = NPC_STATE_SUICIDE;
|
|
constexpr int BEAST_DIVE = NPC_STATE_JUMP;
|
|
constexpr int BEAST_SURFACE = NPC_STATE_STOMP;
|
|
constexpr int BEAST_SUCK = NPC_STATE_ATTACK;
|
|
constexpr int BEAST_BLAST = NPC_STATE_ATTACK2;
|
|
constexpr int BEAST_DOUBLE_SHOT = NPC_STATE_ATTACK3;
|
|
constexpr int BEAST_SWITCH = NPC_STATE_ATTACK4;
|
|
constexpr int BEAST_SURFACE_ALT = NPC_STATE_ATTACK5;
|
|
constexpr int BEAST_SOUL_CALL = NPC_STATE_SUMMON;
|
|
constexpr int BEAST_BACKGROUND = NPC_STATE_SPECIAL;
|
|
constexpr int BEAST_DYING = NPC_STATE_DEATH;
|
|
|
|
// Its horsemen, ten variants apart.
|
|
constexpr int BEAST_HORSEMEN = 4;
|
|
constexpr int BEAST_HORSEMAN_STEP = 10;
|
|
constexpr int BEAST_HORSEMAN_ARRIVING = 99;
|
|
constexpr int BEAST_LEAVING = NPC_STATE_MOVE;
|
|
|
|
// Its look and hurt: the ray layer drawn untinted, the stage of hurt it shows from its health (two thirds of its
|
|
// bar, then four more in the last third), its hurt's gibs from 120 above it.
|
|
constexpr int BEAST_RAY_LAYER = 9;
|
|
constexpr float BEAST_THIRDS = 2.999f;
|
|
constexpr float BEAST_LAST_THIRD = 0.3333f;
|
|
constexpr float BEAST_LAST_STAGES = 5.999f;
|
|
constexpr float BEAST_LAST_STAGES_SPAN = 3.999f;
|
|
constexpr int BEAST_STAGE_DIVE = 2;
|
|
static const Vector BEAST_GIB_OFFSET = vector_make(0, -120);
|
|
constexpr int BEAST_GIBS = 10;
|
|
constexpr float BEAST_GIB_SPREAD = 40;
|
|
constexpr int BEAST_HURT_SHAKE = 15;
|
|
constexpr float BEAST_HURT_BLAST_DECAY = 0.8f;
|
|
constexpr std::array<std::string_view, 3> BEAST_HURT_ANIMATIONS = {"Damage1", "Damage2", "Damage3"};
|
|
constexpr std::array<std::string_view, 3> BEAST_MOVE_HURT_ANIMATIONS = {"MoveLoopDamage1", "MoveLoopDamage2",
|
|
"MoveLoopDamage3"};
|
|
constexpr int BEAST_MUSIC_FIGHT_LAYER = 3;
|
|
constexpr int BOSS_OVERLAY_BEAST_DEAD = 4;
|
|
|
|
// Its moves toward its target: 6% of the way a frame, at most 8 (12 doubled after the dive, 15 switching sides), and
|
|
// half on an interpolation.
|
|
constexpr float BEAST_FOLLOW = 0.06f;
|
|
constexpr float BEAST_FOLLOW_TOP = 8;
|
|
constexpr float BEAST_FOLLOW_TOP_FAST = 12;
|
|
constexpr float BEAST_FOLLOW_TOP_SWITCH = 15;
|
|
constexpr int BEAST_STALACTITE_SHAKE = 10;
|
|
constexpr float BEAST_STALACTITE_LIFT = -8;
|
|
constexpr float BEAST_STALACTITE_BLAST_DECAY = 0.9f;
|
|
constexpr float BEAST_DEATH_BLAST_DECAY = 0.95f;
|
|
|
|
// Idle: it blinks every 30 to 90 frames, and acts after 60.
|
|
constexpr int BEAST_IDLE_FRAMES = 61;
|
|
constexpr int BEAST_BLINK_LEAST = 30;
|
|
constexpr uint32_t BEAST_BLINK_RANGE = 60;
|
|
constexpr int BEAST_MOVE_COOLDOWN = 30;
|
|
constexpr uint32_t BEAST_MOVE_COOLDOWN_RANGE = 20;
|
|
|
|
// Crossing the screen: its blast force grows 0.2 a frame to 7 (7.5 after the dive), and every so far a stalactite
|
|
// (or a pair) comes in from the side it moves toward.
|
|
constexpr float BEAST_BLAST_STEP = 0.2f;
|
|
constexpr float BEAST_BLAST_TOP = 7;
|
|
constexpr float BEAST_BLAST_TOP_FAST = 7.5f;
|
|
constexpr float BEAST_BLAST_FADE = 0.05f;
|
|
constexpr float BEAST_OFFSCREEN = 100;
|
|
constexpr float BEAST_STALACTITE_DEPTH = 55;
|
|
constexpr float BEAST_STALACTITE_JITTER = 60;
|
|
constexpr float BEAST_STALACTITE_EDGE = 20;
|
|
constexpr float BEAST_STALACTITE_GAP = 200;
|
|
constexpr float BEAST_STALACTITE_GAP_HURT = 150;
|
|
constexpr int BEAST_GRUMBLE_EVERY = 60;
|
|
constexpr int BEAST_MOVE_FRAMES = 239;
|
|
constexpr int STALACTITE_TOP = 0;
|
|
constexpr int STALACTITE_BOTTOM = 1;
|
|
constexpr int STALACTITE_CRACKED = 2;
|
|
constexpr int STALACTITE_CRACKED_BASE = 3;
|
|
constexpr int STALACTITE_TIP = 4;
|
|
|
|
// The dives: a lava spawner up from the floor at a random spot (the lowest path of 20 tries while surfacing), and the
|
|
// Beast 120 from the side it surfaces at.
|
|
constexpr float BEAST_SIDE = 120;
|
|
constexpr float BEAST_LAVA_MARGIN = 20;
|
|
constexpr int LAVA_SPAWNER_RISING = 2;
|
|
constexpr int BEAST_LAVA_FRAMES = 60;
|
|
constexpr int BEAST_SURFACE_LAVA_FRAMES = 30;
|
|
constexpr int BEAST_LAVA_PATH = 900;
|
|
constexpr int BEAST_LAVA_TRIES = 20;
|
|
constexpr float BEAST_DIVE_COUNTDOWN = 60;
|
|
constexpr float BEAST_DIVE_SHAKE = 0.125f;
|
|
constexpr float BEAST_LAVA_EVERY_FIRST = 30;
|
|
constexpr float BEAST_LAVA_EVERY_LEAST = 12;
|
|
constexpr float BEAST_LAVA_WAVES = 30;
|
|
constexpr float BEAST_SURFACE_SCREAM = -2;
|
|
constexpr float BEAST_SURFACING = -1;
|
|
constexpr int BEAST_SURFACE_FRAMES = 90;
|
|
constexpr int BEAST_SURFACE_REST = 45;
|
|
|
|
// Surfacing spits eight lava balls up and away from the side it faces, 10 and faster, from 30 above the floor.
|
|
constexpr int BEAST_LAVA_BALLS = 8;
|
|
constexpr float BEAST_LAVA_BALL_SPREAD = 50;
|
|
constexpr float BEAST_LAVA_BALL_ANGLE = -100;
|
|
constexpr float BEAST_LAVA_BALL_SPEED = 10;
|
|
constexpr float BEAST_LAVA_BALL_LEAD = 3;
|
|
constexpr float BEAST_LAVA_BALL_FLOOR = 30;
|
|
constexpr float BEAST_LAVA_BALL_SCALE = 0.8f;
|
|
constexpr float BEAST_LAVA_BALL_SCALE_RANGE = 0.2f;
|
|
constexpr int BEAST_LAVA_BALL_SUBTYPE = 1;
|
|
constexpr int BEAST_SURFACE_SHAKE = 14;
|
|
|
|
// The suction: its loop sound fades in, the attraction swirls toward its mouth 60 out, stalactites hurt within the
|
|
// room's sides, rings of fire shots at 580 with a gap, and everything loose pulled in, eaten when close.
|
|
constexpr float BEAST_SUCK_FADE = 0.05f;
|
|
constexpr float BEAST_MOUTH = 60;
|
|
constexpr float BEAST_SWIRL_FAR = 800;
|
|
static const Vector BEAST_SWIRL_OFFSET = vector_make(0, -24);
|
|
constexpr int BIG_ATTRACT_FAR = 0;
|
|
constexpr int BIG_ATTRACT_NEAR = 1;
|
|
constexpr int BIG_ATTRACT_RAY = 10;
|
|
constexpr int BIG_ATTRACT_RAY_THIN = 11;
|
|
constexpr int BEAST_SUCK_SHAKE = 4;
|
|
constexpr int BEAST_SWIRL_EVERY = 3;
|
|
constexpr int BEAST_STALACTITE_HURT_EVERY = 6;
|
|
constexpr float BEAST_STALACTITE_HURT = 14;
|
|
constexpr float BEAST_STALACTITE_HURT_NEAR = 500;
|
|
constexpr float BEAST_STALACTITE_HURT_FALLOFF = 1500;
|
|
constexpr float BEAST_STALACTITE_HURT_FAR = 0.8f;
|
|
constexpr int BEAST_STALACTITE_HIT_COUNTDOWN = 30;
|
|
constexpr int BEAST_RING_AFTER = 20;
|
|
constexpr int BEAST_RING_EVERY = 30;
|
|
constexpr uint32_t BEAST_RING_GAPS = 20;
|
|
constexpr int BEAST_RING_FIRST = -90;
|
|
constexpr int BEAST_RING_LAST = 60;
|
|
constexpr int BEAST_RING_GAP_HALF = 9;
|
|
constexpr float BEAST_RING_RADIUS = 580;
|
|
constexpr float BEAST_RING_FALL_ACCEL = -0.1f;
|
|
constexpr float BEAST_RING_ACCEL = 0.95f;
|
|
constexpr int BEAST_RING_SLOW_DELAY = 30;
|
|
constexpr int BEAST_RING_FAST_DELAY = 60;
|
|
constexpr float BEAST_PULL_REACH_SQUARED = 1.96e+06f;
|
|
constexpr float BEAST_PULL_PLAYER = 160;
|
|
constexpr float BEAST_PULL_HEAVY = 400;
|
|
constexpr float BEAST_PULL_SHOT = 300;
|
|
constexpr float BEAST_PULL_NEAR = 8;
|
|
constexpr float BEAST_PULL_NEAR_SCALE = 0.015625f;
|
|
constexpr float BEAST_PULL_RAMP = 30;
|
|
constexpr float BEAST_PULL_DAMP = 20;
|
|
constexpr float BEAST_PULL_DAMP_LEAST = 0.4f;
|
|
constexpr float BEAST_PULL_LIFT = -16;
|
|
constexpr float BEAST_PULL_ROCK_LIFT = -60;
|
|
constexpr float BEAST_PULL_ROCK_LIFT_TOP = -36;
|
|
constexpr float BEAST_EAT_REACH = 0.6f;
|
|
constexpr float BEAST_EAT_EFFECT_REACH = 0.4f;
|
|
constexpr float BEAST_EAT_AFTER = 15;
|
|
constexpr int BEAST_SUCK_FRAMES = 360;
|
|
|
|
// The blast: a beam from its mouth for 70 frames, clearing the shots, for 90.
|
|
static const Vector BEAST_BEAM_FROM = vector_make(0, 20);
|
|
static const Vector BEAST_BEAM_OFFSET = vector_make(0, -20);
|
|
constexpr int BEAST_BEAM_FRAMES = 70;
|
|
constexpr int BEAST_BLAST_SHAKE = 8;
|
|
constexpr float BEAST_BLAST_FRAMES = 90;
|
|
|
|
// The double shot: three fans of nine fire shots at 20, 18 degrees apart, then from its Sound the holy fan of ten at
|
|
// 15, 9 degrees apart, with blood.
|
|
constexpr int BEAST_FAN_EVERY = 22;
|
|
constexpr int BEAST_FAN_FRAMES = 70;
|
|
constexpr int BEAST_FAN_HALF = 4;
|
|
constexpr float BEAST_FAN_STEP = 18;
|
|
constexpr float BEAST_FAN_SPEED = 20;
|
|
constexpr float BEAST_FAN_ACCEL = 0.7f;
|
|
constexpr int BEAST_FAN_CHANGE = 12;
|
|
constexpr int BEAST_HOLY_START = 1000;
|
|
constexpr int BEAST_HOLY_END = 1024;
|
|
constexpr int BEAST_HOLY_EVERY = 4;
|
|
constexpr int BEAST_HOLY_HALF = 9;
|
|
constexpr float BEAST_HOLY_STEP = 9;
|
|
constexpr float BEAST_HOLY_SPEED = 15;
|
|
constexpr float BEAST_HOLY_SCALE = 2.5f;
|
|
constexpr ColorMod BEAST_HOLY_COLOR = {{1, 1, 1, 1}, {0, 0, 0, 0}, {1, 0.3f, 0}};
|
|
constexpr float BEAST_HOLY_BLOOD_SPEED = 8;
|
|
constexpr float BEAST_HOLY_BLOOD_SPEED_RANGE = 4;
|
|
|
|
// Switching sides: it plunges past the room's side, its hitbox lowered, then returns 120 in.
|
|
constexpr float BEAST_SWITCH_SINK = 0.8f;
|
|
constexpr float BEAST_SWITCH_NEAR = 80;
|
|
|
|
// The soul call: souls rise from the floor every 8 frames and red rays burst from it every other frame.
|
|
constexpr int BEAST_SOUL_EVERY = 8;
|
|
constexpr float BEAST_SOUL_MARGIN = 50;
|
|
constexpr float BEAST_SOUL_FLOOR = 20;
|
|
static const Vector BEAST_RAY_OFFSET = vector_make(0, -14);
|
|
constexpr ColorMod BEAST_RAY_COLOR = {{1, 0.2f, 0.2f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
constexpr float BEAST_RAY_FRAMES = 160.0f / 9.0f;
|
|
constexpr float BEAST_RAY_INNER = 10;
|
|
constexpr float BEAST_RAY_OUTER = 150;
|
|
constexpr int BEAST_THIN_RAYS = 3;
|
|
constexpr float BEAST_THIN_RAY_SPREAD = 60;
|
|
constexpr float BEAST_THIN_RAY_TURN = 120;
|
|
constexpr float BEAST_THIN_RAY_REACH = 0.15f;
|
|
constexpr float BEAST_THIN_RAY_LENGTH = 500;
|
|
constexpr float BEAST_THIN_RAY_WIDTH = 0.6f;
|
|
constexpr float BEAST_THIN_RAY_WIDTH_RANGE = 0.4f;
|
|
|
|
// The background phase: the horsemen come one by one, 400 right of the fourth row's twelfth cell, each after the room
|
|
// is cleared twice, then the Beast surfaces there.
|
|
constexpr int BEAST_HORSEMAN_COLUMN = 11;
|
|
constexpr int BEAST_HORSEMAN_ROW = 4;
|
|
constexpr int BEAST_HORSEMAN_MIN_WIDTH = 12;
|
|
constexpr int BEAST_HORSEMAN_MIN_HEIGHT = 5;
|
|
constexpr float BEAST_HORSEMAN_RIGHT = 400;
|
|
constexpr int BEAST_BACKGROUND_WAIT = 30;
|
|
constexpr int BEAST_BACKGROUND_DONE = 1000;
|
|
|
|
// The background beast and horsemen behind the arena, about the room's floor 58 up.
|
|
constexpr float BEAST_BACKGROUND_RISE = 58;
|
|
static const std::array<Vector, BEAST_HORSEMEN> BEAST_HORSEMAN_SPOTS = {
|
|
vector_make(-150, -140), vector_make(-50, -200), vector_make(50, -200), vector_make(150, -140)};
|
|
|
|
// A stalactite still standing within the room's sides (100 out of them) as the Beast faces, hurt less the farther it
|
|
// is from the Beast.
|
|
static void beast_stalactites_hurt(Entity_NPC& npc, float left, float right)
|
|
{
|
|
for (Entity* stalactite : entity_query(ENTITY_BEAST, BEAST_STALACTITE))
|
|
{
|
|
if (stalactite->isDead) continue;
|
|
float x = stalactite->pos.x;
|
|
float edge = npc.sprite.isFlipX ? right + BEAST_OFFSCREEN : left - BEAST_OFFSCREEN;
|
|
bool isOutside = npc.sprite.isFlipX ? edge < x : x < edge;
|
|
if (isOutside || edge == x) continue;
|
|
float roll = random_unit();
|
|
float falloff = std::clamp((vector_distance(npc.pos, stalactite->pos) - BEAST_STALACTITE_HURT_NEAR) /
|
|
BEAST_STALACTITE_HURT_FALLOFF,
|
|
0.0f, 1.0f);
|
|
stalactite->TakeDamage((1 - falloff * BEAST_STALACTITE_HURT_FAR) * (roll * BEAST_STALACTITE_HURT + BEAST_STALACTITE_HURT),
|
|
0, EntityRef(), BEAST_STALACTITE_HIT_COUNTDOWN);
|
|
}
|
|
}
|
|
|
|
// Its stalactites and souls die with it, and its shots and lasers fade.
|
|
static void beast_summons_kill(Entity_NPC& npc)
|
|
{
|
|
for (Entity* entity : std::vector<Entity*>(g_game->room->entityList.updateEL))
|
|
{
|
|
if (entity->IsType(ENTITY_BEAST, BEAST_STALACTITE, -1) || entity->IsType(ENTITY_BEAST, BEAST_SOUL, -1))
|
|
entity->Kill(EntityRef(&npc));
|
|
else if ((entity->type == ENTITY_PROJECTILE || entity->type == ENTITY_LASER) && entity->spawnerType == ENTITY_BEAST)
|
|
entity->isDead = true;
|
|
}
|
|
}
|
|
|
|
// A lava spawner rising from the floor, raising the path there.
|
|
static void beast_lava_spawn(Entity_NPC& npc, Vector position, int frames)
|
|
{
|
|
auto* lava = static_cast<Entity_Effect*>(g_game->Spawn({.position = position,
|
|
.spawner = &npc,
|
|
.subType = LAVA_SPAWNER_RISING,
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_LAVA_SPAWNER,
|
|
.seed = Random()}));
|
|
lava->timeout = frames;
|
|
lava->lifespan = frames;
|
|
lava->Update();
|
|
room_path_raise_at(lava->pos, BEAST_LAVA_PATH);
|
|
}
|
|
|
|
// Switches the music to a layer alone.
|
|
static void beast_music_layer_set(int layer)
|
|
{
|
|
MusicManager& music = g_manager->musicManager;
|
|
music.channels[music.currentChannel].enabledLayers.reset();
|
|
music.EnableLayer(layer, LAYER_FADE);
|
|
}
|
|
|
|
// Its hurt stage from its health: 0 and 1 over the first two thirds, 2 to 5 over the last.
|
|
static int beast_stage_get(Entity_NPC& npc)
|
|
{
|
|
int stage = (int)(BEAST_THIRDS - std::clamp(npc.health / npc.maxHitPoints, 0.0f, 1.0f) * BEAST_THIRDS);
|
|
if (stage != BEAST_STAGE_DIVE) return stage;
|
|
float last = std::clamp(npc.health / (npc.maxHitPoints * BEAST_LAST_THIRD), 0.0f, 1.0f);
|
|
return (int)(BEAST_LAST_STAGES - last * BEAST_LAST_STAGES_SPAN);
|
|
}
|
|
|
|
// Its hurt gibs from above it.
|
|
static void beast_gibs_spawn(Entity_NPC& npc)
|
|
{
|
|
gibs_spawn({.position = vector_add(npc.pos, BEAST_GIB_OFFSET),
|
|
.spawner = &npc,
|
|
.spread = BEAST_GIB_SPREAD,
|
|
.amount = BEAST_GIBS,
|
|
.gibFlags = GIB_FLAG_BLOOD | GIB_FLAG_HUGE});
|
|
}
|
|
|
|
// A new hurt stage: the first time past a third it dives into the background-free second phase, and in the last third
|
|
// it shows each new wound.
|
|
static void beast_stage_update(Entity_NPC& npc, int stage)
|
|
{
|
|
if (npc.projectileDelay >= stage) return;
|
|
if (stage > 1 && npc.projectileDelay < 2)
|
|
{
|
|
npc_sound_play(SOUND_ROCKET_BLAST_DEATH, 1, 2, 1);
|
|
npc_sound_play(SOUND_BEAST_GROWL, 1, 2, 1);
|
|
beast_gibs_spawn(npc);
|
|
npc.sprite.Play("TransitionDive");
|
|
npc.state = BEAST_DIVE_TRANSITION;
|
|
beast_summons_kill(npc);
|
|
}
|
|
if (stage > 2)
|
|
{
|
|
npc.sprite.Play(BEAST_HURT_ANIMATIONS[stage - 3]);
|
|
npc_sound_play(SOUND_ROCKET_BLAST_DEATH, 1, 2, 1);
|
|
beast_gibs_spawn(npc);
|
|
game_shake_screen(BEAST_HURT_SHAKE);
|
|
g_game->room->beastArena.scrollSpeed *= BEAST_HURT_BLAST_DECAY;
|
|
}
|
|
npc.projectileDelay = stage;
|
|
}
|
|
|
|
// Its first frame: in the room of the horsemen (variant 666) it waits hidden in the background, otherwise it fights.
|
|
static void beast_init(Entity_NPC& npc)
|
|
{
|
|
npc.targetPosition = npc.pos;
|
|
npc.aiCallFlags = AI_CALL_PRE_UPDATE | AI_CALL_INTERPOLATE | AI_CALL_COLLISION | AI_CALL_POST_UPDATE;
|
|
uint32_t roll = Random();
|
|
npc.i2 = 0;
|
|
npc.projectileDelay = 0;
|
|
npc.flags = (npc.flags & ~FLAG_APPEAR) | FLAG_NO_KNOCKBACK | FLAG_NO_PHYSICS_KNOCKBACK;
|
|
npc.projectileCooldown = (int)(roll % BEAST_BLINK_RANGE) + BEAST_BLINK_LEAST;
|
|
if (g_game->room->descriptor->data->variant == BEAST_ROOM_VARIANT)
|
|
{
|
|
npc.sprite.Play("BGIdle", PLAY_FORCED);
|
|
npc.flags |= FLAG_DONT_COUNT_BOSS_HP;
|
|
npc.entityCollisionClass = ENTCOLL_NONE;
|
|
npc.isVisible = false;
|
|
npc.isInvincible = true;
|
|
npc.state = BEAST_BACKGROUND;
|
|
npc.stateFrame = BEAST_BACKGROUND_WAIT;
|
|
beast_background_spawn(npc);
|
|
}
|
|
else
|
|
{
|
|
npc.sprite.Play("Idle", PLAY_FORCED);
|
|
npc.state = BEAST_IDLE;
|
|
beast_music_layer_set(BEAST_MUSIC_FIGHT_LAYER);
|
|
}
|
|
npc.sprite.GetLayer(BEAST_RAY_LAYER)->bitflags |= ANIM_RENDER_UNTINTED;
|
|
}
|
|
|
|
// Idle: blinking, then crossing the screen, then one of its attacks, then a dive (or switching sides before its first
|
|
// wound).
|
|
static void beast_idle(Entity_NPC& npc, int stage)
|
|
{
|
|
if (npc.projectileCooldown > 0) npc.projectileCooldown = std::max(npc.projectileCooldown - npc_ticks_get(npc), 0);
|
|
if (npc.stateFrame < BEAST_IDLE_FRAMES)
|
|
{
|
|
npc.stateFrame += npc_ticks_get(npc);
|
|
if (npc.sprite.animState.animData && npc.sprite.animState.isPlaying) return;
|
|
if (npc.projectileCooldown < 1)
|
|
{
|
|
npc.sprite.Play("Blink", PLAY_FORCED);
|
|
npc.projectileCooldown = (int)(Random() % BEAST_BLINK_RANGE) + BEAST_BLINK_LEAST;
|
|
}
|
|
else npc.sprite.Play("Idle", PLAY_FORCED);
|
|
return;
|
|
}
|
|
|
|
switch (npc.i1)
|
|
{
|
|
case 0:
|
|
{
|
|
npc.sprite.Play("MoveStart");
|
|
npc.state = BEAST_MOVE;
|
|
npc.stateFrame = 0;
|
|
uint32_t roll = Random();
|
|
npc.i1++;
|
|
npc.i2 = stage;
|
|
npc.projectileCooldown = (int)(roll % BEAST_MOVE_COOLDOWN_RANGE) + BEAST_MOVE_COOLDOWN;
|
|
for (Entity* stalactite : entity_query(ENTITY_BEAST, BEAST_STALACTITE)) stalactite->Remove();
|
|
npc.v1.x = 0;
|
|
return;
|
|
}
|
|
case 1:
|
|
switch (Random() % 3)
|
|
{
|
|
case 0:
|
|
npc.sprite.Play("SuckStart");
|
|
npc.state = BEAST_SUCK;
|
|
break;
|
|
case 1:
|
|
npc.sprite.Play("DoubleShot");
|
|
npc.state = BEAST_DOUBLE_SHOT;
|
|
break;
|
|
default:
|
|
npc.sprite.Play("SoulCall");
|
|
npc.state = BEAST_SOUL_CALL;
|
|
break;
|
|
}
|
|
npc.i1++;
|
|
break;
|
|
case 2:
|
|
if (npc.i2 == 0)
|
|
{
|
|
npc.sprite.Play("MoveStart");
|
|
npc_sound_play(SOUND_BEAST_SWITCH_SIDES, 1, 2, 1);
|
|
npc.state = BEAST_SWITCH;
|
|
}
|
|
else
|
|
{
|
|
npc.sprite.Play("Dive");
|
|
npc.state = BEAST_DIVE;
|
|
}
|
|
npc.i1 = 0;
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
npc.stateFrame = 0;
|
|
}
|
|
|
|
// A stalactite (or a pair, top and bottom) brought in from the side it crosses toward.
|
|
static void beast_stalactites_spawn(Entity_NPC& npc, float x, float top, float bottom)
|
|
{
|
|
auto spawn = [&](Vector at, int subType, uint32_t seed) {
|
|
g_game->Spawn({.position = at, .spawner = &npc, .subType = subType, .type = ENTITY_BEAST, .variant = BEAST_STALACTITE, .seed = seed})
|
|
->Update();
|
|
};
|
|
if (Random() % 3 == 0 && npc.i2 != 2)
|
|
{
|
|
float jitter = random_unit() * BEAST_STALACTITE_JITTER - BEAST_STALACTITE_JITTER * HALF;
|
|
spawn(vector_make(x, top - BEAST_STALACTITE_DEPTH + jitter), STALACTITE_TOP, Random());
|
|
spawn(vector_make(x, bottom + BEAST_STALACTITE_DEPTH + jitter), STALACTITE_BOTTOM, Random());
|
|
return;
|
|
}
|
|
if ((Random() & 1) == 0)
|
|
{
|
|
uint32_t seed = Random();
|
|
spawn(vector_make(x, bottom + BEAST_STALACTITE_EDGE - random_unit() * BEAST_STALACTITE_JITTER), STALACTITE_BOTTOM, seed);
|
|
return;
|
|
}
|
|
int subType = npc.i2 == 1 && (Random() & 1) == 0 ? STALACTITE_CRACKED : STALACTITE_TOP;
|
|
uint32_t seed = Random();
|
|
spawn(vector_make(x, random_unit() * BEAST_STALACTITE_JITTER + (top - BEAST_STALACTITE_EDGE)), subType, seed);
|
|
}
|
|
|
|
// Crossing the screen: the background races past as its blast force builds, stalactites come in, and before its dive
|
|
// it stops after 240 frames.
|
|
static void beast_move(Entity_NPC& npc, int stage, Room& room)
|
|
{
|
|
if (!npc.sprite.animState.animData || !npc.sprite.animState.isPlaying)
|
|
npc.sprite.Play(stage >= 3 ? BEAST_MOVE_HURT_ANIMATIONS[stage - 3] : "MoveLoop");
|
|
if (npc.projectileCooldown > 0 && npc.sprite.animState.IsLoopingAnimation())
|
|
npc.projectileCooldown = std::max(npc.projectileCooldown - npc_ticks_get(npc), 0);
|
|
if (npc.sprite.IsEventTriggered("Shoot")) npc.entityCollisionClass = ENTCOLL_ALL;
|
|
if (npc.sprite.WasEventTriggered("Shoot") || npc.sprite.animState.IsLoopingAnimation())
|
|
{
|
|
float top = npc.i2 == 2 ? BEAST_BLAST_TOP_FAST : BEAST_BLAST_TOP;
|
|
float& force = room.beastArena.scrollSpeed;
|
|
force = npc.sprite.isFlipX ? std::max(force - BEAST_BLAST_STEP, -top) : std::min(force + BEAST_BLAST_STEP, top);
|
|
npc.v1.x -= std::abs(force);
|
|
if (npc.v1.x <= 0)
|
|
{
|
|
float x = npc.sprite.isFlipX ? room.bottomRightPos.x + BEAST_OFFSCREEN + npc.v1.x : room.topLeftPos.x - BEAST_OFFSCREEN - npc.v1.x;
|
|
beast_stalactites_spawn(npc, x, room.topLeftPos.y, room.bottomRightPos.y);
|
|
float gap = npc.i2 == 2 || npc.i2 == 1 ? BEAST_STALACTITE_GAP_HURT : BEAST_STALACTITE_GAP;
|
|
npc.v1.x += random_unit() * BEAST_STALACTITE_JITTER + gap;
|
|
}
|
|
}
|
|
if (npc.stateFrame % BEAST_GRUMBLE_EVERY == 0) npc_sound_play(SOUND_BEAST_GRUMBLE, 1, 2, 1);
|
|
if (npc.i2 != 2 && npc.stateFrame > BEAST_MOVE_FRAMES)
|
|
{
|
|
npc.state = BEAST_IDLE;
|
|
npc.sprite.Play("MoveEnd");
|
|
npc.stateFrame = 0;
|
|
return;
|
|
}
|
|
npc.stateFrame += npc_ticks_get(npc);
|
|
}
|
|
|
|
// Its dives: into the background for its second phase (surfacing at once, moving), or into the lava to rise from its
|
|
// other side.
|
|
static void beast_dive(Entity_NPC& npc, Room& room)
|
|
{
|
|
if (npc.sprite.IsEventTriggered("Shoot")) npc.entityCollisionClass = ENTCOLL_NONE;
|
|
if (!npc.sprite.IsFinished()) return;
|
|
|
|
npc.v1 = vector_make(BEAST_DIVE_COUNTDOWN, 0);
|
|
float side = npc.sprite.isFlipX ? room.bottomRightPos.x - BEAST_SIDE : room.topLeftPos.x + BEAST_SIDE;
|
|
if (npc.state != BEAST_DIVE_TRANSITION)
|
|
{
|
|
npc.state = BEAST_SURFACE;
|
|
uint32_t seed = Random();
|
|
float left = room.topLeftPos.x + BEAST_LAVA_MARGIN;
|
|
Vector at = vector_make((room.bottomRightPos.x - BEAST_LAVA_MARGIN - left) * random_unit() + left, room.bottomRightPos.y);
|
|
auto* lava = static_cast<Entity_Effect*>(g_game->Spawn({.position = at,
|
|
.spawner = &npc,
|
|
.subType = LAVA_SPAWNER_RISING,
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_LAVA_SPAWNER,
|
|
.seed = seed}));
|
|
lava->timeout = BEAST_LAVA_FRAMES;
|
|
lava->lifespan = BEAST_LAVA_FRAMES;
|
|
lava->Update();
|
|
room_path_raise_at(lava->pos, BEAST_LAVA_PATH);
|
|
npc.targetPosition.x = side;
|
|
npc.sprite.isFlipX = !npc.sprite.isFlipX;
|
|
return;
|
|
}
|
|
npc.sprite.Play("TransitionSurface");
|
|
npc.v1.y = BEAST_SURFACING;
|
|
npc.stateFrame = 0;
|
|
npc.targetPosition.x = side;
|
|
npc.pos.x = side;
|
|
npc.state = BEAST_MOVE;
|
|
npc.sprite.isFlipX = !npc.sprite.isFlipX;
|
|
npc.i1 = 0;
|
|
npc.i2 = 2;
|
|
npc.v1.x = BEAST_SIDE;
|
|
}
|
|
|
|
// Surfacing spits lava balls up from the floor (the surfacing out of the background only roars).
|
|
static void beast_lava_balls(Entity_NPC& npc, Room& room)
|
|
{
|
|
if (npc.v1.y == BEAST_SURFACE_SCREAM)
|
|
{
|
|
npc_sound_play(SOUND_BEAST_SURFACE_GROWL, 1, 2, 1);
|
|
return;
|
|
}
|
|
npc_sound_play(SOUND_BEAST_FIRE_BARF, 1, 2, 1);
|
|
npc.entityCollisionClass = ENTCOLL_ALL;
|
|
ProjectileParams params;
|
|
params.variant = PROJECTILE_LAVA;
|
|
params.isFallingKept = true;
|
|
for (int ball = 0; ball < BEAST_LAVA_BALLS; ball++)
|
|
{
|
|
float angle = (random_unit() * BEAST_LAVA_BALL_SPREAD + BEAST_LAVA_BALL_ANGLE) * DEGREES_TO_RADIANS;
|
|
Vector velocity = vector_scale(vector_make(std::cos(angle), std::sin(angle)), (float)ball + BEAST_LAVA_BALL_SPEED);
|
|
if (!npc.sprite.isFlipX) velocity.x = -velocity.x;
|
|
float floor = room.bottomRightPos.y;
|
|
params.scale = random_unit() * BEAST_LAVA_BALL_SCALE_RANGE + BEAST_LAVA_BALL_SCALE;
|
|
Vector from = vector_make(velocity.x * BEAST_LAVA_BALL_LEAD + npc.pos.x,
|
|
velocity.y * BEAST_LAVA_BALL_LEAD + (floor - BEAST_LAVA_BALL_FLOOR));
|
|
npc.fire_projectiles(from, velocity, PROJECTILES_SINGLE, params)->subtype = BEAST_LAVA_BALL_SUBTYPE;
|
|
}
|
|
}
|
|
|
|
// A lava spawner where the floor's path is lowest of 21 random spots.
|
|
static void beast_surface_lava_spawn(Entity_NPC& npc, Room& room)
|
|
{
|
|
auto pathAt = [&](Vector spot) {
|
|
int index = room.GetGridIndex(spot);
|
|
return index >= 0 && index < ROOM_GRID_CELLS ? room.gridPaths[index] : 0;
|
|
};
|
|
float left = room.topLeftPos.x + BEAST_LAVA_MARGIN;
|
|
float span = room.bottomRightPos.x - BEAST_LAVA_MARGIN - left;
|
|
float floor = room.bottomRightPos.y - BEAST_LAVA_MARGIN;
|
|
Vector best = vector_make(random_unit() * span + left, floor);
|
|
int lowest = pathAt(best);
|
|
for (int tries = 0; tries < BEAST_LAVA_TRIES && lowest != 0; tries++)
|
|
{
|
|
Vector spot = vector_make(random_unit() * span + left, floor);
|
|
int path = pathAt(spot);
|
|
if (path < lowest)
|
|
{
|
|
best = spot;
|
|
lowest = path;
|
|
}
|
|
}
|
|
beast_lava_spawn(npc, best, BEAST_SURFACE_LAVA_FRAMES);
|
|
}
|
|
|
|
// Under the lava (v1 counts down to the next wave of lava, v1.y counts the waves), then surfacing and spitting.
|
|
static void beast_surface(Entity_NPC& npc, Room& room)
|
|
{
|
|
if (npc.v1.y < 0)
|
|
{
|
|
if (npc.sprite.IsEventTriggered("Shoot"))
|
|
{
|
|
beast_lava_balls(npc, room);
|
|
game_shake_screen(BEAST_SURFACE_SHAKE);
|
|
}
|
|
if (npc.sprite.IsFinished()) npc.sprite.Play("Idle", PLAY_FORCED);
|
|
npc.stateFrame += npc_ticks_get(npc);
|
|
if (npc.stateFrame > BEAST_SURFACE_FRAMES)
|
|
{
|
|
npc.stateFrame = npc.v1.y == BEAST_SURFACE_SCREAM ? BEAST_SURFACE_REST : 0;
|
|
npc.state = BEAST_IDLE;
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (npc.v1.y == 0) game_shake_screen((int)((BEAST_DIVE_COUNTDOWN - npc.v1.x) * BEAST_DIVE_SHAKE));
|
|
for (int tick = 0; tick < npc_ticks_get(npc); tick++)
|
|
{
|
|
npc.v1.x -= 1;
|
|
if (npc.v1.x > 0) continue;
|
|
npc.v1.y += 1;
|
|
npc.v1.x = std::max(BEAST_LAVA_EVERY_FIRST - (npc.v1.y + npc.v1.y), BEAST_LAVA_EVERY_LEAST);
|
|
if (npc.v1.y == BEAST_LAVA_WAVES)
|
|
{
|
|
npc.v1.x = BEAST_DIVE_COUNTDOWN;
|
|
continue;
|
|
}
|
|
if (npc.v1.y == BEAST_LAVA_WAVES + 1)
|
|
{
|
|
npc.sprite.Play("Surface");
|
|
npc.v1.y = BEAST_SURFACING;
|
|
npc.stateFrame = 0;
|
|
return;
|
|
}
|
|
beast_surface_lava_spawn(npc, room);
|
|
}
|
|
}
|
|
|
|
// A ring of fire shots about its mouth 580 out, with a gap at a random angle; those near the gap speed and fade
|
|
// sooner.
|
|
static void beast_fire_ring(Entity_NPC& npc, Vector mouth)
|
|
{
|
|
int gap = (int)(Random() % BEAST_RING_GAPS) * 2 - (int)BEAST_RING_GAPS;
|
|
for (int angle = BEAST_RING_FIRST; angle < BEAST_RING_LAST; angle += 2)
|
|
{
|
|
int fromGap = std::abs(angle - gap);
|
|
if (fromGap <= BEAST_RING_GAP_HALF) continue;
|
|
Vector at = vector_scale(vector_from_angle((float)angle), BEAST_RING_RADIUS);
|
|
if (!npc.sprite.isFlipX) at.x = -at.x;
|
|
auto* shot = static_cast<Entity_Projectile*>(g_game->Spawn({.position = vector_add(mouth, at),
|
|
.spawner = &npc,
|
|
.type = ENTITY_PROJECTILE,
|
|
.variant = PROJECTILE_FIRE,
|
|
.seed = Random()}));
|
|
shot->fallingSpeed = 0;
|
|
shot->fallingAccel = BEAST_RING_FALL_ACCEL;
|
|
shot->acceleration = BEAST_RING_ACCEL;
|
|
int band = ((fromGap - BEAST_RING_GAP_HALF - 1) / 2) % 4;
|
|
shot->projectileFlags = PROJECTILE_ACCELERATE;
|
|
if (band != 0)
|
|
{
|
|
shot->changeTimeout = band == 2 ? BEAST_RING_FAST_DELAY : BEAST_RING_SLOW_DELAY;
|
|
shot->changeFlags = PROJECTILE_ACCELERATE | PROJECTILE_FADEOUT;
|
|
shot->projectileFlags |= PROJECTILE_CHANGE_FLAGS_AFTER_TIMEOUT;
|
|
}
|
|
shot->Update();
|
|
}
|
|
}
|
|
|
|
// What the suction can pull: shots, tears, bombs and players, some effects, its rocks, and pickups that are not
|
|
// for sale nor closed chests.
|
|
static bool beast_is_suckable(Entity& entity)
|
|
{
|
|
switch (entity.type)
|
|
{
|
|
case ENTITY_PROJECTILE:
|
|
case ENTITY_TEAR:
|
|
case ENTITY_BOMB:
|
|
case ENTITY_PLAYER:
|
|
return true;
|
|
case ENTITY_EFFECT:
|
|
return entity.variant == EFFECT_EMBER_PARTICLE && entity.sortingLayer == SORTING_NORMAL;
|
|
case ENTITY_BEAST:
|
|
return entity.variant == BEAST_ROCK;
|
|
case ENTITY_PICKUP:
|
|
return static_cast<Entity_Pickup&>(entity).price == 0 &&
|
|
(!Entity_Pickup::IsChest(entity.variant) || entity.subtype != 0);
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// The suction's pull on one entity: shots and tears slowed and lifted, swallowed when at its mouth, all drawn in.
|
|
static void beast_pull(Entity_NPC& npc, Entity& entity, Vector mouth)
|
|
{
|
|
if (&entity == &npc || (entity.pos.x == mouth.x && entity.pos.y == mouth.y) || entity.friction == 0) return;
|
|
Vector toMouth = vector_sub(mouth, entity.pos);
|
|
float distanceSquared = vector_length_squared(toMouth);
|
|
if (distanceSquared >= BEAST_PULL_REACH_SQUARED) return;
|
|
float distance = std::sqrt(distanceSquared);
|
|
if (distance > 0) toMouth = vector_scale(toMouth, 1 / distance);
|
|
|
|
float strength = BEAST_PULL_PLAYER;
|
|
bool isEnemy = entity.type >= ENTITY_FIRST_ENEMY && entity.type <= ENTITY_LAST_ENEMY;
|
|
if ((entity.type == ENTITY_PLAYER && g_game->deathmatchManager.is_active()) || isEnemy || entity.type == ENTITY_BOMB)
|
|
strength = BEAST_PULL_HEAVY;
|
|
else if (entity.type == ENTITY_TEAR || entity.type == ENTITY_PROJECTILE) strength = BEAST_PULL_SHOT;
|
|
float nearness = distance >= BEAST_PULL_NEAR ? 1 / distance : distance * BEAST_PULL_NEAR_SCALE;
|
|
if (entity.type == ENTITY_PROJECTILE || entity.type == ENTITY_TEAR)
|
|
nearness *= std::min(entity.updateTime / BEAST_PULL_RAMP, 1.0f);
|
|
float pull = strength * nearness / entity.friction;
|
|
float damp = std::max(1 - nearness * BEAST_PULL_DAMP, BEAST_PULL_DAMP_LEAST);
|
|
float eatReach = npc.size * npc.size * BEAST_EAT_REACH * BEAST_EAT_REACH;
|
|
|
|
if (entity.type == ENTITY_TEAR)
|
|
{
|
|
auto& tear = static_cast<Entity_Tear&>(entity);
|
|
tear.velocity = vector_scale(tear.velocity, damp);
|
|
if (tear.tearFlags[TEAR_ORBIT] && vector_length_squared(tear.velocity) < 1)
|
|
tear.SetTearFlags(tear.tearFlags & ~TearFlags().set(TEAR_ORBIT));
|
|
float lift = std::max(nearness * BEAST_PULL_LIFT, BEAST_PULL_LIFT);
|
|
tear.velocity.y += lift * tear.speedMultiplier;
|
|
if (!tear.isDead && distanceSquared < eatReach && tear.updateTime > BEAST_EAT_AFTER && !tear.tearFlags[TEAR_LUDOVICO])
|
|
tear.Remove();
|
|
}
|
|
else if (entity.type == ENTITY_PROJECTILE || entity.type == ENTITY_BEAST)
|
|
{
|
|
entity.velocity = vector_scale(entity.velocity, damp);
|
|
if (!entity.isDead && distanceSquared < eatReach && entity.updateTime > BEAST_EAT_AFTER) entity.Remove();
|
|
if (entity.type != ENTITY_PROJECTILE)
|
|
entity.velocity.y += std::max(nearness * BEAST_PULL_ROCK_LIFT, BEAST_PULL_ROCK_LIFT_TOP) * entity.speedMultiplier;
|
|
}
|
|
else if (entity.type == ENTITY_EFFECT)
|
|
{
|
|
entity.velocity = vector_scale(entity.velocity, damp);
|
|
if (distanceSquared < npc.size * npc.size * BEAST_EAT_EFFECT_REACH * BEAST_EAT_EFFECT_REACH) entity.Remove();
|
|
}
|
|
entity.velocity = vector_add(entity.velocity, vector_scale(toMouth, pull * entity.speedMultiplier));
|
|
}
|
|
|
|
// One frame of the suction while its mouth is open: swirls, hurt stalactites, rings of fire and the pull.
|
|
static void beast_suck_tick(Entity_NPC& npc, Room& room)
|
|
{
|
|
game_shake_screen(BEAST_SUCK_SHAKE);
|
|
float side = npc.sprite.isFlipX ? 1.0f : -1.0f;
|
|
Vector mouth = vector_make(npc.pos.x + side * BEAST_MOUTH, npc.pos.y);
|
|
if (npc.stateFrame % BEAST_SWIRL_EVERY == 0)
|
|
{
|
|
Entity* swirl = g_game->Spawn({.position = vector_make(npc.pos.x + side * BEAST_SWIRL_FAR, npc.pos.y),
|
|
.subType = BIG_ATTRACT_FAR,
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_BIG_ATTRACT,
|
|
.seed = Random()});
|
|
swirl->posOffset = BEAST_SWIRL_OFFSET;
|
|
swirl->targetPosition = vector_make(npc.pos.x + side * BEAST_MOUTH, npc.pos.y);
|
|
swirl->Update();
|
|
}
|
|
if (npc.stateFrame % BEAST_STALACTITE_HURT_EVERY == 0) beast_stalactites_hurt(npc, room.topLeftPos.x, room.bottomRightPos.x);
|
|
if (npc.stateFrame > BEAST_RING_AFTER && npc.stateFrame % BEAST_RING_EVERY == 0) beast_fire_ring(npc, mouth);
|
|
if ((npc.stateFrame & 1) == 0)
|
|
{
|
|
Entity* swirl = g_game->Spawn({.position = vector_make(npc.pos.x + side * BEAST_MOUTH, npc.pos.y),
|
|
.subType = BIG_ATTRACT_NEAR,
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_BIG_ATTRACT,
|
|
.seed = Random()});
|
|
swirl->posOffset = BEAST_SWIRL_OFFSET;
|
|
swirl->Update();
|
|
}
|
|
for (Entity* entity : std::vector<Entity*>(g_game->room->entityList.updateEL))
|
|
if (beast_is_suckable(*entity)) beast_pull(npc, *entity, mouth);
|
|
}
|
|
|
|
// The suction: its loop rises, and for 360 frames the open mouth pulls everything in, then the blast.
|
|
static void beast_suck(Entity_NPC& npc, Room& room)
|
|
{
|
|
SFXManager& sfx = g_manager->sfxManager;
|
|
float volume = sfx.GetAmbientSoundVolume(SOUND_BEAST_SUCTION_LOOP);
|
|
if (volume < 1 && volume > 0) sfx.SetAmbientSound(SOUND_BEAST_SUCTION_LOOP, volume + BEAST_SUCK_FADE, 1);
|
|
if (npc.sprite.IsPlaying("SuckStart") && npc.sprite.IsEventTriggered("Shoot"))
|
|
{
|
|
npc_sound_play(SOUND_BEAST_SUCTION_START, 1, 2, 1);
|
|
sfx.SetAmbientSound(SOUND_BEAST_SUCTION_LOOP, BEAST_SUCK_FADE, 1);
|
|
}
|
|
if (npc.sprite.IsFinished()) npc.sprite.Play("SuckLoop");
|
|
for (int tick = 0; tick < npc_ticks_get(npc); tick++)
|
|
{
|
|
AnimationState& anim = npc.sprite.animState;
|
|
if (anim.animData && (anim.WasEventTriggered("Shoot") || anim.animData->isLooping)) beast_suck_tick(npc, room);
|
|
if (npc.stateFrame > BEAST_SUCK_FRAMES)
|
|
{
|
|
npc.stateFrame = 0;
|
|
npc.sprite.Play("SuckEnd");
|
|
npc.state = BEAST_BLAST;
|
|
npc_sound_play(SOUND_BEAST_SUCTION_END, 1, 2, 1);
|
|
sfx.SetAmbientSound(SOUND_BEAST_SUCTION_LOOP, sfx.GetAmbientSoundVolume(SOUND_BEAST_SUCTION_LOOP) - BEAST_SUCK_FADE, 1);
|
|
return;
|
|
}
|
|
npc.stateFrame++;
|
|
}
|
|
}
|
|
|
|
// The blast after the suction: its beam, the shots it swallowed gone.
|
|
static void beast_blast(Entity_NPC& npc)
|
|
{
|
|
SFXManager& sfx = g_manager->sfxManager;
|
|
sfx.SetAmbientSound(SOUND_BEAST_SUCTION_LOOP, sfx.GetAmbientSoundVolume(SOUND_BEAST_SUCTION_LOOP) - BEAST_SUCK_FADE, 1);
|
|
if (npc.sprite.IsFinished())
|
|
{
|
|
npc.sprite.Play("BlastLoop");
|
|
npc_sound_play(SOUND_BEAST_LASER, 1, 2, 1);
|
|
Entity_Laser::ShootAngle({.position = vector_add(npc.pos, BEAST_BEAM_FROM),
|
|
.posOffset = BEAST_BEAM_OFFSET,
|
|
.source = &npc,
|
|
.angleDegrees = npc.sprite.isFlipX ? 0 : HALF_TURN_DEGREES,
|
|
.timeout = BEAST_BEAM_FRAMES,
|
|
.variant = LASER_BEAST});
|
|
for (Entity* entity : g_game->room->entityList.updateEL)
|
|
if (entity->type == ENTITY_PROJECTILE) entity->isDead = true;
|
|
}
|
|
if (npc.sprite.WasEventTriggered("Shoot") || npc.sprite.animState.IsLoopingAnimation()) game_shake_screen(BEAST_BLAST_SHAKE);
|
|
npc.stateFrame += npc_ticks_get(npc);
|
|
if ((float)npc.stateFrame > BEAST_BLAST_FRAMES)
|
|
{
|
|
npc.stateFrame = 0;
|
|
npc.state = BEAST_IDLE;
|
|
npc.sprite.Play("BlastEnd");
|
|
}
|
|
}
|
|
|
|
// A fan of fire shots that hurt enemies too, then accelerate.
|
|
static void beast_fire_fan(Entity_NPC& npc, Vector mouth)
|
|
{
|
|
ProjectileParams params;
|
|
params.variant = PROJECTILE_FIRE;
|
|
params.fallingAccelModifier = BEAST_RING_FALL_ACCEL;
|
|
params.bulletFlags = PROJECTILE_HIT_ENEMIES | PROJECTILE_CHANGE_FLAGS_AFTER_TIMEOUT | PROJECTILE_ACCELERATE_EX;
|
|
params.changeFlags = PROJECTILE_HIT_ENEMIES;
|
|
params.changeTimeout = BEAST_FAN_CHANGE;
|
|
params.acceleration = BEAST_FAN_ACCEL;
|
|
params.isFallingKept = true;
|
|
float side = npc.sprite.isFlipX ? 1.0f : -1.0f;
|
|
for (int shot = -BEAST_FAN_HALF; shot <= BEAST_FAN_HALF; shot++)
|
|
npc.FireProjectiles(mouth, vector_scale(vector_scale(vector_from_angle((float)shot * BEAST_FAN_STEP), side), BEAST_FAN_SPEED),
|
|
PROJECTILES_SINGLE, params);
|
|
}
|
|
|
|
// The holy fan: ten large glowing shots, and blood beside half of them.
|
|
static void beast_holy_fan(Entity_NPC& npc, Vector mouth)
|
|
{
|
|
ProjectileParams params;
|
|
params.fallingAccelModifier = BEAST_RING_FALL_ACCEL;
|
|
params.color = BEAST_HOLY_COLOR;
|
|
params.bulletFlags = PROJECTILE_HIT_ENEMIES;
|
|
params.scale = BEAST_HOLY_SCALE;
|
|
params.isFallingKept = true;
|
|
float side = npc.sprite.isFlipX ? 1.0f : -1.0f;
|
|
for (int shot = -BEAST_HOLY_HALF; shot < BEAST_HOLY_HALF + 1; shot += 2)
|
|
{
|
|
Vector direction = vector_scale(vector_from_angle((float)shot * BEAST_HOLY_STEP), side);
|
|
npc.FireProjectiles(mouth, vector_scale(direction, BEAST_HOLY_SPEED), PROJECTILES_SINGLE, params);
|
|
if ((Random() & 1) != 0) continue;
|
|
Vector velocity = vector_scale(direction, random_unit() * BEAST_HOLY_BLOOD_SPEED_RANGE + BEAST_HOLY_BLOOD_SPEED);
|
|
blood_explosion_spawn((int)(~Random() & 1) + BLOOD_EXPLOSION_SPLASH, mouth, {}, BEAST_HOLY_COLOR, velocity);
|
|
}
|
|
}
|
|
|
|
// The double shot: three fans of fire, then from its Sound the holy fan.
|
|
static void beast_double_shot(Entity_NPC& npc)
|
|
{
|
|
if (npc.sprite.IsEventTriggered("Shoot")) npc_sound_play(SOUND_BEAST_SPIT, 1, 2, 1);
|
|
if (npc.sprite.WasEventTriggered("Shoot"))
|
|
{
|
|
Vector mouth = vector_make(npc.pos.x + (npc.sprite.isFlipX ? BEAST_MOUTH : -BEAST_MOUTH), npc.pos.y);
|
|
for (int tick = npc_ticks_get(npc); tick > 0; tick--)
|
|
{
|
|
int frame = npc.stateFrame;
|
|
if (!npc.sprite.animState.animData || !npc.sprite.animState.WasEventTriggered("Sound"))
|
|
{
|
|
if (frame % BEAST_FAN_EVERY == 0 && frame < BEAST_FAN_FRAMES) beast_fire_fan(npc, mouth);
|
|
}
|
|
else if (frame % BEAST_HOLY_EVERY == 0 && frame >= BEAST_HOLY_START && frame < BEAST_HOLY_END)
|
|
beast_holy_fan(npc, mouth);
|
|
npc.stateFrame++;
|
|
}
|
|
}
|
|
if (npc.sprite.IsEventTriggered("Sound")) npc.stateFrame = BEAST_HOLY_START;
|
|
if (npc.sprite.IsFinished())
|
|
{
|
|
npc.stateFrame = 0;
|
|
npc.state = BEAST_IDLE;
|
|
}
|
|
}
|
|
|
|
// Switching sides: it plunges past the side it faces, lowered, then turns and rises 120 in.
|
|
static void beast_switch(Entity_NPC& npc, Room& room)
|
|
{
|
|
if (npc.stateFrame == 0)
|
|
{
|
|
if (npc.sprite.IsEventTriggered("Shoot"))
|
|
{
|
|
npc.targetPosition.x = npc.sprite.isFlipX ? room.bottomRightPos.x + BEAST_OFFSCREEN : room.topLeftPos.x - BEAST_OFFSCREEN;
|
|
npc.sizeMulti.y *= BEAST_SWITCH_SINK;
|
|
}
|
|
if ((npc.sprite.WasEventTriggered("Shoot") || npc.sprite.animState.IsLoopingAnimation()) &&
|
|
std::abs(npc.targetPosition.x - npc.pos.x) < BEAST_SWITCH_NEAR)
|
|
{
|
|
npc.stateFrame = 1;
|
|
npc.sprite.Play("MoveEndTurn");
|
|
}
|
|
if (npc.sprite.IsFinished()) npc.sprite.Play("MoveLoopFast");
|
|
return;
|
|
}
|
|
if (npc.sprite.IsEventTriggered("Shoot"))
|
|
{
|
|
npc.sizeMulti = npc.config->collisionRadiusMulti;
|
|
npc.targetPosition.x = npc.sprite.isFlipX ? room.bottomRightPos.x - BEAST_SIDE : room.topLeftPos.x + BEAST_SIDE;
|
|
}
|
|
if (!npc.sprite.IsFinished()) return;
|
|
npc.sprite.isFlipX = !npc.sprite.isFlipX;
|
|
npc.sprite.Play("Idle");
|
|
npc.state = BEAST_IDLE;
|
|
npc.stateFrame = 0;
|
|
}
|
|
|
|
// Red rays burst from the Beast: a wide one and three thin ones at random turns.
|
|
static void beast_rays_spawn(Entity_NPC& npc)
|
|
{
|
|
int frames = (int)std::ceil(BEAST_RAY_FRAMES);
|
|
auto* ray = static_cast<Entity_Effect*>(g_game->Spawn({.position = npc.pos,
|
|
.spawner = &npc,
|
|
.subType = BIG_ATTRACT_RAY,
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_BIG_ATTRACT,
|
|
.seed = Random()}));
|
|
ray->posOffset = BEAST_RAY_OFFSET;
|
|
ray->SetColor(BEAST_RAY_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
|
ray->minRadius = BEAST_RAY_INNER;
|
|
ray->maxRadius = BEAST_RAY_OUTER;
|
|
ray->timeout = frames * 2;
|
|
ray->lifespan = frames * 2;
|
|
ray->Update();
|
|
|
|
float turn = random_unit() * FULL_TURN_DEGREES;
|
|
for (int thin = 0; thin < BEAST_THIN_RAYS; thin++)
|
|
{
|
|
auto* line = static_cast<Entity_Effect*>(g_game->Spawn({.position = npc.pos,
|
|
.spawner = &npc,
|
|
.subType = BIG_ATTRACT_RAY_THIN,
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_BIG_ATTRACT,
|
|
.seed = Random()}));
|
|
line->posOffset = BEAST_RAY_OFFSET;
|
|
line->sprite.rotation = random_unit() * BEAST_THIN_RAY_SPREAD - BEAST_THIN_RAY_SPREAD * HALF +
|
|
(float)thin * BEAST_THIN_RAY_TURN + turn;
|
|
line->SetColor(BEAST_RAY_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
|
line->timeout = frames;
|
|
line->lifespan = frames;
|
|
float roll = random_unit();
|
|
line->minRadius = BEAST_RAY_INNER;
|
|
line->maxRadius = (roll * BEAST_THIN_RAY_REACH + BEAST_THIN_RAY_REACH) * BEAST_THIN_RAY_LENGTH;
|
|
line->sprite.GetLayer(0)->size.y = random_unit() * BEAST_THIN_RAY_WIDTH_RANGE + BEAST_THIN_RAY_WIDTH;
|
|
line->Update();
|
|
}
|
|
}
|
|
|
|
// The soul call: a roar, then souls rising from the floor and rays bursting until its Sound.
|
|
static void beast_soul_call(Entity_NPC& npc, Room& room)
|
|
{
|
|
if (npc.sprite.IsEventTriggered("Roar")) npc_sound_play(SOUND_BEAST_GHOST_ROAR, 1, 2, 1);
|
|
if (npc.sprite.IsEventTriggered("Shoot")) npc_sound_play(SOUND_BEAST_GHOST_RISE, 1, 2, 1);
|
|
if (npc.sprite.WasEventTriggered("Shoot") && !npc.sprite.WasEventTriggered("Sound"))
|
|
{
|
|
game_shake_screen(BEAST_SUCK_SHAKE);
|
|
for (int tick = npc_ticks_get(npc); tick > 0; tick--)
|
|
{
|
|
if ((npc.stateFrame & 1) == 0) beast_stalactites_hurt(npc, room.topLeftPos.x, room.bottomRightPos.x);
|
|
if (npc.stateFrame % BEAST_SOUL_EVERY == 0)
|
|
{
|
|
uint32_t seed = Random();
|
|
float left = room.topLeftPos.x + BEAST_SOUL_MARGIN;
|
|
Vector at = vector_make((room.bottomRightPos.x - BEAST_SOUL_MARGIN - left) * random_unit() + left,
|
|
room.bottomRightPos.y - BEAST_SOUL_FLOOR);
|
|
g_game->Spawn({.position = at, .spawner = &npc, .type = ENTITY_BEAST, .variant = BEAST_SOUL, .seed = seed})
|
|
->Update();
|
|
}
|
|
if ((npc.stateFrame & 1) == 0) beast_rays_spawn(npc);
|
|
npc.stateFrame++;
|
|
}
|
|
}
|
|
if (!npc.sprite.IsFinished()) return;
|
|
npc.state = BEAST_IDLE;
|
|
npc.stateFrame = 0;
|
|
}
|
|
|
|
// The background phase: each horseman in turn leaves the background (the Beast itself last) and comes as an ultra
|
|
// horseman, and once the four are beaten the Beast surfaces from the lava.
|
|
static void beast_background(Entity_NPC& npc, Room& room)
|
|
{
|
|
if (npc.stateFrame != BEAST_BACKGROUND_DONE)
|
|
{
|
|
if (npc.stateFrame >= 1)
|
|
{
|
|
if (!npc.child && room.GetAliveEnemiesCount() == 1) npc.stateFrame -= npc_ticks_get(npc);
|
|
return;
|
|
}
|
|
if (npc.i1 > 0)
|
|
{
|
|
g_game->playerManager.trigger_room_clear();
|
|
g_game->playerManager.trigger_room_clear();
|
|
}
|
|
size_t slot = npc.i1 < BEAST_HORSEMEN ? (size_t)npc.i1 + 1 : 0;
|
|
EntityPtr& leaving = npc.entityDeque[slot];
|
|
if (leaving)
|
|
{
|
|
npc.child = leaving;
|
|
leaving = nullptr;
|
|
static_cast<Entity_NPC*>(npc.child.get())->state = BEAST_LEAVING;
|
|
npc.child->sprite.Play(npc.i1 < BEAST_HORSEMEN ? "LeaveStart" : "Leave");
|
|
}
|
|
npc.stateFrame = BEAST_BACKGROUND_DONE;
|
|
return;
|
|
}
|
|
if (npc.child) return;
|
|
|
|
bool isWide = room.gridWidth >= BEAST_HORSEMAN_MIN_WIDTH && room.gridHeight >= BEAST_HORSEMAN_MIN_HEIGHT;
|
|
Vector at = vector_add(room.GetGridPosition(isWide ? room.gridWidth * BEAST_HORSEMAN_ROW + BEAST_HORSEMAN_COLUMN : -1),
|
|
vector_make(BEAST_HORSEMAN_RIGHT, 0));
|
|
room.lastAliveBossCount = 0;
|
|
Entity* horseman = nullptr;
|
|
if (npc.i1 < BEAST_HORSEMEN)
|
|
{
|
|
uint32_t seed = Random();
|
|
horseman = g_game->Spawn({.position = at,
|
|
.type = ENTITY_BEAST,
|
|
.variant = BEAST_ULTRA_FAMINE + npc.i1 * BEAST_HORSEMAN_STEP,
|
|
.seed = seed});
|
|
}
|
|
if (!horseman)
|
|
{
|
|
npc.flags &= ~FLAG_DONT_COUNT_BOSS_HP;
|
|
npc.isVisible = true;
|
|
npc.entityCollisionClass = ENTCOLL_NONE;
|
|
npc.isInvincible = false;
|
|
npc.i1 = 0;
|
|
beast_music_layer_set(BEAST_MUSIC_FIGHT_LAYER);
|
|
npc.pos = vector_sub(at, vector_make(BEAST_HORSEMAN_RIGHT, 0));
|
|
npc.state = BEAST_SURFACE;
|
|
npc.sprite.Play("Surface");
|
|
npc_sound_play(SOUND_BEAST_LAVA_RISE, 1, 2, 1);
|
|
npc.v1.y = BEAST_SURFACE_SCREAM;
|
|
npc.stateFrame = 0;
|
|
return;
|
|
}
|
|
horseman->flags &= ~FLAG_APPEAR;
|
|
horseman->Update();
|
|
static_cast<Entity_NPC*>(horseman)->state = BEAST_HORSEMAN_ARRIVING;
|
|
npc.child = horseman;
|
|
npc.i1++;
|
|
npc.stateFrame = BEAST_BACKGROUND_WAIT;
|
|
}
|
|
|
|
// Its death throes: the camera on it, its last sounds and the boss overlay.
|
|
static void beast_dying_update(Entity_NPC& npc)
|
|
{
|
|
g_game->room->camera->SetFocusPosition(npc.pos);
|
|
g_game->room->beastArena.scrollSpeed *= BEAST_DEATH_BLAST_DECAY;
|
|
AnimationState& anim = npc.sprite.animState;
|
|
if (!anim.animData) return;
|
|
if (anim.IsEventTriggered("Sound1")) npc_sound_play(SOUND_BEAST_DEATH, 1, 2, 1);
|
|
if (anim.IsEventTriggered("Sound2")) npc_sound_play(SOUND_BEAST_DEATH_2, 1, 2, 1);
|
|
if (anim.IsEventTriggered("Sound3")) npc_sound_play(SOUND_BEAST_ANGELIC_BLAST, 1, 2, 1);
|
|
if (anim.WasEventTriggered("Sound3")) game_shake_screen(BEAST_STALACTITE_SHAKE);
|
|
if (anim.IsEventTriggered("Shoot")) g_game->bossOverlay.play(BOSS_OVERLAY_BEAST_DEAD);
|
|
}
|
|
|
|
// Its glide toward its target (after the update, and half on an interpolation).
|
|
static void beast_follow(Entity_NPC& npc)
|
|
{
|
|
if (vector_is_zero(npc.targetPosition)) return;
|
|
float top = BEAST_FOLLOW_TOP;
|
|
Vector step = vector_scale(vector_sub(npc.targetPosition, npc.pos), BEAST_FOLLOW);
|
|
if (npc.i2 > 0)
|
|
{
|
|
top = BEAST_FOLLOW_TOP_FAST;
|
|
step = vector_scale(step, 2);
|
|
}
|
|
if (npc.state == BEAST_SWITCH) top = BEAST_FOLLOW_TOP_SWITCH;
|
|
float length = vector_length(step);
|
|
if (top < length && length > 0) step = vector_scale(step, top / length);
|
|
if (npc.aiCallPhase == AI_PHASE_INTERPOLATE) step = vector_scale(step, HALF);
|
|
npc.pos = vector_add(npc.pos, step);
|
|
npc.velocity = {};
|
|
}
|
|
|
|
// 00592460 The Beast (951.0): first it waits behind the arena while the four ultra horsemen come, then it crosses the
|
|
// scrolling hell blasting the arena past, brings stalactites, sucks everything in and blasts, spits fire, calls souls
|
|
// and dives through the lava, hurting through four more stages in its last third.
|
|
static void beast_update(Entity_NPC& npc)
|
|
{
|
|
Room& room = *g_game->room;
|
|
if (npc.aiCallPhase == AI_PHASE_COLLISION)
|
|
{
|
|
Entity& collider = *npc.collisionEntity;
|
|
if (!collider.IsType(ENTITY_BEAST, BEAST_STALACTITE, -1)) return;
|
|
if (collider.subtype != STALACTITE_CRACKED_BASE)
|
|
{
|
|
auto& stalactite = static_cast<Entity_NPC&>(collider);
|
|
stalactite.state = NPC_STATE_SUICIDE;
|
|
stalactite.v2 = vector_make(-room.beastArena.scrollSpeed, BEAST_STALACTITE_LIFT);
|
|
game_shake_screen(BEAST_STALACTITE_SHAKE);
|
|
g_game->room->beastArena.scrollSpeed *= BEAST_STALACTITE_BLAST_DECAY;
|
|
}
|
|
npc.collisionResult = 0;
|
|
return;
|
|
}
|
|
if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE)
|
|
{
|
|
if (npc.state == BEAST_DYING) beast_dying_update(npc);
|
|
return;
|
|
}
|
|
if (npc.aiCallPhase == AI_PHASE_POST_UPDATE || npc.aiCallPhase == AI_PHASE_INTERPOLATE) return beast_follow(npc);
|
|
|
|
int stage = beast_stage_get(npc);
|
|
beast_stage_update(npc, stage);
|
|
if (npc.isDead)
|
|
{
|
|
LayerState& ray = *npc.sprite.GetLayer(BEAST_RAY_LAYER);
|
|
layer_additive_set(ray);
|
|
ray.wrapSMode = WRAP_CLAMP;
|
|
ray.wrapTMode = WRAP_CLAMP;
|
|
npc.sprite.PlayOverlay("DeathRay");
|
|
beast_summons_kill(npc);
|
|
}
|
|
|
|
switch (npc.state)
|
|
{
|
|
case NPC_STATE_INIT:
|
|
beast_init(npc);
|
|
break;
|
|
case BEAST_IDLE:
|
|
beast_idle(npc, stage);
|
|
break;
|
|
case BEAST_MOVE:
|
|
beast_move(npc, stage, room);
|
|
break;
|
|
case BEAST_DIVE_TRANSITION:
|
|
case BEAST_DIVE:
|
|
beast_dive(npc, room);
|
|
break;
|
|
case BEAST_SURFACE:
|
|
case BEAST_SURFACE_ALT:
|
|
beast_surface(npc, room);
|
|
break;
|
|
case BEAST_SUCK:
|
|
beast_suck(npc, room);
|
|
break;
|
|
case BEAST_BLAST:
|
|
beast_blast(npc);
|
|
break;
|
|
case BEAST_DOUBLE_SHOT:
|
|
beast_double_shot(npc);
|
|
break;
|
|
case BEAST_SWITCH:
|
|
beast_switch(npc, room);
|
|
break;
|
|
case BEAST_SOUL_CALL:
|
|
beast_soul_call(npc, room);
|
|
break;
|
|
case BEAST_BACKGROUND:
|
|
beast_background(npc, room);
|
|
break;
|
|
}
|
|
|
|
if (npc.isDead || (npc.state != BEAST_SUCK && npc.state != BEAST_BLAST)) g_manager->sfxManager.Stop(SOUND_BEAST_SUCTION_LOOP);
|
|
if (npc.state != BEAST_MOVE && npc.state != BEAST_BACKGROUND)
|
|
room.beastArena.scrollSpeed = std::max(room.beastArena.scrollSpeed - BEAST_BLAST_FADE, 0.0f);
|
|
}
|
|
|
|
// 00592280 The background beast and its four horsemen behind the arena, held in its entity deque (the beast first).
|
|
void beast_background_spawn(Entity_NPC& npc)
|
|
{
|
|
Room& room = *g_game->room;
|
|
npc.ClearDequeRefs();
|
|
npc.entityDeque.resize(BEAST_HORSEMEN + 1);
|
|
Vector middle = vector_make((room.bottomRightPos.x + room.topLeftPos.x) * HALF,
|
|
room.bottomRightPos.y - BEAST_BACKGROUND_RISE);
|
|
Entity* beast = g_game->Spawn({.position = middle,
|
|
.spawner = &npc,
|
|
.type = ENTITY_BEAST,
|
|
.variant = BEAST_BACKGROUND_BEAST,
|
|
.seed = Random()});
|
|
beast->Update();
|
|
npc.entityDeque[0] = beast;
|
|
for (int horseman = 0; horseman < BEAST_HORSEMEN; horseman++)
|
|
{
|
|
uint32_t seed = Random();
|
|
Entity* rider = g_game->Spawn({.position = vector_add(beast->pos, BEAST_HORSEMAN_SPOTS[horseman]),
|
|
.spawner = &npc,
|
|
.type = ENTITY_BEAST,
|
|
.variant = BEAST_BACKGROUND_BEAST + 1 + horseman,
|
|
.seed = seed});
|
|
rider->Update();
|
|
npc.entityDeque[horseman + 1] = rider;
|
|
}
|
|
}
|
|
|
|
// The stalactites (951.1) by subtype: hanging from the top or rising from the bottom, cracked (breaking once the
|
|
// Beast blasts it into the room), its cracked base and the tip that falls. They break on the Beast, drift with the
|
|
// arena and burst into rocks.
|
|
constexpr std::array<std::string_view, 5> STALACTITE_ANIMATIONS = {"Top", "Bottom", "TopCracked", "TopCrackedBase",
|
|
"TopCrackedTip"};
|
|
constexpr std::array<float, 5> STALACTITE_HEIGHTS = {-10, -10, -10, -10, -110};
|
|
constexpr uint64_t STALACTITE_FLAGS = FLAG_NO_STATUS_EFFECTS | FLAG_NO_TARGET | FLAG_NO_BLOOD_SPLASH |
|
|
FLAG_NO_DEATH_TRIGGER | FLAG_NO_KNOCKBACK | FLAG_NO_PHYSICS_KNOCKBACK |
|
|
FLAG_HIDE_HP_BAR | FLAG_NO_REWARD | FLAG_NO_PLAYER_CONTROL;
|
|
constexpr float STALACTITE_FLOOR = 30;
|
|
constexpr float STALACTITE_FLOOR_REACH = 60;
|
|
constexpr float STALACTITE_FLOOR_FRICTION = 0.5f;
|
|
constexpr float STALACTITE_WOBBLE = -0.8f;
|
|
constexpr float STALACTITE_WOBBLE_STOP = 0.3f;
|
|
constexpr float STALACTITE_HIT_WOBBLE = 3;
|
|
constexpr float STALACTITE_CRACK_REACH = 200;
|
|
constexpr float STALACTITE_BASE_HEIGHT = 0.25f;
|
|
constexpr float STALACTITE_TIP_HEIGHT = HALF;
|
|
static const Vector STALACTITE_TIP_DROP = vector_make(0, 100);
|
|
constexpr float STALACTITE_TIP_FALL = 1.5f;
|
|
constexpr float STALACTITE_GONE = 200;
|
|
constexpr int STALACTITE_SHAKE = 4;
|
|
constexpr float STALACTITE_ROCK_AREA = 3800;
|
|
constexpr int STALACTITE_DISCARDED_DRAWS = 3;
|
|
constexpr float STALACTITE_SCATTER = 5;
|
|
constexpr float STALACTITE_THROW_SPREAD = 40;
|
|
constexpr float STALACTITE_THROW_SHARE = 0.7f;
|
|
constexpr float STALACTITE_THROW_SHARE_RANGE = 0.3f;
|
|
constexpr float STALACTITE_ROCK_SCALE = 0.8f;
|
|
constexpr float STALACTITE_ROCK_GRAVITY = 0.25f;
|
|
constexpr float STALACTITE_DUST_TURN = 10;
|
|
constexpr float STALACTITE_DUST_TURN_LEAST = 2;
|
|
constexpr int STALACTITE_DUST_FRAMES = 15;
|
|
|
|
// A stalactite cracks: its base stays (its hitbox a quarter high) and its tip comes away, falling or flung.
|
|
static Entity_NPC* stalactite_crack(Entity_NPC& npc)
|
|
{
|
|
npc.PlaySound(SOUND_ROCK_CRUMBLE, 1, 2, false, 1);
|
|
npc.subtype = STALACTITE_CRACKED_BASE;
|
|
npc.sprite.Play("TopCrackedBase");
|
|
EntityConfig_Entity& config = *npc.config;
|
|
npc.SetSize(config.collisionRadius,
|
|
vector_make(config.collisionRadiusMulti.x, config.collisionRadiusMulti.y * STALACTITE_BASE_HEIGHT), -1);
|
|
auto* tip = static_cast<Entity_NPC*>(g_game->Spawn({.position = vector_add(npc.pos, STALACTITE_TIP_DROP),
|
|
.subType = STALACTITE_TIP,
|
|
.type = ENTITY_BEAST,
|
|
.variant = BEAST_STALACTITE,
|
|
.seed = Random()}));
|
|
tip->SetSize(config.collisionRadius,
|
|
vector_make(config.collisionRadiusMulti.x, config.collisionRadiusMulti.y * STALACTITE_TIP_HEIGHT), -1);
|
|
tip->sprite.isFlipX = npc.sprite.isFlipX;
|
|
return tip;
|
|
}
|
|
|
|
// A stalactite bursts into rocks flung along the Beast's blow and dust, from every null's capsule by its size.
|
|
static void stalactite_burst(Entity_NPC& npc)
|
|
{
|
|
npc.PlaySound(SOUND_ROCK_CRUMBLE, 1, 2, false, 1);
|
|
npc.PlaySound(SOUND_STONE_IMPACT, 1, 2, false, 1);
|
|
game_shake_screen(STALACTITE_SHAKE);
|
|
if (!npc.sprite.file) return;
|
|
for (const std::string& null : npc.sprite.file->nullLayerNames)
|
|
{
|
|
Capsule capsule;
|
|
npc.GetNullCapsule(capsule, null);
|
|
if (capsule.radius <= 0) continue;
|
|
int rocks = (int)std::ceil((capsule.halfLength + capsule.radius) * capsule.radius * 4 / STALACTITE_ROCK_AREA);
|
|
for (int rock = 0; rock < rocks; rock++)
|
|
{
|
|
for (int draw = 0; draw < STALACTITE_DISCARDED_DRAWS; draw++) Random();
|
|
uint32_t seed = Random();
|
|
float scatterAngle = random_unit() * RANDOM_HALF_TURN;
|
|
scatterAngle += scatterAngle;
|
|
float scatter = random_unit();
|
|
float turn = random_unit() * STALACTITE_THROW_SPREAD - STALACTITE_THROW_SPREAD * HALF;
|
|
Vector throwDirection = vector_rotated(npc.v2, turn);
|
|
float share = random_unit() * STALACTITE_THROW_SHARE_RANGE + STALACTITE_THROW_SHARE;
|
|
Vector velocity = vector_add(vector_scale(vector_make(std::cos(scatterAngle), std::sin(scatterAngle)), scatter * STALACTITE_SCATTER),
|
|
vector_scale(throwDirection, share));
|
|
auto* piece = static_cast<Entity_NPC*>(g_game->Spawn({.position = capsule.center,
|
|
.velocity = velocity,
|
|
.spawner = &npc,
|
|
.type = ENTITY_BEAST,
|
|
.variant = BEAST_ROCK,
|
|
.seed = seed}));
|
|
piece->scale = random_unit() + STALACTITE_ROCK_SCALE;
|
|
float size = piece->scale * piece->shrinkStatus1;
|
|
piece->sprite.scale = vector_make(size, size);
|
|
piece->targetPosition = vector_make(STALACTITE_ROCK_GRAVITY, 0);
|
|
piece->Update();
|
|
|
|
uint32_t dustSeed = Random();
|
|
float dustAngle = random_unit() * RANDOM_HALF_TURN;
|
|
dustAngle += dustAngle;
|
|
float dustSpeed = random_unit() * STALACTITE_SCATTER;
|
|
auto* dust = static_cast<Entity_Effect*>(g_game->Spawn({.position = capsule.center,
|
|
.velocity = vector_scale(vector_make(std::cos(dustAngle), std::sin(dustAngle)), dustSpeed),
|
|
.spawner = &npc,
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_DUST_CLOUD,
|
|
.seed = dustSeed}));
|
|
dust->posOffset = npc.posOffset;
|
|
dust->sprite.scale = vector_make(1, 1);
|
|
dust->rotation = random_unit() * STALACTITE_DUST_TURN + STALACTITE_DUST_TURN_LEAST;
|
|
int frames = (int)(Random() % STALACTITE_DUST_FRAMES) + STALACTITE_DUST_FRAMES;
|
|
dust->timeout = frames;
|
|
dust->lifespan = frames;
|
|
dust->Update();
|
|
}
|
|
}
|
|
}
|
|
|
|
// 00596120 A stalactite (951.1): it wobbles when hit, a cracked one breaks off its tip once the blast carries it in,
|
|
// the Beast's blow (state 5) breaks it, and it is gone 200 past the side the arena scrolls toward.
|
|
static void beast_stalactite_update(Entity_NPC& npc)
|
|
{
|
|
Room& room = *g_game->room;
|
|
if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE)
|
|
{
|
|
if (room.bottomRightPos.y - STALACTITE_FLOOR < npc.pos.y + STALACTITE_FLOOR_REACH) npc.friction *= STALACTITE_FLOOR_FRICTION;
|
|
if (npc.subtype == STALACTITE_TIP || vector_is_zero(npc.targetPosition)) return;
|
|
npc.velocity = vector_sub(npc.targetPosition, npc.pos);
|
|
return;
|
|
}
|
|
|
|
size_t look = (uint32_t)npc.subtype < STALACTITE_TIP ? (size_t)npc.subtype : STALACTITE_TIP;
|
|
if (npc.state == NPC_STATE_INIT)
|
|
{
|
|
npc.state = NPC_STATE_IDLE;
|
|
npc.sprite.Play(STALACTITE_ANIMATIONS[look]);
|
|
npc.aiCallFlags = AI_CALL_PRE_UPDATE;
|
|
npc.flags = (npc.flags & ~FLAG_APPEAR) | STALACTITE_FLAGS;
|
|
npc.posOffset.y = STALACTITE_HEIGHTS[look];
|
|
npc.targetPosition = npc.pos;
|
|
}
|
|
else if (npc.state == NPC_STATE_IDLE || npc.state == NPC_STATE_SUICIDE)
|
|
{
|
|
if (npc.posOffset.x != 0)
|
|
{
|
|
npc.posOffset.x *= STALACTITE_WOBBLE;
|
|
if (std::abs(npc.posOffset.x) < STALACTITE_WOBBLE_STOP) npc.posOffset.x = 0;
|
|
}
|
|
float force = room.beastArena.scrollSpeed;
|
|
if (npc.subtype == STALACTITE_CRACKED)
|
|
{
|
|
if ((force > 0 && room.topLeftPos.x + STALACTITE_CRACK_REACH < npc.pos.x) ||
|
|
(force < 0 && npc.pos.x < room.bottomRightPos.x - STALACTITE_CRACK_REACH))
|
|
stalactite_crack(npc)->Update();
|
|
}
|
|
else if (npc.subtype == STALACTITE_TIP) npc.velocity.y += npc.speedMultiplier * STALACTITE_TIP_FALL;
|
|
|
|
if (npc.state == NPC_STATE_SUICIDE)
|
|
{
|
|
npc.state = NPC_STATE_IDLE;
|
|
if (npc.subtype == STALACTITE_TOP || npc.subtype == STALACTITE_CRACKED)
|
|
{
|
|
Entity_NPC* tip = stalactite_crack(npc);
|
|
tip->isVisible = false;
|
|
tip->v2 = npc.v2;
|
|
tip->Kill(EntityRef(&npc));
|
|
tip->Update();
|
|
}
|
|
else npc.Kill(EntityRef());
|
|
}
|
|
}
|
|
|
|
if (npc.pendingDamage > 0) npc.posOffset.x = npc.posOffset.x >= 0 ? -STALACTITE_HIT_WOBBLE : STALACTITE_HIT_WOBBLE;
|
|
float force = room.beastArena.scrollSpeed;
|
|
if ((force > 0 && npc.pos.x > room.bottomRightPos.x + STALACTITE_GONE) ||
|
|
(force < 0 && npc.pos.x < room.topLeftPos.x - STALACTITE_GONE))
|
|
return npc.Remove();
|
|
if (npc.isDead) stalactite_burst(npc);
|
|
}
|
|
|
|
// The rocks (951.2): thrown pieces of stalactite that fall, splash into the lava, and break into rubble.
|
|
constexpr uint64_t BEAST_ROCK_FLAGS = FLAG_NO_STATUS_EFFECTS | FLAG_NO_TARGET | FLAG_NO_BLOOD_SPLASH | FLAG_NO_KNOCKBACK |
|
|
FLAG_NO_PHYSICS_KNOCKBACK | FLAG_HIDE_HP_BAR | FLAG_NO_REWARD | FLAG_NO_PLAYER_CONTROL;
|
|
constexpr int BEAST_ROCK_LAST_TURN = 6;
|
|
constexpr float BEAST_ROCK_HEIGHT = -22;
|
|
constexpr float BEAST_ROCK_KEPT_TOP = -600;
|
|
constexpr float BEAST_ROCK_KEPT_SIDES = -200;
|
|
constexpr int BEAST_ROCK_SPLASH_AFTER = 2;
|
|
constexpr float BEAST_ROCK_LAVA = 30;
|
|
constexpr ColorMod BEAST_ROCK_RUBBLE_TINT = {{0.54901963f, 0.48235297f, 0.48235297f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
constexpr float BEAST_ROCK_SOUND_MARGIN = -20;
|
|
constexpr float BEAST_ROCK_RUBBLE = 4;
|
|
constexpr float BEAST_ROCK_RUBBLE_RANGE = HALF;
|
|
constexpr int BEAST_ROCK_RUBBLE_MOST = 16;
|
|
constexpr float BEAST_ROCK_RUBBLE_SPEED = 1;
|
|
constexpr int TOOTH_PARTICLE_ROCK = 1;
|
|
|
|
// The rock breaks: a poof in its color and, inside the room, rubble scattered from within it.
|
|
static void rock_break(Entity_NPC& npc)
|
|
{
|
|
ColorMod rubbleColor = BEAST_ROCK_RUBBLE_TINT;
|
|
color_multiply(rubbleColor, npc.sprite.color);
|
|
Entity* poof = g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_ROCK_POOF, .seed = Random()});
|
|
poof->posOffset = npc.posOffset;
|
|
poof->SetColor(npc.color, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
|
poof->Update();
|
|
poof->sprite.rotation = 0;
|
|
poof->sprite.scale = vector_make(npc.scale, npc.scale);
|
|
if (!g_game->room->IsPositionInRoom(npc.pos, BEAST_ROCK_SOUND_MARGIN)) return;
|
|
|
|
npc_sound_play(SOUND_ROCK_CRUMBLE, 1, 2, 1);
|
|
int pieces = std::clamp((int)((random_unit() * BEAST_ROCK_RUBBLE_RANGE + 1) * npc.scale * BEAST_ROCK_RUBBLE), 1, BEAST_ROCK_RUBBLE_MOST);
|
|
for (int piece = 0; piece < pieces; piece++)
|
|
{
|
|
Vector direction = vector_from_angle(random_unit() * FULL_TURN_DEGREES);
|
|
float speed = random_unit() * 2 + BEAST_ROCK_RUBBLE_SPEED;
|
|
float reach = random_unit();
|
|
Vector at = vector_add(vector_scale(direction, reach * npc.size), npc.pos);
|
|
Entity* rubble = g_game->Spawn({.position = at,
|
|
.velocity = vector_scale(direction, speed),
|
|
.subType = TOOTH_PARTICLE_ROCK,
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_TOOTH_PARTICLE,
|
|
.seed = Random()});
|
|
rubble->posOffset = npc.posOffset;
|
|
rubble->SetColor(rubbleColor, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
|
rubble->Update();
|
|
}
|
|
}
|
|
|
|
// 00596c60 A rock (951.2): it turns by its size, falls by its targetPosition's x, is gone off the room's sides,
|
|
// splashes into the Beast's lava, and breaks on a player or familiar.
|
|
static void beast_rock_update(Entity_NPC& npc)
|
|
{
|
|
if (npc.aiCallPhase == AI_PHASE_COLLISION)
|
|
{
|
|
int type = npc.collisionEntity->type;
|
|
if (type == ENTITY_PLAYER || type == ENTITY_FAMILIAR) npc.isDead = true;
|
|
return;
|
|
}
|
|
if (npc.state == NPC_STATE_INIT)
|
|
{
|
|
npc.state = NPC_STATE_IDLE;
|
|
npc.sprite.Play("Rotate" + std::to_string(std::min((int)(npc.scale + npc.scale + 1), BEAST_ROCK_LAST_TURN)));
|
|
npc.scale = 1;
|
|
npc.sprite.scale = vector_make(1, 1);
|
|
npc.entityCollisionClass = ENTCOLL_NONE;
|
|
npc.aiCallFlags = AI_CALL_COLLISION;
|
|
npc.flags = (npc.flags & ~FLAG_APPEAR) | BEAST_ROCK_FLAGS;
|
|
return;
|
|
}
|
|
|
|
Room& room = *g_game->room;
|
|
npc.posOffset.y = BEAST_ROCK_HEIGHT;
|
|
npc.velocity.y += npc.speedMultiplier * npc.targetPosition.x;
|
|
Vector kept = room.GetClampedPositionImpl(npc.pos, BEAST_ROCK_KEPT_TOP, BEAST_ROCK_KEPT_SIDES, BEAST_ROCK_KEPT_SIDES, BEAST_ROCK_KEPT_SIDES);
|
|
if (kept.x != npc.pos.x || kept.y != npc.pos.y) npc.Remove();
|
|
if (room.IsBeastDungeon() && g_game->frameCount - npc.spawnFrame > BEAST_ROCK_SPLASH_AFTER && npc.velocity.y > 0 &&
|
|
room.bottomRightPos.y - BEAST_ROCK_LAVA < npc.pos.y)
|
|
{
|
|
npc.Remove();
|
|
g_game->Spawn({.position = npc.pos, .subType = POOF02_LAVA_SPLASH, .type = ENTITY_EFFECT, .variant = EFFECT_POOF02, .seed = Random()})
|
|
->Update();
|
|
return;
|
|
}
|
|
if (npc.isDead) rock_break(npc);
|
|
}
|
|
|
|
// The Beast's souls (951.3): launched up at a slight random angle, they wander on a sine slowing down, then dash at the
|
|
// player and burst. Each leaves a trail drawn as a beam.
|
|
constexpr float BEAST_SOUL_HEIGHT = -15;
|
|
constexpr float BEAST_SOUL_LAUNCH_SPREAD = 20;
|
|
constexpr float BEAST_SOUL_LAUNCH_SPEED = 10;
|
|
constexpr RNG BEAST_SOUL_FRAME_SHIFTS = {0, 1, 27, 27};
|
|
constexpr int BEAST_SOUL_IDLE_FRAMES = 4;
|
|
constexpr uint64_t BEAST_SOUL_FLAGS =
|
|
FLAG_NO_STATUS_EFFECTS | FLAG_NO_TARGET | FLAG_NO_DEATH_TRIGGER | FLAG_HIDE_HP_BAR | FLAG_NO_PLAYER_CONTROL;
|
|
constexpr int BEAST_SOUL_WANDER = NPC_STATE_IDLE;
|
|
constexpr int BEAST_SOUL_BURST = NPC_STATE_SUICIDE;
|
|
constexpr int BEAST_SOUL_DASH = NPC_STATE_ATTACK;
|
|
constexpr float BEAST_SOUL_SLOWDOWN = 0.002f;
|
|
constexpr float BEAST_SOUL_WEAVE_SPEED = 0.4f;
|
|
constexpr float BEAST_SOUL_WEAVE_SPEED_RANGE = 0.1f;
|
|
constexpr float BEAST_SOUL_WEAVE = 90;
|
|
constexpr float BEAST_SOUL_DRAG_LEAST = 0.95f;
|
|
constexpr float BEAST_SOUL_DASH_AT = 0.9f;
|
|
constexpr float BEAST_SOUL_DASH_PUSH = 2;
|
|
constexpr float BEAST_SOUL_DASH_TOP = 20;
|
|
constexpr int BEAST_SOUL_STEER_FRAMES = 40;
|
|
constexpr float BEAST_SOUL_STEER_RAMP = 0.25f;
|
|
constexpr float BEAST_SOUL_STEER_TOP = 20;
|
|
constexpr int BEAST_SOUL_DASH_FRAMES = 61;
|
|
constexpr float BEAST_SOUL_TRAIL_FADE = 0.1f;
|
|
constexpr float BEAST_SOUL_TRAIL_DRAG = 0.98f;
|
|
constexpr float BEAST_SOUL_TRAIL_ALPHA = 1.4f;
|
|
constexpr float BEAST_SOUL_TRAIL_SPEED = 8;
|
|
constexpr float BEAST_SOUL_TRAIL_WAVE = 0.4f;
|
|
constexpr float BEAST_SOUL_TRAIL_WAVE_ANGLE = 30;
|
|
constexpr float BEAST_SOUL_INTERPOLATION_STEP = HALF;
|
|
constexpr float BEAST_SOUL_ANGLE_UP = 90;
|
|
|
|
// The soul's trail (vectorDeque1 kept, vectorDeque2 drawn, three vectors a point: its place, its drift and its alpha):
|
|
// each point drifts and fades, a new one is laid at the soul behind it, the faded ones drop.
|
|
static void soul_trail_update(Entity_NPC& npc, float step)
|
|
{
|
|
std::deque<Vector>& kept = npc.vectorDeque1;
|
|
std::deque<Vector>& drawn = npc.vectorDeque2;
|
|
if (drawn.size() < kept.size()) drawn.resize(kept.size());
|
|
float drag = timescale_factor(BEAST_SOUL_TRAIL_DRAG, step);
|
|
for (size_t i = 0; i < kept.size(); i += CORD_STRIDE)
|
|
{
|
|
drawn[i] = vector_add(kept[i], vector_scale(kept[i + 1], step));
|
|
drawn[i + 1] = vector_scale(kept[i + 1], drag);
|
|
drawn[i + 2].x = std::max(kept[i + 2].x - BEAST_SOUL_TRAIL_FADE, 0.0f);
|
|
}
|
|
|
|
drawn.push_front(vector_make(BEAST_SOUL_TRAIL_ALPHA, 0));
|
|
Vector back = vector_resized(npc.velocity, BEAST_SOUL_TRAIL_SPEED);
|
|
float wave = std::sin(npc.updateTime * BEAST_SOUL_TRAIL_WAVE) * BEAST_SOUL_TRAIL_WAVE_ANGLE;
|
|
drawn.push_front(vector_scale(vector_rotated(back, wave), -1));
|
|
drawn.push_front(vector_add(npc.posOffset, npc.pos));
|
|
while (!drawn.empty() && drawn.back().x <= 0)
|
|
for (size_t i = 0; i < CORD_STRIDE; i++) drawn.pop_back();
|
|
|
|
npc.sprite.rotation = vector_angle(npc.velocity) + BEAST_SOUL_ANGLE_UP;
|
|
if (npc.aiCallPhase != AI_PHASE_INTERPOLATE) kept = drawn;
|
|
}
|
|
|
|
// The soul's dash: pushed along its heading (v2) at most 20, steering toward its target for 40 frames, bursting after
|
|
// 60 (or at once without a target).
|
|
static void soul_dash(Entity_NPC& npc)
|
|
{
|
|
if (npc.target)
|
|
{
|
|
npc.velocity = vector_add(npc.velocity, vector_scale(npc.v2, BEAST_SOUL_DASH_PUSH * npc.speedMultiplier));
|
|
float speed = vector_length(npc.velocity);
|
|
if (speed > BEAST_SOUL_DASH_TOP && speed > 0) npc.velocity = vector_scale(npc.velocity, BEAST_SOUL_DASH_TOP / speed);
|
|
if (npc.stateFrame < BEAST_SOUL_STEER_FRAMES)
|
|
{
|
|
Vector steer = vector_resized(vector_sub(npc.target->pos, npc.pos),
|
|
std::min((float)npc.stateFrame * BEAST_SOUL_STEER_RAMP, BEAST_SOUL_STEER_TOP));
|
|
npc.v2 = vector_normalized(vector_add(npc.v2, vector_scale(steer, npc.speedMultiplier)));
|
|
}
|
|
npc.stateFrame += npc_ticks_get(npc);
|
|
if (npc.stateFrame < BEAST_SOUL_DASH_FRAMES) return;
|
|
}
|
|
npc.state = BEAST_SOUL_BURST;
|
|
}
|
|
|
|
// 005971e0 A soul of the Beast (951.3): launched up, it weaves while slowing, then dashes at the player and bursts
|
|
// like Dogma's babies, its trail laid after each update and interpolation.
|
|
static void beast_soul_update(Entity_NPC& npc)
|
|
{
|
|
if (npc.aiCallPhase == AI_PHASE_POST_UPDATE) return soul_trail_update(npc, npc.speedMultiplier);
|
|
if (npc.aiCallPhase == AI_PHASE_INTERPOLATE) return soul_trail_update(npc, BEAST_SOUL_INTERPOLATION_STEP * npc.speedMultiplier);
|
|
|
|
switch (npc.state)
|
|
{
|
|
case NPC_STATE_INIT:
|
|
{
|
|
npc.posOffset.y = BEAST_SOUL_HEIGHT;
|
|
float launch = random_unit() * BEAST_SOUL_LAUNCH_SPREAD - BEAST_SOUL_LAUNCH_SPREAD * HALF;
|
|
npc.v2 = vector_rotated(vector_make(0, -1), launch);
|
|
npc.velocity = vector_scale(npc.v2, BEAST_SOUL_LAUNCH_SPEED);
|
|
RNG rng = BEAST_SOUL_FRAME_SHIFTS;
|
|
rng._seed = npc.initSeed;
|
|
npc.sprite.SetFrame("Idle", (int)rng.RandomInt(BEAST_SOUL_IDLE_FRAMES));
|
|
npc.isInvincible = true;
|
|
npc.v1.x = 1;
|
|
npc.flags = (npc.flags & ~FLAG_APPEAR) | BEAST_SOUL_FLAGS;
|
|
npc.state = BEAST_SOUL_WANDER;
|
|
npc.aiCallFlags = AI_CALL_INTERPOLATE | AI_CALL_POST_UPDATE;
|
|
break;
|
|
}
|
|
case BEAST_SOUL_WANDER:
|
|
{
|
|
npc.v1.x -= npc.speedMultiplier * BEAST_SOUL_SLOWDOWN;
|
|
Vector drift = vector_resized(npc.velocity, npc.v1.x * npc.v1.x);
|
|
float weave = std::sin((random_unit() * BEAST_SOUL_WEAVE_SPEED_RANGE + BEAST_SOUL_WEAVE_SPEED) * npc.updateTime) * BEAST_SOUL_WEAVE;
|
|
float speed = vector_length(npc.velocity);
|
|
Vector turned = vector_resized(vector_add(vector_rotated(drift, weave), npc.velocity), speed);
|
|
npc.velocity = vector_scale(turned, timescale_factor(std::max(npc.v1.x, BEAST_SOUL_DRAG_LEAST), npc.speedMultiplier));
|
|
if (vector_length_squared(npc.velocity) > 1) npc.v2 = vector_normalized(npc.velocity);
|
|
if (npc.v1.x >= BEAST_SOUL_DASH_AT) break;
|
|
npc.state = BEAST_SOUL_DASH;
|
|
npc_sound_play(SOUND_BEAST_GHOST_DASH, 1, 2, 1);
|
|
npc.target = npc.GetPlayerTarget();
|
|
npc.stateFrame = 0;
|
|
break;
|
|
}
|
|
case BEAST_SOUL_BURST:
|
|
{
|
|
Entity* burst = g_game->Spawn({.position = npc.pos,
|
|
.spawner = &npc,
|
|
.subType = ENEMY_GHOST_BLAST,
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_ENEMY_GHOST,
|
|
.seed = Random()});
|
|
burst->sprite.rotation = random_unit() * FULL_TURN_DEGREES;
|
|
burst->sprite.scale = vector_make(1, 1);
|
|
burst->SetCollisionDamage(20);
|
|
burst->Update();
|
|
damage_radius({.position = npc.pos, .source = &npc, .damage = 1, .playerDamageThreshold = 50, .radius = 60});
|
|
npc_sound_play(SOUND_DEMON_HIT, 0.8f, 2, random_unit() * 0.2f + 1.2f);
|
|
npc.Remove();
|
|
break;
|
|
}
|
|
case BEAST_SOUL_DASH:
|
|
soul_dash(npc);
|
|
break;
|
|
}
|
|
}
|
|
|
|
constexpr size_t BEAST_SOUL_TRAIL_LEAST = 8;
|
|
constexpr float BEAST_SOUL_TRAIL_SMOOTH_EDGE = 0.3f;
|
|
constexpr float BEAST_SOUL_TRAIL_SMOOTH_MIDDLE = 0.4f;
|
|
constexpr float BEAST_SOUL_TRAIL_LONGEST = 128;
|
|
constexpr float BEAST_SOUL_TRAIL_THINNEST = HALF;
|
|
|
|
// 00597d00 Draws a soul's trail through the beam renderer: its points on screen, smoothed, fading by their alpha,
|
|
// narrowed when the trail is longer than 128.
|
|
static void beast_soul_render(Entity_NPC& npc, const Vector& offset)
|
|
{
|
|
std::deque<Vector>& trail = npc.vectorDeque2;
|
|
if (trail.size() <= BEAST_SOUL_TRAIL_LEAST) return;
|
|
|
|
std::vector<Vector> screen;
|
|
for (size_t i = 0; i < trail.size(); i += CORD_STRIDE)
|
|
screen.push_back(vector_add(render_position_get(trail[i], RENDER_SNAPPED), offset));
|
|
|
|
struct TrailPoint
|
|
{
|
|
Vector pos{};
|
|
float alpha = 0;
|
|
float length = 0;
|
|
};
|
|
std::vector<TrailPoint> points = {{.pos = screen[0], .alpha = trail[2].x}};
|
|
float length = 0;
|
|
for (size_t i = 1; i + 1 < screen.size(); i++)
|
|
{
|
|
Vector smoothed = vector_add(vector_add(vector_scale(screen[i - 1], BEAST_SOUL_TRAIL_SMOOTH_EDGE),
|
|
vector_scale(screen[i], BEAST_SOUL_TRAIL_SMOOTH_MIDDLE)),
|
|
vector_scale(screen[i + 1], BEAST_SOUL_TRAIL_SMOOTH_EDGE));
|
|
points.push_back({.pos = smoothed, .alpha = trail[i * CORD_STRIDE + 2].x});
|
|
length += vector_distance(points[points.size() - 2].pos, points.back().pos);
|
|
points.back().length = length;
|
|
}
|
|
float width = 1;
|
|
if (length > BEAST_SOUL_TRAIL_LONGEST) width = std::max(BEAST_SOUL_TRAIL_LONGEST / length, BEAST_SOUL_TRAIL_THINNEST);
|
|
|
|
g_beamRenderer.Begin(npc.sprite, 0, BEAM_FRAME_MAIN, BEAM_COORDINATE_PIXELS);
|
|
for (const TrailPoint& point : points)
|
|
g_beamRenderer.Add({.color = color_make({1, 1, 1, point.alpha}),
|
|
.pos = point.pos,
|
|
.coordinate = width * point.length,
|
|
.width = width});
|
|
g_beamRenderer.End();
|
|
}
|
|
|
|
// 00598260 The Beast's forms draw themselves, but for the souls' trails.
|
|
void beast_render(Entity_NPC& npc, const Vector& offset)
|
|
{
|
|
if (npc.variant == BEAST_SOUL) return beast_soul_render(npc, offset);
|
|
npc.Entity::Render(offset);
|
|
}
|
|
|
|
// The Beast's forms (951) by variant: its stalactites, rocks and souls, the four ultra horsemen and their summons, and
|
|
// the background beasts.
|
|
void boss_beast_update(Entity_NPC& npc)
|
|
{
|
|
switch (npc.variant)
|
|
{
|
|
case BEAST_STALACTITE:
|
|
return beast_stalactite_update(npc);
|
|
case BEAST_ROCK:
|
|
return beast_rock_update(npc);
|
|
case BEAST_SOUL:
|
|
return beast_soul_update(npc);
|
|
case BEAST_ULTRA_FAMINE:
|
|
return NpcAI::ENTITY_BEAST_ultra_famine(&npc);
|
|
case BEAST_ULTRA_FAMINE_FLY:
|
|
return NpcAI::ENTITY_BEAST_ultra_famine_fly(&npc);
|
|
case BEAST_ULTRA_PESTILENCE:
|
|
return NpcAI::ENTITY_BEAST_ultra_pestilence(&npc);
|
|
case BEAST_ULTRA_PESTILENCE_FLY:
|
|
return NpcAI::ENTITY_BEAST_pestilence_fly(&npc);
|
|
case BEAST_ULTRA_PESTILENCE_MAGGOT:
|
|
return NpcAI::ENTITY_BEAST_ultra_pestilence_maggot(&npc);
|
|
case BEAST_ULTRA_PESTILENCE_FLY_BALL:
|
|
return NpcAI::ENTITY_BEAST_ultra_pestilence_fly_ball(&npc);
|
|
case BEAST_ULTRA_WAR:
|
|
return NpcAI::ENTITY_BEAST_ultra_war(&npc);
|
|
case BEAST_ULTRA_WAR_BOMB:
|
|
return NpcAI::ENTITY_BEAST_ultra_war_bomb(&npc);
|
|
case BEAST_ULTRA_DEATH:
|
|
return NpcAI::ENTITY_BEAST_ultra_death(&npc);
|
|
case BEAST_ULTRA_DEATH_SCYTHE:
|
|
return NpcAI::ENTITY_BEAST_ultra_death_scythe(&npc);
|
|
case BEAST_ULTRA_DEATH_HEAD:
|
|
return NpcAI::ENTITY_BEAST_ultra_death_head(&npc);
|
|
case BEAST_BACKGROUND_BEAST:
|
|
case BEAST_BACKGROUND_FAMINE:
|
|
case BEAST_BACKGROUND_PESTILENCE:
|
|
case BEAST_BACKGROUND_WAR:
|
|
case BEAST_BACKGROUND_DEATH:
|
|
return NpcAI::ENTITY_BEAST_background(&npc);
|
|
default:
|
|
return beast_update(npc);
|
|
}
|
|
}
|