1277 lines
53 KiB
C++
1277 lines
53 KiB
C++
#include "boss_ai.h"
|
|
#include "entity_config.h"
|
|
#include "entity_list.h"
|
|
#include "entity_player.h"
|
|
#include "manager.h"
|
|
#include "music_manager.h"
|
|
#include "npc_caves.h"
|
|
#include "room_grid.h"
|
|
#include "room_render.h"
|
|
#include "sfx_manager.h"
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <cmath>
|
|
#include <cstdio>
|
|
|
|
// His phases: sitting, standing, then winged. Isaac rises one winged phase more for each light wall he calls.
|
|
enum IsaacPhase
|
|
{
|
|
ISAAC_SITTING,
|
|
ISAAC_STANDING,
|
|
ISAAC_WINGED
|
|
};
|
|
|
|
// The three bytes he keeps in i2: his phase, the slant of his light walls and the frames until his next attack.
|
|
enum IsaacByte
|
|
{
|
|
BYTE_PHASE,
|
|
BYTE_WALL_SLANT,
|
|
BYTE_COOLDOWN
|
|
};
|
|
|
|
// His ??? teleport (JUMP) and Isaac's light walls (ATTACK2) go through these steps in i1: vanishing, appearing, and
|
|
// a wall sweeping down from the left or the right, counted in frames from 1000 or 2000.
|
|
constexpr int STEP_VANISH = 0;
|
|
constexpr int STEP_APPEAR = 1;
|
|
constexpr int WALL_FROM_LEFT = 1000;
|
|
constexpr int WALL_FROM_RIGHT = 2000;
|
|
constexpr int WALL_END = 3000;
|
|
|
|
// The angelic babies he calls and the summons ??? throws out.
|
|
constexpr int BABY_ANGELIC = 1;
|
|
constexpr int SUMMON_SUBTYPE = 1;
|
|
constexpr int SUMMON_SUBTYPE_POOTER = 2;
|
|
constexpr int BEAM_SUBTYPE = 2;
|
|
|
|
// Health thresholds: he stands below 75% (??? below 70%), takes wings below half, and Isaac calls a wall at each
|
|
// tenth of his health below that, down to a tenth. ??? summons below 90% and curves his shots there.
|
|
constexpr float STAND_THRESHOLD = 0.75f;
|
|
constexpr float BLUE_STAND_THRESHOLD = 0.7f;
|
|
constexpr float WINGS_THRESHOLD = 0.5f;
|
|
constexpr int WALL_PHASE_LAST = 6;
|
|
constexpr std::array<float, 5> WALL_THRESHOLDS = {0.5f, 0.4f, 0.3f, 0.2f, 0.1f};
|
|
constexpr float BLUE_SUMMON_THRESHOLD = 0.9f;
|
|
constexpr float POOTER_THRESHOLD = 0.7f;
|
|
|
|
// Sitting he whimpers one time in 20, 45 to 144 frames later, and is held to his spot. Winged he drifts freely.
|
|
constexpr int WHIMPER_ODDS = 20;
|
|
constexpr int ISAAC_WHIMPER_DELAY_MIN = 45;
|
|
constexpr int ISAAC_WHIMPER_DELAY_RANGE = 100;
|
|
constexpr float HELD_FRICTION = 0.6f;
|
|
constexpr float WINGED_FRICTION = 0.9f;
|
|
|
|
// His aimed shots: every 20 frames (30 standing, 25 or 12 winged, half for ???), at 8 (6 standing, three quarters
|
|
// for ???), a tenth off true. Hits taken since his last shots add up to 200, and past 100 and 150 fire a second and
|
|
// third shot, each spending 10 (5 for ???) of them. One ??? shot in 10 is a big homing one.
|
|
constexpr int SHOT_INTERVAL = 20;
|
|
constexpr int SHOT_INTERVAL_STANDING = 30;
|
|
constexpr int SHOT_INTERVAL_WINGED = 25;
|
|
constexpr int SHOT_INTERVAL_WINGED_BLUE = 12;
|
|
constexpr float ISAAC_SHOT_SPEED = 8;
|
|
constexpr float SHOT_SPEED_STANDING = 6;
|
|
constexpr float BLUE_SHOT_SPEED_SCALE = 0.75f;
|
|
constexpr float SHOT_WOBBLE = 0.1f;
|
|
constexpr float SHOT_FALL = -0.1f;
|
|
constexpr float SHOT_HOMING_SCALE = 1.2f;
|
|
constexpr int SHOT_HOMING_ODDS = 10;
|
|
constexpr float HITS_CAP = 200;
|
|
constexpr float HITS_SECOND_SHOT = 100;
|
|
constexpr float HITS_THIRD_SHOT = 150;
|
|
constexpr float HITS_PER_SHOT = 10;
|
|
constexpr float BLUE_HITS_PER_SHOT = 5;
|
|
constexpr float SHOT_LEAD = 0.3f;
|
|
constexpr float BLUE_SHOT_LEAD = 0.6f;
|
|
|
|
// ??? summons every 30 frames, one roll in 8, while fewer than 9 enemies are about: 2 to 5 flies (a Moter one time in
|
|
// 4, a Pooter 3 times in 4 below 70%) thrown 15 out at 3.
|
|
constexpr int SUMMON_INTERVAL = 30;
|
|
constexpr int SUMMON_ODDS_MASK = 7;
|
|
constexpr int BLUE_SUMMON_CROWD = 9;
|
|
constexpr int SUMMON_COUNT_MIN = 2;
|
|
constexpr float BLUE_SUMMON_REACH = 15;
|
|
constexpr float SUMMON_SPEED = 3;
|
|
|
|
// Standing Isaac's light beams: one roll in 4 starts two, 5 frames apart, at a random spot or one roll in 3 where his
|
|
// target heads, 40 frames between rolls. One roll in 10 with at most one enemy left calls two angelic babies 100 out
|
|
// instead, 120 frames before the next.
|
|
constexpr int BEAMS_ODDS_MASK = 3;
|
|
constexpr int BEAMS_FRAMES = 10;
|
|
constexpr int BEAMS_SPACING = 5;
|
|
constexpr int BEAMS_COOLDOWN = 40;
|
|
constexpr int BEAM_AIM_ODDS = 3;
|
|
constexpr float BEAM_SPOT_MARGIN = 20;
|
|
constexpr float BEAM_JITTER = 20;
|
|
constexpr float BEAM_AIM_LEAD = 0.2f;
|
|
constexpr float BEAM_SIZE = 10;
|
|
constexpr int BABIES_ODDS = 10;
|
|
constexpr int BABIES_CROWD = 2;
|
|
constexpr int BABIES_COUNT = 2;
|
|
constexpr int BABIES_COOLDOWN = 120;
|
|
constexpr float BABIES_REACH = 100;
|
|
constexpr float BABIES_JITTER = 10;
|
|
|
|
// His cell is marked so walkers keep off, below the paths the room already blocks.
|
|
constexpr int ISAAC_PATH_LIMIT = 951;
|
|
|
|
// Idle he waits 60 to 119 frames first, then 15 to 104 after each attack (a third for Hush's ???).
|
|
constexpr int FIRST_COOLDOWN_MIN = 60;
|
|
constexpr int FIRST_COOLDOWN_RANGE = 60;
|
|
constexpr int COOLDOWN_MIN = 15;
|
|
constexpr int COOLDOWN_RANGE = 90;
|
|
constexpr int HUSH_COOLDOWN_DIVISOR = 3;
|
|
constexpr int ISAAC_ATTACK_FRAMES = 40;
|
|
constexpr int ATTACK_PICKS = 6;
|
|
constexpr int ATTACK_PATTERNS = 5;
|
|
constexpr float G_FUEL_SHIELD = 90;
|
|
|
|
// His shot rings: waves after 3 frames (19 winged, past the wings' rise), i1 / 5 + 3 of them, 3 to 6 frames apart.
|
|
// Isaac's ring pattern is i1 % 5: 10 shots at 7 curving left, right or straight, 8 turned a half step on even waves,
|
|
// or 8 at 12 through walls. The curving ones fire a second ring at 11 curving the other way.
|
|
constexpr int WAVE_DELAY = 3;
|
|
constexpr int WAVE_DELAY_WINGED = 19;
|
|
constexpr int WAVES_MIN = 3;
|
|
constexpr float WAVE_SPACING_MIN = 3;
|
|
constexpr float WAVE_SPACING_RANGE = 3;
|
|
constexpr float WAVE_SPACING_PICKS = 5;
|
|
constexpr float ISAAC_RING_SPEED = 7;
|
|
constexpr float RING_SPEED_FAST = 12;
|
|
constexpr float RING_SPEED_SECOND = 11;
|
|
constexpr float RING_COUNT = 10;
|
|
constexpr float RING_COUNT_SMALL = 8;
|
|
constexpr float RING_FALL_ACCEL = -0.06f;
|
|
constexpr float RING_CURVE = 0.002f;
|
|
constexpr float RING_CURVE_FAST = 0.009f;
|
|
constexpr float RING_CURVE_SECOND = 0.015f;
|
|
constexpr float RING_FALL_ACCEL_SECOND = 0.15f;
|
|
constexpr float RING_HALF_STEP = 0.3926991f;
|
|
constexpr float WAVE_VOLUME = 0.5f;
|
|
|
|
// ???'s bursts: 6 to 9 shots at 7 from 20 below him, curving below 90%, one in 5 big and homing in the first 3
|
|
// patterns.
|
|
constexpr int BURST_COUNT_MIN = 6;
|
|
constexpr int BURST_COUNT_PICKS = 4;
|
|
constexpr float BLUE_BURST_SPEED = 7;
|
|
constexpr float BURST_DROP = 20;
|
|
constexpr float BLUE_BURST_FALL_ACCEL = -0.05f;
|
|
constexpr float BURST_FALL_ACCEL_HUSH = -0.15f;
|
|
constexpr float BURST_CURVE = 0.007f;
|
|
constexpr float BURST_CURVE_HUSH = 0.0035f;
|
|
constexpr int BURST_BIG_PICKS = 3;
|
|
constexpr int BURST_BIG_ODDS = 5;
|
|
constexpr float BURST_BIG_SCALE = 1.5f;
|
|
|
|
// Standing, his attack is a ring of 1.5 shots on frame 6: 4 at 7 bursting (Isaac) or 4 at 10 homing (???), or 8 at
|
|
// 10 (Isaac) or 8 at 8 homing (???).
|
|
constexpr float STAND_RING_FRAME = 6;
|
|
constexpr float STAND_RING_SCALE = 1.5f;
|
|
static const Vector STAND_RING_BURST = vector_make(7, 4);
|
|
static const Vector STAND_RING_WIDE = vector_make(10, 8);
|
|
static const Vector BLUE_STAND_RING_FEW = vector_make(10, 4);
|
|
static const Vector BLUE_STAND_RING_WIDE = vector_make(8, 8);
|
|
|
|
// The animation frames his sounds play on.
|
|
constexpr float STAND_SOUND_FRAME = 20;
|
|
constexpr float EVOLVE_SOUND_FRAME = 17;
|
|
constexpr float VANISH_SOUND_FRAME = 19;
|
|
constexpr float CHARGE_SOUND_FRAME = 17;
|
|
|
|
// Winged he keeps 120 to 200 from his target (??? right on it), along its axis for Isaac, every 15 frames, and steps
|
|
// 1.3 (0.175 of it for ???) along the nearest of 8 directions while 32 away.
|
|
constexpr int DRIFT_INTERVAL = 15;
|
|
constexpr float DRIFT_DISTANCE_MIN = 120;
|
|
constexpr float DRIFT_DISTANCE_RANGE = 80;
|
|
constexpr float DRIFT_SLACK = 32;
|
|
constexpr float DRIFT_SPEED = 1.3f;
|
|
constexpr float BLUE_DRIFT_SCALE = 0.175f;
|
|
constexpr float OCTANT = 0.7853982f;
|
|
|
|
// ??? teleports every 100 frames one roll in 2, near his target: 151 out along its heading, or around it on further
|
|
// rings, keeping 150 from every player, in 20 tries. Isaac reappears anywhere 100 from every player.
|
|
constexpr int TELEPORT_INTERVAL = 100;
|
|
constexpr float TELEPORT_REACH = 151;
|
|
constexpr float TELEPORT_CLEARANCE = 150;
|
|
constexpr float TELEPORT_RING_STEP = 12.5f;
|
|
constexpr float TELEPORT_TURN = 90;
|
|
constexpr float TELEPORT_FULL_TURN = 360;
|
|
constexpr int TELEPORT_TURNS = 4;
|
|
constexpr int ISAAC_TELEPORT_TRIES = 20;
|
|
constexpr float ISAAC_TELEPORT_CLEARANCE = 100;
|
|
|
|
// The light walls: from the top corner 10 in, a line of 11 beams 60 apart slanting down and across, moving 75 (plus
|
|
// up to 20 of jitter) further every 8 frames and shifted along its slant by up to 75 times root 2, until no beam fits
|
|
// in the room. Then Isaac reappears and fires pattern 27.
|
|
constexpr float WALL_INSET = 10;
|
|
constexpr float WALL_STEP = 75;
|
|
constexpr float WALL_JITTER = 20;
|
|
constexpr float WALL_BEAM_SPACING = 60;
|
|
constexpr int WALL_STEP_FRAMES = 8;
|
|
constexpr int WALL_BEAM_FIRST = -1;
|
|
constexpr int WALL_BEAM_END = 10;
|
|
constexpr float WALL_SLANT_SCALE = 255;
|
|
constexpr float WALL_BEAM_MARGIN = 10;
|
|
constexpr int WALL_ATTACK_PATTERN = 27;
|
|
constexpr RNG WALL_JITTER_RNG = {0, 1, 11, 6};
|
|
|
|
// Hush rises 60 below the room's top when Hush's ??? dies, and every shot within 1000 is gone.
|
|
constexpr float HUSH_DROP = 60;
|
|
constexpr float SHOT_CLEAR_RADIUS = 1000;
|
|
constexpr float HUSH_MUSIC_FADE = 0.08f;
|
|
|
|
// Logs a line with one number, as KAGE_LogMessage's callers format it.
|
|
static void isaac_log(const char* format, int value)
|
|
{
|
|
char line[64];
|
|
std::snprintf(line, sizeof(line), format, value);
|
|
KAGE_LogMessage(LOG_INFO, (uint8_t*)line);
|
|
}
|
|
|
|
// One of the bytes Isaac keeps in i2.
|
|
static int byte_get(const Entity_NPC& npc, IsaacByte index)
|
|
{
|
|
return npc.i2 >> (index * 8) & 0xff;
|
|
}
|
|
|
|
static void byte_set(Entity_NPC& npc, IsaacByte index, int value)
|
|
{
|
|
int shift = index * 8;
|
|
npc.i2 = (npc.i2 & ~(0xff << shift)) | (value & 0xff) << shift;
|
|
}
|
|
|
|
// Whether his animation reached a frame on this update.
|
|
static bool anim_frame_crossed(Entity_NPC& npc, float frame)
|
|
{
|
|
const AnimationState& anim = npc.sprite.animState;
|
|
float current = anim.animData ? anim.animFrame : ANIMATION_FRAME_UNSET;
|
|
return current - npc.speedMultiplier * npc.sprite.playbackSpeed < frame && anim.animData && frame <= current;
|
|
}
|
|
|
|
// Marks a spot's cell so walkers keep off it, unless the room blocks it already.
|
|
static void grid_path_claim(Vector position)
|
|
{
|
|
Room& room = *g_game->room;
|
|
int cell = room.GetGridIndex(position);
|
|
if (cell >= 0 && cell < ROOM_GRID_CELLS && room.gridPaths[cell] < ISAAC_PATH_LIMIT)
|
|
room.gridPaths[cell] = GRID_PATH_FREED;
|
|
}
|
|
|
|
static bool is_blue(const Entity_NPC& npc)
|
|
{
|
|
return npc.variant == ISAAC_FORM_CHEST || npc.variant == ISAAC_FORM_HUSH;
|
|
}
|
|
|
|
// A light beam of his at a spot, hurting from where it lands.
|
|
static Entity* light_beam_spawn(Entity_NPC& npc, Vector position)
|
|
{
|
|
return g_game->Spawn({.position = position, .spawner = &npc, .subType = BEAM_SUBTYPE, .type = ENTITY_EFFECT,
|
|
.variant = EFFECT_CRACK_THE_SKY, .seed = Random()});
|
|
}
|
|
|
|
// The first update: he sits where he is, ready to attack after a minute or two. ??? takes a shield on G-Fuel.
|
|
static void isaac_init(Entity_NPC& npc)
|
|
{
|
|
npc.targetPosition = npc.pos;
|
|
byte_set(npc, BYTE_PHASE, ISAAC_SITTING);
|
|
npc.stateFrame = 0;
|
|
npc.state = NPC_STATE_IDLE;
|
|
byte_set(npc, BYTE_COOLDOWN, Random() % FIRST_COOLDOWN_RANGE + FIRST_COOLDOWN_MIN);
|
|
if (npc.variant == ISAAC_FORM_CHEST && g_game->seedEffects.HasSeedEffect(SEED_G_FUEL))
|
|
npc.shieldStrength = G_FUEL_SHIELD;
|
|
}
|
|
|
|
// Below his thresholds he stands (??? calling two eternal flies), then takes his wings.
|
|
static void phase_update(Entity_NPC& npc)
|
|
{
|
|
bool isIsaac = npc.variant == ISAAC_FORM_CATHEDRAL;
|
|
if (!isIsaac && !is_blue(npc)) return;
|
|
|
|
float stand = npc.maxHitPoints * (isIsaac ? STAND_THRESHOLD : BLUE_STAND_THRESHOLD);
|
|
if (npc.health < stand && byte_get(npc, BYTE_PHASE) == ISAAC_SITTING)
|
|
{
|
|
byte_set(npc, BYTE_PHASE, ISAAC_STANDING);
|
|
npc.state = NPC_STATE_SPECIAL;
|
|
if (is_blue(npc))
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
uint32_t seed = Random();
|
|
Entity* fly =
|
|
g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_ETERNALFLY, .seed = seed});
|
|
fly->parent = &npc;
|
|
}
|
|
}
|
|
if (npc.health < npc.maxHitPoints * WINGS_THRESHOLD && byte_get(npc, BYTE_PHASE) == ISAAC_STANDING)
|
|
{
|
|
byte_set(npc, BYTE_PHASE, ISAAC_WINGED);
|
|
npc.state = NPC_STATE_SPECIAL;
|
|
}
|
|
}
|
|
|
|
// His aimed shots, one to three by the hits he took, straight along an axis for winged Isaac and leading with his own
|
|
// drift once winged.
|
|
static void aimed_shots_fire(Entity_NPC& npc, int phase, float speed)
|
|
{
|
|
ProjectileParams params;
|
|
if (Random() % SHOT_HOMING_ODDS == 0 && is_blue(npc))
|
|
{
|
|
params.bulletFlags |= PROJECTILE_SMART;
|
|
params.scale = SHOT_HOMING_SCALE;
|
|
}
|
|
else params.variant = PROJECTILE_TEAR;
|
|
params.fallingSpeedModifier = SHOT_FALL;
|
|
params.fallingAccelModifier = SHOT_FALL;
|
|
|
|
int count = npc.v2.y > HITS_THIRD_SHOT ? 3 : npc.v2.y > HITS_SECOND_SHOT ? 2 : 1;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
Vector aim = vector_sub(npc.GetPlayerTarget()->pos, npc.pos);
|
|
if (phase >= ISAAC_WINGED && npc.variant == ISAAC_FORM_CATHEDRAL)
|
|
{
|
|
if (std::abs(aim.x) <= std::abs(aim.y)) aim.x = 0;
|
|
else aim.y = 0;
|
|
}
|
|
aim = vector_add(vector_normalized(aim), vector_scale(random_direction(), SHOT_WOBBLE));
|
|
Vector velocity = vector_resized(aim, speed);
|
|
if (phase >= ISAAC_WINGED && npc.variant == ISAAC_FORM_CATHEDRAL)
|
|
velocity = vector_add(velocity, vector_scale(npc.velocity, SHOT_LEAD));
|
|
else if (phase >= ISAAC_WINGED && is_blue(npc))
|
|
velocity = vector_add(velocity, vector_scale(npc.velocity, BLUE_SHOT_LEAD));
|
|
npc.FireProjectiles(npc.pos, velocity, PROJECTILES_SINGLE, params);
|
|
}
|
|
npc.v2.y -= count * (is_blue(npc) ? BLUE_HITS_PER_SHOT : HITS_PER_SHOT);
|
|
}
|
|
|
|
// Hits since his last shots pile up, and he shoots on his interval (winged, only while idle).
|
|
static void aimed_shots_update(Entity_NPC& npc)
|
|
{
|
|
if (npc.v2.x > npc.health) npc.v2.y = std::min(npc.v2.x - npc.health + npc.v2.y, HITS_CAP);
|
|
|
|
int phase = byte_get(npc, BYTE_PHASE);
|
|
int interval = phase == ISAAC_STANDING ? SHOT_INTERVAL_STANDING : SHOT_INTERVAL;
|
|
float speed = ISAAC_SHOT_SPEED;
|
|
if (phase < ISAAC_WINGED)
|
|
{
|
|
if (is_blue(npc)) interval /= 2;
|
|
if (phase == ISAAC_STANDING) speed = SHOT_SPEED_STANDING;
|
|
}
|
|
else interval = is_blue(npc) ? SHOT_INTERVAL_WINGED_BLUE : SHOT_INTERVAL_WINGED;
|
|
if (is_blue(npc)) speed *= BLUE_SHOT_SPEED_SCALE;
|
|
|
|
bool isShooting = npc.state != NPC_STATE_ATTACK && (phase < ISAAC_WINGED || npc.state == NPC_STATE_IDLE);
|
|
if (isShooting && npc.GetIntervalTicks((float)interval, 0)) aimed_shots_fire(npc, phase, speed);
|
|
npc.v2.y = std::max(npc.v2.y, 0.0f);
|
|
}
|
|
|
|
// ??? throws out flies now and then below 90%, keeping the room under 10 enemies.
|
|
static void blue_summons_update(Entity_NPC& npc, int enemies)
|
|
{
|
|
if (!is_blue(npc) || !npc.GetIntervalTicks(SUMMON_INTERVAL, 0)) return;
|
|
if ((Random() & SUMMON_ODDS_MASK) != 0 || enemies >= BLUE_SUMMON_CROWD) return;
|
|
if (npc.health >= npc.maxHitPoints * BLUE_SUMMON_THRESHOLD) return;
|
|
|
|
int extra = (int)(Random() & 3) + SUMMON_COUNT_MIN;
|
|
int count = enemies + extra < BLUE_SUMMON_CROWD + 1 ? extra : BLUE_SUMMON_CROWD - enemies;
|
|
float angle = random_unit() * PI_F * 2;
|
|
float step = 2 * PI_F / (float)count;
|
|
for (int i = 0; i < count; i++, angle += step)
|
|
{
|
|
int type = (Random() & 3) == 0 ? ENTITY_MOTER : ENTITY_ATTACKFLY;
|
|
int subType = SUMMON_SUBTYPE;
|
|
if (npc.health < npc.maxHitPoints * POOTER_THRESHOLD && (Random() & 3) != 0)
|
|
{
|
|
subType = SUMMON_SUBTYPE_POOTER;
|
|
type = ENTITY_POOTER;
|
|
}
|
|
Vector direction = vector_make(std::cos(angle), std::sin(angle));
|
|
uint32_t seed = Random();
|
|
Entity* fly = g_game->Spawn({.position = vector_add(npc.pos, vector_scale(direction, BLUE_SUMMON_REACH)),
|
|
.velocity = vector_scale(direction, SUMMON_SPEED),
|
|
.spawner = &npc,
|
|
.subType = subType,
|
|
.type = type,
|
|
.seed = seed});
|
|
fly->ClearEntityFlags(FLAG_APPEAR);
|
|
fly->isKillOnTouch = true;
|
|
}
|
|
}
|
|
|
|
// Standing Isaac rolls for two light beams, or for two angelic babies once his helpers are gone.
|
|
static void standing_powers_roll(Entity_NPC& npc, int ticks)
|
|
{
|
|
if (npc.projectileCooldown >= 0)
|
|
{
|
|
npc.projectileCooldown -= ticks;
|
|
return;
|
|
}
|
|
if ((Random() & BEAMS_ODDS_MASK) == 0)
|
|
{
|
|
npc.stateFrame = BEAMS_FRAMES;
|
|
npc.projectileCooldown = BEAMS_COOLDOWN;
|
|
return;
|
|
}
|
|
if (Random() % BABIES_ODDS != 0 || g_game->room->GetAliveEnemiesCount() >= BABIES_CROWD) return;
|
|
|
|
npc.projectileCooldown = BABIES_COOLDOWN;
|
|
for (int i = 0; i < BABIES_COUNT; i++)
|
|
{
|
|
Vector around = vector_add(npc.pos, vector_scale(random_direction(), BABIES_REACH));
|
|
Vector spot = room_free_pickup_position_find({.position = around, .isAvoidActiveEntities = true,
|
|
.isAllowPits = true});
|
|
Vector jitter = random_direction();
|
|
float reach = random_unit() * BABIES_JITTER;
|
|
Vector position = vector_add(spot, vector_scale(jitter, reach));
|
|
g_game->Spawn({.position = position, .spawner = &npc, .type = ENTITY_BABY, .variant = BABY_ANGELIC,
|
|
.seed = Random()});
|
|
}
|
|
}
|
|
|
|
// While standing, his beam countdown drops a light beam every 5 frames, at a random spot or where his target heads.
|
|
static void standing_beams_update(Entity_NPC& npc, int ticks)
|
|
{
|
|
Room& room = *g_game->room;
|
|
for (; ticks > 0; ticks--)
|
|
{
|
|
if (byte_get(npc, BYTE_PHASE) != ISAAC_STANDING) continue;
|
|
if (npc.stateFrame-- <= 0 || npc.stateFrame % BEAMS_SPACING != 0) continue;
|
|
|
|
Vector spot = room_free_pickup_position_find({.position = room.GetRandomPosition(BEAM_SPOT_MARGIN)});
|
|
Vector jitter = random_direction();
|
|
spot = vector_add(spot, vector_scale(jitter, random_unit() * BEAM_JITTER));
|
|
if (Random() % BEAM_AIM_ODDS == 0)
|
|
{
|
|
Entity& target = *npc.GetPlayerTarget();
|
|
float lead = vector_length(vector_sub(npc.pos, target.pos)) * BEAM_AIM_LEAD;
|
|
spot = room.GetClampedPositionImpl(vector_add(target.pos, vector_scale(target.velocity, lead)),
|
|
BEAM_SPOT_MARGIN, BEAM_SPOT_MARGIN, BEAM_SPOT_MARGIN,
|
|
BEAM_SPOT_MARGIN);
|
|
}
|
|
grid_path_claim(spot);
|
|
Entity* beam = light_beam_spawn(npc, spot);
|
|
beam->SetSize(BEAM_SIZE, vector_make(-1, -1), -1);
|
|
beam->Update();
|
|
}
|
|
}
|
|
|
|
// Winged he drifts toward a spot by his target (along its axis for Isaac), stepping along the nearest of 8
|
|
// directions. Feared or shrunk he flees it, confused he wanders.
|
|
static void winged_drift(Entity_NPC& npc)
|
|
{
|
|
if (npc.GetIntervalTicks(DRIFT_INTERVAL, 0))
|
|
{
|
|
if (npc.variant == ISAAC_FORM_CATHEDRAL) npc.v1.y = random_unit() * DRIFT_DISTANCE_RANGE + DRIFT_DISTANCE_MIN;
|
|
if (npc.variant == ISAAC_FORM_CHEST) npc.v1.y = 0;
|
|
}
|
|
Vector targetPos = npc.GetPlayerTarget()->pos;
|
|
Vector away = vector_sub(npc.pos, targetPos);
|
|
if (npc.variant == ISAAC_FORM_CATHEDRAL)
|
|
{
|
|
if (std::abs(away.x) <= std::abs(away.y)) away.x = 0;
|
|
else away.y = 0;
|
|
}
|
|
Vector goal = vector_sub(vector_add(targetPos, vector_scale(vector_normalized(away), npc.v1.y)), npc.pos);
|
|
|
|
if (npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK))
|
|
{
|
|
if (is_blue(npc)) npc.friction = HELD_FRICTION;
|
|
npc.pathfinder.EvadeTarget(targetPos, STATUS_OBEYED);
|
|
return;
|
|
}
|
|
if (npc.HasEntityFlags(FLAG_CONFUSION))
|
|
{
|
|
if (is_blue(npc)) npc.friction = HELD_FRICTION;
|
|
int moves = npc.variant == ISAAC_FORM_CATHEDRAL ? 3 : 1;
|
|
for (int i = 0; i < moves; i++) npc.pathfinder.MoveRandomly(STATUS_OBEYED);
|
|
return;
|
|
}
|
|
if (vector_length(goal) <= DRIFT_SLACK) return;
|
|
|
|
float angle = std::floor(std::atan2(goal.y, goal.x) / OCTANT + 0.5f) * OCTANT;
|
|
Vector step = vector_scale(vector_normalized(vector_make(std::cos(angle), std::sin(angle))), DRIFT_SPEED);
|
|
npc_push(npc, is_blue(npc) ? vector_scale(step, BLUE_DRIFT_SCALE) : step);
|
|
}
|
|
|
|
// Idle he waits out his cooldown (only once hurt), then picks an attack. Isaac calls a wall at each tenth of his
|
|
// health below half, ??? teleports now and then, and winged he drifts about his target.
|
|
static void idle_update(Entity_NPC& npc, int ticks)
|
|
{
|
|
int phase = byte_get(npc, BYTE_PHASE);
|
|
npc_anim_loop(npc.sprite, phase == ISAAC_SITTING ? "1Idle" : phase == ISAAC_STANDING ? "2Idle" : "3Idle");
|
|
|
|
int cooldown = byte_get(npc, BYTE_COOLDOWN);
|
|
if (cooldown - ticks < 1 && npc.health < npc.maxHitPoints)
|
|
{
|
|
npc.state = NPC_STATE_ATTACK;
|
|
npc.projectileCooldown = ISAAC_ATTACK_FRAMES;
|
|
byte_set(npc, BYTE_COOLDOWN, 0);
|
|
if (phase != ISAAC_STANDING)
|
|
{
|
|
uint32_t picks = Random();
|
|
npc.i1 = (int)(Random() % ATTACK_PATTERNS + picks % ATTACK_PICKS * ATTACK_PATTERNS);
|
|
}
|
|
else npc.i1 = (npc.i1 + 1) % 2;
|
|
npc.v1.x = random_unit() * PI_F;
|
|
}
|
|
else byte_set(npc, BYTE_COOLDOWN, std::max(cooldown - ticks, 0));
|
|
|
|
if (is_blue(npc) && phase >= ISAAC_WINGED && (g_game->frameCount - npc.spawnFrame) % TELEPORT_INTERVAL == 0 &&
|
|
(Random() & 1) == 0)
|
|
{
|
|
npc.state = NPC_STATE_JUMP;
|
|
npc.i1 = STEP_VANISH;
|
|
}
|
|
if (npc.variant == ISAAC_FORM_CATHEDRAL && phase >= ISAAC_WINGED && phase <= WALL_PHASE_LAST &&
|
|
npc.health < npc.maxHitPoints * WALL_THRESHOLDS[phase - ISAAC_WINGED])
|
|
{
|
|
byte_set(npc, BYTE_PHASE, phase + 1);
|
|
npc.state = NPC_STATE_ATTACK2;
|
|
npc.i1 = STEP_VANISH;
|
|
}
|
|
if (phase >= ISAAC_WINGED) winged_drift(npc);
|
|
}
|
|
|
|
// Isaac's ring wave, by his pattern: curving one way then the other, straight, turning by waves, or through walls.
|
|
static void isaac_wave_fire(Entity_NPC& npc, int wave)
|
|
{
|
|
ProjectileParams params;
|
|
params.circleAngle = npc.v1.x;
|
|
params.variant = PROJECTILE_TEAR;
|
|
params.fallingSpeedModifier = SHOT_FALL;
|
|
params.fallingAccelModifier = RING_FALL_ACCEL;
|
|
params.curvingStrength = RING_CURVE;
|
|
Vector ring = vector_make(ISAAC_RING_SPEED, RING_COUNT);
|
|
int pattern = npc.i1 % ATTACK_PATTERNS;
|
|
switch (pattern)
|
|
{
|
|
case 0:
|
|
params.bulletFlags = PROJECTILE_CURVE_LEFT;
|
|
break;
|
|
case 1:
|
|
params.bulletFlags = PROJECTILE_CURVE_RIGHT;
|
|
break;
|
|
case 3:
|
|
ring.y = RING_COUNT_SMALL;
|
|
if (wave % 2 == 0) params.circleAngle += RING_HALF_STEP;
|
|
break;
|
|
case 4:
|
|
ring = vector_make(RING_SPEED_FAST, RING_COUNT_SMALL);
|
|
params.bulletFlags |= PROJECTILE_CURVE_LEFT | PROJECTILE_NO_WALL_COLLIDE;
|
|
params.curvingStrength = RING_CURVE_FAST;
|
|
break;
|
|
}
|
|
npc.FireProjectiles(npc.pos, ring, PROJECTILES_RING, params);
|
|
if (pattern > 1) return;
|
|
|
|
params.bulletFlags = pattern == 0 ? PROJECTILE_CURVE_RIGHT : PROJECTILE_CURVE_LEFT;
|
|
params.curvingStrength = RING_CURVE_SECOND;
|
|
params.fallingAccelModifier = RING_FALL_ACCEL_SECOND;
|
|
npc.FireProjectiles(npc.pos, vector_make(RING_SPEED_SECOND, ring.y), PROJECTILES_RING, params);
|
|
}
|
|
|
|
// ???'s burst: an even spread from below him, curving once he is hurt, now and then big and homing.
|
|
static void blue_burst_fire(Entity_NPC& npc)
|
|
{
|
|
int count = (int)npc.v1.x % BURST_COUNT_PICKS + BURST_COUNT_MIN;
|
|
float step = 2 * PI_F / (float)count;
|
|
float angle = npc.v1.x;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
angle += step;
|
|
Vector velocity = vector_make(std::cos(angle) * BLUE_BURST_SPEED, std::sin(angle) * BLUE_BURST_SPEED);
|
|
ProjectileParams params;
|
|
if (is_blue(npc))
|
|
{
|
|
params.fallingAccelModifier = npc.variant == ISAAC_FORM_CHEST ? BLUE_BURST_FALL_ACCEL : BURST_FALL_ACCEL_HUSH;
|
|
params.fallingSpeedModifier = SHOT_FALL;
|
|
}
|
|
if (npc.health < npc.maxHitPoints * BLUE_SUMMON_THRESHOLD)
|
|
{
|
|
params.bulletFlags = PROJECTILE_CURVE_RIGHT;
|
|
if (npc.variant == ISAAC_FORM_CHEST) params.curvingStrength = BURST_CURVE;
|
|
else if (npc.variant == ISAAC_FORM_HUSH) params.curvingStrength = BURST_CURVE_HUSH;
|
|
}
|
|
if (npc.i1 < BURST_BIG_PICKS && Random() % BURST_BIG_ODDS == 0)
|
|
{
|
|
params.bulletFlags |= PROJECTILE_SMART;
|
|
params.scale = BURST_BIG_SCALE;
|
|
}
|
|
else params.variant = PROJECTILE_TEAR;
|
|
npc.FireProjectiles(vector_make(npc.pos.x, npc.pos.y + BURST_DROP), velocity, PROJECTILES_SINGLE, params);
|
|
}
|
|
}
|
|
|
|
// One wave of his attack, with its cries. Sitting he restarts his attack pose, winged he lowers his arms on the last.
|
|
static void wave_fire(Entity_NPC& npc, int wave, int waves)
|
|
{
|
|
float pitch = champion_pitch_get(npc);
|
|
npc_sound_play(SOUND_THUMBS_DOWN, WAVE_VOLUME, 2, pitch);
|
|
npc_sound_play(SOUND_BLOODSHOOT, 1, 2, pitch);
|
|
if (npc.variant == ISAAC_FORM_CATHEDRAL) isaac_wave_fire(npc, wave);
|
|
else blue_burst_fire(npc);
|
|
|
|
int phase = byte_get(npc, BYTE_PHASE);
|
|
if (phase == ISAAC_SITTING) npc_anim_restart(npc.sprite, "1Attack");
|
|
if (phase >= ISAAC_WINGED && waves == wave + 1) npc_anim_loop(npc.sprite, "3FBAttack4End");
|
|
}
|
|
|
|
// Standing, his attack is a single ring of big shots as he throws his arms up.
|
|
static void standing_ring_fire(Entity_NPC& npc)
|
|
{
|
|
npc.sprite.Play("2Attack");
|
|
if (!anim_frame_crossed(npc, STAND_RING_FRAME)) return;
|
|
|
|
npc.PlaySound(SOUND_THUMBSUP, 1, 2, false, 1);
|
|
npc.PlaySound(SOUND_BLOODSHOOT, 1, 2, false, 1);
|
|
ProjectileParams params;
|
|
params.circleAngle = npc.v1.x;
|
|
params.scale = STAND_RING_SCALE;
|
|
if (npc.i1 != 0 && npc.i1 != 1) return;
|
|
|
|
Vector ring = npc.i1 == 0 ? BLUE_STAND_RING_FEW : BLUE_STAND_RING_WIDE;
|
|
if (npc.variant == ISAAC_FORM_CATHEDRAL)
|
|
{
|
|
params.variant = PROJECTILE_TEAR;
|
|
if (npc.i1 == 0) params.bulletFlags |= PROJECTILE_BURST;
|
|
ring = npc.i1 == 0 ? STAND_RING_BURST : STAND_RING_WIDE;
|
|
}
|
|
else params.bulletFlags |= PROJECTILE_SMART;
|
|
npc.FireProjectiles(npc.pos, ring, PROJECTILES_RING, params);
|
|
}
|
|
|
|
// Winged, he raises his arms (a chime on frame 17), holds them up through his waves, then lowers them.
|
|
static void winged_pose_update(Entity_NPC& npc)
|
|
{
|
|
if (byte_get(npc, BYTE_COOLDOWN) == 0) npc_anim_loop(npc.sprite, "3FBAttack4Start");
|
|
const AnimationState& anim = npc.sprite.animState;
|
|
if (!anim.animData || anim.animData->name != "3FBAttack4Start") return;
|
|
|
|
if (!anim.isPlaying) npc_anim_loop(npc.sprite, "3FBAttack4Loop");
|
|
else if (anim_frame_crossed(npc, CHARGE_SOUND_FRAME)) npc.PlaySound(SOUND_POWERUP2, 1, 2, false, 1);
|
|
}
|
|
|
|
// An attack: waves of shots counted up from the start, then back to idle with a fresh cooldown once its pose ends.
|
|
static void attack_update(Entity_NPC& npc, int ticks)
|
|
{
|
|
int phase = byte_get(npc, BYTE_PHASE);
|
|
bool isLowered = false;
|
|
if (phase == ISAAC_STANDING) standing_ring_fire(npc);
|
|
else
|
|
{
|
|
if (phase == ISAAC_SITTING) npc_anim_loop(npc.sprite, "1Attack");
|
|
else winged_pose_update(npc);
|
|
const AnimationState& anim = npc.sprite.animState;
|
|
isLowered = anim.animData && !anim.isPlaying && anim.animData->name == "3FBAttack4End";
|
|
|
|
for (; ticks > 0; ticks--)
|
|
{
|
|
int count = byte_get(npc, BYTE_COOLDOWN);
|
|
int delay = byte_get(npc, BYTE_PHASE) < ISAAC_WINGED ? WAVE_DELAY : WAVE_DELAY_WINGED;
|
|
int waves = npc.i1 / ATTACK_PATTERNS + WAVES_MIN;
|
|
int since = count - delay;
|
|
float picks = std::clamp((float)npc.i1 / WAVE_SPACING_PICKS / WAVE_SPACING_PICKS, 0.0f, 1.0f);
|
|
int spacing = (int)(picks * WAVE_SPACING_RANGE + WAVE_SPACING_MIN);
|
|
if (count > delay && since % spacing == 0 && since / spacing < waves) wave_fire(npc, since / spacing, waves);
|
|
byte_set(npc, BYTE_COOLDOWN, count + 1);
|
|
}
|
|
}
|
|
|
|
if ((byte_get(npc, BYTE_PHASE) < ISAAC_WINGED && npc_anim_is_done(npc)) || isLowered)
|
|
{
|
|
npc.state = NPC_STATE_IDLE;
|
|
int cooldown = (int)(Random() % COOLDOWN_RANGE) + COOLDOWN_MIN;
|
|
byte_set(npc, BYTE_COOLDOWN, npc.variant == ISAAC_FORM_HUSH ? cooldown / HUSH_COOLDOWN_DIVISOR : cooldown);
|
|
}
|
|
}
|
|
|
|
// Standing up (a chime on frame 20) or taking his wings (on frame 17), then idle.
|
|
static void rise_update(Entity_NPC& npc)
|
|
{
|
|
int phase = byte_get(npc, BYTE_PHASE);
|
|
if (phase == ISAAC_STANDING)
|
|
{
|
|
npc.sprite.Play("1StandUp");
|
|
if (anim_frame_crossed(npc, STAND_SOUND_FRAME)) npc.PlaySound(SOUND_HOLY, 1, 2, false, 1);
|
|
}
|
|
else if (phase >= ISAAC_WINGED)
|
|
{
|
|
npc.sprite.Play("2Evolve");
|
|
if (anim_frame_crossed(npc, EVOLVE_SOUND_FRAME)) npc.PlaySound(SOUND_SUPERHOLY, 1, 2, false, 1);
|
|
}
|
|
if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE;
|
|
}
|
|
|
|
// Fading out through a portal. True once gone.
|
|
static bool vanish_update(Entity_NPC& npc)
|
|
{
|
|
npc.sprite.Play("3FBAttack3");
|
|
if (anim_frame_crossed(npc, VANISH_SOUND_FRAME)) npc.PlaySound(SOUND_HELL_PORTAL2, 1, 2, false, 1);
|
|
return npc_anim_is_done(npc);
|
|
}
|
|
|
|
static bool is_player_near(Vector spot, float distance)
|
|
{
|
|
for (Entity_Player* player : g_game->playerManager.playerList)
|
|
if (vector_length(vector_sub(player->pos, spot)) < distance) return true;
|
|
return false;
|
|
}
|
|
|
|
// ??? reappears ahead of his target, or on rings around it while a player stands within 150.
|
|
static void blue_teleport(Entity_NPC& npc)
|
|
{
|
|
float reach = std::max(npc.v1.y, TELEPORT_REACH);
|
|
Entity& target = *npc.GetPlayerTarget();
|
|
Vector heading = vector_is_zero(target.velocity) ? random_direction() : vector_normalized(target.velocity);
|
|
Room& room = *g_game->room;
|
|
Vector spot = room.GetClampedPosition(vector_add(target.pos, vector_scale(heading, reach)), npc.size);
|
|
|
|
int tries = 0;
|
|
float turn = random_unit() * TELEPORT_FULL_TURN;
|
|
while (is_player_near(spot, TELEPORT_CLEARANCE))
|
|
{
|
|
float angle = (float)(tries % TELEPORT_TURNS) * TELEPORT_TURN + turn;
|
|
float ring = (float)tries * TELEPORT_RING_STEP + TELEPORT_REACH;
|
|
spot = room.GetClampedPositionImpl(vector_add(target.pos, vector_scale(vector_from_angle(angle), ring)),
|
|
npc.size, npc.size, npc.size, npc.size);
|
|
if (++tries >= ISAAC_TELEPORT_TRIES) break;
|
|
}
|
|
isaac_log("??? teleport: %d tries\n", tries);
|
|
npc.pos = spot;
|
|
npc.PlaySound(SOUND_HELL_PORTAL1, 1, 2, false, 1);
|
|
}
|
|
|
|
// ???'s teleport: he vanishes, then reappears near his target and goes back to idle.
|
|
static void blue_jump_update(Entity_NPC& npc)
|
|
{
|
|
if (npc.i1 == STEP_VANISH)
|
|
{
|
|
if (vanish_update(npc)) npc.i1 = STEP_APPEAR;
|
|
return;
|
|
}
|
|
if (npc.i1 != STEP_APPEAR) return;
|
|
|
|
npc.sprite.Play("3Appear");
|
|
if (anim_frame_crossed(npc, 0)) blue_teleport(npc);
|
|
if (!npc_anim_is_done(npc)) return;
|
|
npc.i1 = STEP_VANISH;
|
|
npc.state = NPC_STATE_IDLE;
|
|
}
|
|
|
|
// Isaac reappears anywhere in the room 100 from every player, in 20 tries.
|
|
static void isaac_teleport(Entity_NPC& npc)
|
|
{
|
|
npc.isVisible = true;
|
|
npc.entityCollisionClass = ENTCOLL_ALL;
|
|
Room& room = *g_game->room;
|
|
int tries = 0;
|
|
do
|
|
{
|
|
float y = (room.bottomRightPos.y - room.topLeftPos.y) * random_unit() + room.topLeftPos.y;
|
|
float x = (room.bottomRightPos.x - room.topLeftPos.x) * random_unit() + room.topLeftPos.x;
|
|
npc.pos = vector_make(x, y);
|
|
} while (is_player_near(npc.pos, ISAAC_TELEPORT_CLEARANCE) && ++tries < ISAAC_TELEPORT_TRIES);
|
|
isaac_log("Isaac teleport: %d tries\n", tries);
|
|
npc_sound_play(SOUND_HELL_PORTAL1, 1, 2, champion_pitch_get(npc));
|
|
}
|
|
|
|
// One frame of a light wall: every 8 frames a slanted line of beams one step further across. False once none fits.
|
|
static bool wall_step(Entity_NPC& npc)
|
|
{
|
|
Room& room = *g_game->room;
|
|
bool isLeft = npc.i1 < WALL_FROM_RIGHT;
|
|
int frame = npc.i1 - (isLeft ? WALL_FROM_LEFT : WALL_FROM_RIGHT);
|
|
Vector origin = vector_make(isLeft ? room.topLeftPos.x + WALL_INSET : room.bottomRightPos.x - WALL_INSET,
|
|
room.topLeftPos.y + WALL_INSET);
|
|
Vector line = vector_make(isLeft ? -WALL_BEAM_SPACING : WALL_BEAM_SPACING, WALL_BEAM_SPACING);
|
|
|
|
RNG rng = WALL_JITTER_RNG;
|
|
rng._seed = (uint32_t)npc.projectileDelay;
|
|
Vector jitter = RandomVector((uint32_t)npc.projectileDelay);
|
|
float reach = rng.RandomFloat() * WALL_JITTER;
|
|
Vector step = vector_make((isLeft ? WALL_STEP : -WALL_STEP) + reach * jitter.x, reach * jitter.y);
|
|
if (frame % WALL_STEP_FRAMES != 0) return true;
|
|
|
|
int index = frame / WALL_STEP_FRAMES;
|
|
float slant = (float)byte_get(npc, BYTE_WALL_SLANT) / WALL_SLANT_SCALE * (float)index;
|
|
Vector shift = vector_scale(vector_normalized(line), slant * WALL_STEP * std::sqrt(2.0f));
|
|
Vector start = vector_add(vector_scale(step, (float)index), origin);
|
|
EntityConfig_Entity* config = g_manager->entityConfig.GetEntity(ENTITY_EFFECT, EFFECT_CRACK_THE_SKY, 0);
|
|
bool isInRoom = false;
|
|
for (int beam = WALL_BEAM_FIRST; beam < WALL_BEAM_END; beam++)
|
|
{
|
|
Vector spot = vector_add(vector_add(shift, vector_scale(line, (float)beam)), start);
|
|
if (!room.IsPositionInRoom(spot, WALL_BEAM_MARGIN)) continue;
|
|
isInRoom = true;
|
|
light_beam_spawn(npc, spot)->SetSize(BEAM_SIZE, config->collisionRadiusMulti, config->gridCollisionPoints);
|
|
}
|
|
return isInRoom;
|
|
}
|
|
|
|
// Isaac's light walls: he vanishes, a wall sweeps the room from one top corner, then he reappears and attacks.
|
|
static void wall_update(Entity_NPC& npc, int ticks)
|
|
{
|
|
if (byte_get(npc, BYTE_PHASE) < ISAAC_WINGED) return;
|
|
|
|
if (npc.i1 == STEP_VANISH)
|
|
{
|
|
if (!vanish_update(npc)) return;
|
|
npc.i1 = (int)((Random() & 1) + 1) * WALL_FROM_LEFT;
|
|
byte_set(npc, BYTE_WALL_SLANT, (int)Random());
|
|
npc.projectileDelay = (int)Random();
|
|
npc.isVisible = false;
|
|
npc.entityCollisionClass = ENTCOLL_NONE;
|
|
npc.pos = Vector{};
|
|
npc.velocity = Vector{};
|
|
return;
|
|
}
|
|
if (npc.i1 == STEP_APPEAR)
|
|
{
|
|
npc.sprite.Play("3Appear");
|
|
if (anim_frame_crossed(npc, 0)) isaac_teleport(npc);
|
|
if (!npc_anim_is_done(npc)) return;
|
|
npc.i1 = WALL_ATTACK_PATTERN;
|
|
npc.state = NPC_STATE_ATTACK;
|
|
byte_set(npc, BYTE_COOLDOWN, 0);
|
|
return;
|
|
}
|
|
|
|
for (; ticks > 0 && npc.i1 >= WALL_FROM_LEFT && npc.i1 < WALL_END; ticks--, npc.i1++)
|
|
if (!wall_step(npc))
|
|
{
|
|
npc.i1 = STEP_APPEAR;
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Hush's ??? dies into Hush: the shots about are gone and Hush rises at the top of the room to his own music.
|
|
static void hush_call(Entity_NPC& npc)
|
|
{
|
|
Room& room = *g_game->room;
|
|
Vector position = vector_make(Room::GetCenterPos().x, room.topLeftPos.y + HUSH_DROP);
|
|
npc.maxHitPoints = 0;
|
|
room.entityList.bossMaxHealth = 0;
|
|
for (Entity* shot : entity_query_radius(npc.pos, SHOT_CLEAR_RADIUS, QUERY_PROJECTILES)) shot->isDead = true;
|
|
|
|
Entity* hush = g_game->Spawn({.position = position, .spawner = &npc, .type = ENTITY_HUSH, .seed = Random()});
|
|
hush->ClearEntityFlags(FLAG_APPEAR);
|
|
hush->Update();
|
|
g_manager->musicManager.Crossfade(MUSIC_HUSH_BOSS, HUSH_MUSIC_FADE);
|
|
}
|
|
|
|
// 00463100 Isaac (102.0), ??? (102.1) and Hush's ??? (102.2): sitting, standing and winged, with aimed shots, rings
|
|
// and bursts, light beams and walls, angelic babies, summons and teleports. Hush's ??? calls Hush as he dies.
|
|
void boss_isaac_update(Entity_NPC& npc)
|
|
{
|
|
if (npc.state == NPC_STATE_INIT) return isaac_init(npc);
|
|
|
|
int ticks = npc_ticks_get(npc);
|
|
if (byte_get(npc, BYTE_PHASE) == ISAAC_SITTING && Random() % WHIMPER_ODDS == 0)
|
|
npc.PlaySound(SOUND_SCARED_WHIMPER, 1, (int)(Random() % ISAAC_WHIMPER_DELAY_RANGE) + ISAAC_WHIMPER_DELAY_MIN, false, 1);
|
|
if (npc.pendingDamage > 0)
|
|
for (DamageEvent& event : npc.damageEvents)
|
|
if (event.source.type == ENTITY_EFFECT && event.source.variant == EFFECT_CRACK_THE_SKY) event.damage = 0;
|
|
|
|
phase_update(npc);
|
|
if (byte_get(npc, BYTE_PHASE) < ISAAC_WINGED)
|
|
{
|
|
npc.velocity = vector_sub(npc.targetPosition, npc.pos);
|
|
npc.friction *= HELD_FRICTION;
|
|
}
|
|
else npc.friction *= WINGED_FRICTION;
|
|
|
|
aimed_shots_update(npc);
|
|
blue_summons_update(npc, g_game->room->GetAliveEnemiesCount());
|
|
if (byte_get(npc, BYTE_PHASE) == ISAAC_STANDING && npc.variant == ISAAC_FORM_CATHEDRAL) standing_powers_roll(npc, ticks);
|
|
standing_beams_update(npc, ticks);
|
|
|
|
switch (npc.state)
|
|
{
|
|
case NPC_STATE_IDLE:
|
|
idle_update(npc, ticks);
|
|
break;
|
|
case NPC_STATE_ATTACK:
|
|
attack_update(npc, ticks);
|
|
break;
|
|
case NPC_STATE_ATTACK2:
|
|
wall_update(npc, ticks);
|
|
break;
|
|
case NPC_STATE_SPECIAL:
|
|
rise_update(npc);
|
|
break;
|
|
case NPC_STATE_JUMP:
|
|
blue_jump_update(npc);
|
|
break;
|
|
}
|
|
|
|
if (npc.isDead && npc.variant == ISAAC_FORM_HUSH) hush_call(npc);
|
|
npc.v2.x = npc.health;
|
|
}
|
|
|
|
// The babies, by variant: the plain baby, the angelic baby Isaac calls and Ultra Pride's baby. The Imp shares them.
|
|
enum BabyVariant
|
|
{
|
|
BABY_PLAIN,
|
|
BABY_ANGELIC_VARIANT,
|
|
BABY_ULTRA_PRIDE,
|
|
BABY_WRINKLY
|
|
};
|
|
|
|
// Babies drift 0.33 toward their target and splat now and then. One within 200 in line shoots (Ultra Pride's a big
|
|
// homing shot, a summoned angelic baby two) at 8 (10 in hard mode), 35 frames apart.
|
|
constexpr float BABY_FRICTION = 0.7f;
|
|
constexpr float BABY_DRIFT = 0.33f;
|
|
constexpr float BABY_CONTROLLED_DRIFT = 0.1f;
|
|
constexpr float BABY_CONTROL_REACH = 100;
|
|
constexpr int BABY_SPLAT_ODDS = 10;
|
|
constexpr float BABY_SPLAT_MIN = 0.2f;
|
|
constexpr float BABY_SPLAT_RANGE = 0.3f;
|
|
constexpr float ANGEL_SHOT_RANGE = 200;
|
|
constexpr int BABY_SHOT_FRAMES = 7;
|
|
constexpr int BABY_SHOT_COOLDOWN = 35;
|
|
constexpr float BABY_SHOT_VOLUME = 0.85f;
|
|
constexpr float BABY_SHOT_FALL_ACCEL = -0.05f;
|
|
constexpr float BABY_SHOT_SPEED_MULTI = 1.07f;
|
|
constexpr float ANGEL_SHOT_SPEED = 8;
|
|
constexpr float BABY_SHOT_SPEED_HARD = 10;
|
|
constexpr float BABY_BIG_SCALE = 1.5f;
|
|
constexpr int BABY_SUMMONED = 1;
|
|
|
|
// They blink away once restless: 20 after a hit, gaining one a frame while their target is near in line (within 20
|
|
// on an axis and 400 away) and a little each frame. Past 20 they pick a spot 60 to 310 away (50 to 120 from the
|
|
// target for an angelic baby, else 200 off its axes) on a free cell, in two tries, and past 40 they vanish to it,
|
|
// reappearing 24 frames later.
|
|
constexpr float RESTLESS_HIT = 20;
|
|
constexpr float RESTLESS_LINE = 20;
|
|
constexpr float RESTLESS_NEAR = 400;
|
|
constexpr float RESTLESS_DRIFT = 0.1f;
|
|
constexpr float RESTLESS_PICK = 20;
|
|
constexpr float RESTLESS_BLINK = 40;
|
|
constexpr int BLINK_TRIES = 2;
|
|
constexpr float BLINK_REACH_MIN = 60;
|
|
constexpr float BLINK_REACH_RANGE = 250;
|
|
constexpr float ANGELIC_BLINK_MIN = 50;
|
|
constexpr float ANGELIC_BLINK_MAX = 120;
|
|
constexpr float BLINK_AXIS_SLACK = 20;
|
|
constexpr float BLINK_TARGET_MIN = 200;
|
|
constexpr int BLINK_PATH_LIMIT = 499;
|
|
constexpr int BABY_BLINK_FRAMES = 24;
|
|
constexpr int GRID_COLUMN_ORIGIN = 40;
|
|
constexpr int GRID_ROW_ORIGIN = 120;
|
|
constexpr int BABY_GRID_CELL = 40;
|
|
|
|
// The Imp growls one time in 90 a second later and, one roll in 20 while it may attack, shoots every 10 frames for 20
|
|
// to 49 frames (50 controlled) at 10, its target's lead 5 frames ahead, then rests 30. Shots within 100 push it aside.
|
|
constexpr int IMP_GROWL_ODDS = 90;
|
|
constexpr int IMP_GROWL_DELAY = 60;
|
|
constexpr int IMP_ATTACK_ODDS = 20;
|
|
constexpr float IMP_CONTROLLED_RANGE = 1000;
|
|
constexpr int IMP_ATTACK_MIN = 20;
|
|
constexpr int IMP_ATTACK_RANGE = 30;
|
|
constexpr int IMP_ATTACK_CONTROLLED = 50;
|
|
constexpr int IMP_SHOT_SPACING = 10;
|
|
constexpr float IMP_SHOT_SPEED = 10;
|
|
constexpr float IMP_SHOT_LEAD = 5;
|
|
constexpr int IMP_REST = 30;
|
|
constexpr float IMP_DODGE_RADIUS = 100;
|
|
constexpr float IMP_DODGE_REACH_SQUARED = 10000;
|
|
constexpr float IMP_DODGE_MIN = 2;
|
|
constexpr float IMP_CHARGE_RATE = 0.05f;
|
|
constexpr float IMP_CHARGE_PUSH = 1.6f;
|
|
constexpr float IMP_RECHARGE_RATE = 0.1f;
|
|
constexpr int CONTROL_ACTION_DASH = 8;
|
|
constexpr int CONTROL_ACTION_BLINK = 9;
|
|
constexpr int CONTROL_TARGET_BLINK = 2;
|
|
constexpr float BLINK_PATH_SPEED = 4;
|
|
|
|
static bool is_imp(const Entity_NPC& npc)
|
|
{
|
|
return npc.type == ENTITY_IMP;
|
|
}
|
|
|
|
// A blink spot: a random one 60 to 310 out, kept if it suits the baby and lies on a free cell, snapped to its center.
|
|
static void blink_spot_pick(Entity_NPC& npc)
|
|
{
|
|
for (int tries = 0; vector_is_zero(npc.targetPosition) && tries < BLINK_TRIES; tries++)
|
|
{
|
|
float angle = random_unit() * PI_ROUGH * 2;
|
|
float reach = random_unit() * BLINK_REACH_RANGE + BLINK_REACH_MIN;
|
|
Vector spot = vector_make(std::cos(angle) * reach + npc.pos.x, std::sin(angle) * reach + npc.pos.y);
|
|
Vector fromTarget = vector_sub(npc.GetPlayerTarget()->pos, spot);
|
|
float distance = vector_length(fromTarget);
|
|
bool isSuited = npc.variant == BABY_ANGELIC_VARIANT
|
|
? distance > ANGELIC_BLINK_MIN && distance < ANGELIC_BLINK_MAX
|
|
: std::abs(fromTarget.x) > BLINK_AXIS_SLACK && std::abs(fromTarget.y) > BLINK_AXIS_SLACK &&
|
|
distance > BLINK_TARGET_MIN;
|
|
if (!isSuited) continue;
|
|
|
|
Room& room = *g_game->room;
|
|
int column = (int)((spot.x - GRID_COLUMN_ORIGIN) / BABY_GRID_CELL + 0.5f);
|
|
int row = (int)((spot.y - GRID_ROW_ORIGIN) / BABY_GRID_CELL + 0.5f);
|
|
if (column < 0 || column >= room.gridWidth || row < 0 || row >= room.gridHeight) continue;
|
|
int cell = row * room.gridWidth + column;
|
|
if (cell < 0 || (cell < ROOM_GRID_CELLS && room.gridPaths[cell] > BLINK_PATH_LIMIT)) continue;
|
|
if (room.GetGridCollision(cell) != 0) continue;
|
|
npc.targetPosition = vector_make((float)(cell % room.gridWidth * BABY_GRID_CELL + GRID_COLUMN_ORIGIN),
|
|
(float)(cell / room.gridWidth * BABY_GRID_CELL + GRID_ROW_ORIGIN));
|
|
}
|
|
}
|
|
|
|
// Starts a blink: the Vanish animation, no shadow, and the Imp's warp sound.
|
|
static void blink_start(Entity_NPC& npc)
|
|
{
|
|
npc.state = NPC_STATE_JUMP;
|
|
npc.stateFrame = 0;
|
|
npc_anim_restart(npc.sprite, "Vanish");
|
|
npc.shadowSize = 0;
|
|
}
|
|
|
|
// The Imp rolls to attack while hostile (controlled, while aiming), then counts down its rest.
|
|
static void imp_move_update(Entity_NPC& npc, int ticks)
|
|
{
|
|
if (Random() % IMP_GROWL_ODDS == 0) npc_sound_play(SOUND_IMP_GROWL, 1, IMP_GROWL_DELAY, 1);
|
|
if (npc.projectileDelay < 1)
|
|
{
|
|
bool isAttacking = false;
|
|
if (npc.controllerID != -1) isAttacking = npc.IsTargetInAttackRange(IMP_CONTROLLED_RANGE, BABY_SHOT_FRAMES, false);
|
|
else if (Random() % IMP_ATTACK_ODDS == 0) isAttacking = npc.IsHostileTo(npc.GetPlayerTarget());
|
|
if (isAttacking)
|
|
{
|
|
npc.state = NPC_STATE_ATTACK;
|
|
npc.projectileCooldown =
|
|
npc.controllerID == -1 ? (int)(Random() % IMP_ATTACK_RANGE) + IMP_ATTACK_MIN : IMP_ATTACK_CONTROLLED;
|
|
npc.SpawnControlTarget(0, -1);
|
|
}
|
|
}
|
|
if (npc.projectileDelay > 0) npc.projectileDelay -= ticks;
|
|
}
|
|
|
|
// A baby splats now and then and shoots its target once in range and rested.
|
|
static void baby_move_update(Entity_NPC& npc, int ticks)
|
|
{
|
|
if (Random() % BABY_SPLAT_ODDS == 0) npc.MakeSplat(random_unit() * BABY_SPLAT_RANGE + BABY_SPLAT_MIN);
|
|
if (npc.projectileCooldown < 1 && npc.IsTargetInAttackRange(ANGEL_SHOT_RANGE, BABY_SHOT_FRAMES, false))
|
|
{
|
|
npc.projectileCooldown = BABY_SHOT_COOLDOWN;
|
|
npc_anim_restart(npc.sprite, "Attack");
|
|
npc.UpdateControllerMovement(true);
|
|
}
|
|
if (npc.sprite.animState.animData && npc.sprite.IsEventTriggered("Shoot"))
|
|
{
|
|
npc.UpdateControllerMovement(false);
|
|
npc.PlaySound(SOUND_FLOATY_BABY_ROAR, BABY_SHOT_VOLUME, 2, false, 1);
|
|
ProjectileParams params;
|
|
params.fallingAccelModifier = BABY_SHOT_FALL_ACCEL;
|
|
params.velocityMulti = BABY_SHOT_SPEED_MULTI;
|
|
ProjectilesMode mode = PROJECTILES_SINGLE;
|
|
if (npc.variant == BABY_ULTRA_PRIDE)
|
|
{
|
|
params.bulletFlags |= PROJECTILE_SMART;
|
|
params.scale = BABY_BIG_SCALE;
|
|
}
|
|
else if (npc.variant == BABY_ANGELIC_VARIANT && npc.subtype != BABY_SUMMONED) mode = PROJECTILES_TWO;
|
|
float speed = game_is_hard_mode() ? BABY_SHOT_SPEED_HARD : ANGEL_SHOT_SPEED;
|
|
Vector aim = vector_sub(npc.GetPlayerTarget()->pos, npc.pos);
|
|
if (npc.controllerID != -1 && !vector_is_zero(npc.controllerMovement)) aim = npc.controllerMovement;
|
|
npc.FireProjectiles(npc.pos, vector_scale(vector_normalized(aim), speed), mode, params);
|
|
}
|
|
if (npc.projectileCooldown > 0) npc.projectileCooldown -= ticks;
|
|
}
|
|
|
|
// Moving: attacks, the Move loop, and growing restless until a blink.
|
|
static void baby_wander_update(Entity_NPC& npc, int ticks, Vector toTarget)
|
|
{
|
|
npc.entityCollisionClass = ENTCOLL_ALL;
|
|
if (is_imp(npc)) imp_move_update(npc, ticks);
|
|
else baby_move_update(npc, ticks);
|
|
if (npc_anim_is_done(npc)) npc_anim_loop(npc.sprite, "Move");
|
|
|
|
if (npc.pendingDamage > 0) npc.v1.x = RESTLESS_HIT;
|
|
bool isInLine = std::abs(toTarget.x) < RESTLESS_LINE || std::abs(toTarget.y) < RESTLESS_LINE;
|
|
if (isInLine && vector_length(toTarget) < RESTLESS_NEAR) npc.v1.x += 1;
|
|
npc.v1.x += random_unit() * RESTLESS_DRIFT;
|
|
|
|
if (npc.controllerID != -1)
|
|
{
|
|
if (!npc.IsControllerActionPressed(CONTROL_ACTION_BLINK)) return;
|
|
blink_start(npc);
|
|
npc.targetPosition = npc.pos;
|
|
return;
|
|
}
|
|
if (npc.v1.x > RESTLESS_PICK) blink_spot_pick(npc);
|
|
if (npc.v1.x <= RESTLESS_BLINK || vector_is_zero(npc.targetPosition)) return;
|
|
blink_start(npc);
|
|
if (is_imp(npc)) npc_sound_play(SOUND_IMP_WARP_OUT, 1, 2, 1);
|
|
}
|
|
|
|
// Blinking: gone and harmless, then back at its spot 24 frames on, and moving again once the animation ends.
|
|
static void baby_blink_update(Entity_NPC& npc)
|
|
{
|
|
if (npc.controllerID != -1 && !vector_is_zero(npc.targetPosition))
|
|
{
|
|
npc.SpawnControlTarget(CONTROL_TARGET_BLINK, -1);
|
|
npc.pathfinder.FindGridPath(Vector{}, BLINK_PATH_SPEED, 0, DIRECT_PATH_FAR);
|
|
npc.targetPosition = npc.pos;
|
|
}
|
|
npc.entityCollisionClass = ENTCOLL_NONE;
|
|
if (npc.stateFrame > BABY_BLINK_FRAMES && !vector_is_zero(npc.targetPosition))
|
|
{
|
|
npc.shadowSize = npc.config->shadowSize;
|
|
npc_anim_restart(npc.sprite, "Vanish2");
|
|
npc.stateFrame = 0;
|
|
npc.pos = npc.targetPosition;
|
|
npc.targetPosition = Vector{};
|
|
npc.v1.x = 0;
|
|
npc.ClearChild();
|
|
if (is_imp(npc)) npc_sound_play(SOUND_IMP_WARP_IN, 1, 2, 1);
|
|
return;
|
|
}
|
|
if (npc_anim_is_done(npc) && vector_is_zero(npc.targetPosition)) npc.state = NPC_STATE_MOVE;
|
|
}
|
|
|
|
// The Imp's volley: a shot every 10 frames at its target's lead (controlled, at its aim mark), then a rest.
|
|
static void imp_attack_update(Entity_NPC& npc, int ticks)
|
|
{
|
|
npc.SpawnControlTarget(0, -1);
|
|
for (; ticks > 0; ticks--)
|
|
{
|
|
if (npc.projectileCooldown < 1)
|
|
{
|
|
npc.state = NPC_STATE_MOVE;
|
|
npc.projectileDelay = IMP_REST;
|
|
return;
|
|
}
|
|
if (--npc.projectileCooldown % IMP_SHOT_SPACING != 0) continue;
|
|
|
|
npc_anim_restart(npc.sprite, "Attack");
|
|
Entity& target = *npc.GetPlayerTarget();
|
|
Vector aim = vector_add(target.pos, vector_scale(target.velocity, IMP_SHOT_LEAD));
|
|
if (npc.controllerID != -1) aim = npc.aimTargetEffect.get() ? npc.aimTargetEffect->pos : npc.pos;
|
|
ProjectileParams params;
|
|
npc.FireProjectiles(npc.pos, vector_scale(vector_normalized(vector_sub(aim, npc.pos)), IMP_SHOT_SPEED),
|
|
PROJECTILES_SINGLE, params);
|
|
if (is_imp(npc)) npc_sound_play(SOUND_IMP_SHOOT, 1, 2, 1);
|
|
}
|
|
}
|
|
|
|
// The Imp sidesteps the player's tears within 100, more the further its target is.
|
|
static void imp_dodge(Entity_NPC& npc, float targetDistanceSquared)
|
|
{
|
|
std::vector<Entity*> tears = entity_query_radius(npc.pos, IMP_DODGE_RADIUS, QUERY_TEARS);
|
|
if (tears.empty()) return;
|
|
|
|
float urgency = std::clamp(targetDistanceSquared, 0.0f, IMP_DODGE_REACH_SQUARED) / IMP_DODGE_REACH_SQUARED;
|
|
Vector dodge{};
|
|
int count = 0;
|
|
for (Entity* tear : tears)
|
|
{
|
|
Vector away = vector_sub(npc.pos, tear->pos);
|
|
if (vector_dot(away, tear->velocity) <= 0) continue;
|
|
|
|
float falloff = 1 - vector_length_squared(away) / IMP_DODGE_REACH_SQUARED;
|
|
Vector side = vector_make(tear->velocity.y, -tear->velocity.x);
|
|
if (vector_dot(away, side) < 0) side = vector_scale(side, -1);
|
|
float push = (random_unit() * 2 + IMP_DODGE_MIN) * falloff * urgency;
|
|
dodge = vector_add(dodge, vector_resized(side, push));
|
|
count++;
|
|
}
|
|
if (count > 0) npc.velocity = vector_add(npc.velocity, vector_scale(dodge, npc.speedMultiplier / (float)count));
|
|
}
|
|
|
|
// A controlled Imp dashes while its action is held, slowing as its charge fills, and recharges once released.
|
|
static void imp_dash(Entity_NPC& npc, Vector toTarget)
|
|
{
|
|
if (!npc.IsControllerActionPressed(CONTROL_ACTION_DASH))
|
|
{
|
|
if (npc.v2.x > 0) npc.v2.x = -1;
|
|
return;
|
|
}
|
|
if (npc.v2.x < 0) return;
|
|
|
|
npc.v2.x = std::min(npc.speedMultiplier * IMP_CHARGE_RATE + npc.v2.x, 1.0f);
|
|
npc_push(npc, vector_scale(vector_normalized(toTarget), IMP_CHARGE_PUSH * (1 - npc.v2.x)));
|
|
}
|
|
|
|
// 0052ae30 The baby (38) and the Imp (259): drifting, shooting and blinking about, the Wrinkly Baby apart.
|
|
void npc_baby_update(Entity_NPC& npc)
|
|
{
|
|
if (npc.type == ENTITY_BABY && npc.variant == BABY_WRINKLY) return npc_wrinkly_baby_update(npc);
|
|
if (npc.state == NPC_STATE_INIT)
|
|
{
|
|
npc.sprite.Play("Move");
|
|
npc.state = NPC_STATE_MOVE;
|
|
return;
|
|
}
|
|
|
|
int ticks = npc_ticks_get(npc);
|
|
grid_path_claim(npc.pos);
|
|
npc.friction *= BABY_FRICTION;
|
|
Vector toTarget = vector_sub(npc.CalcTargetPosition(0), npc.pos);
|
|
if (npc.controllerID != -1) toTarget = vector_scale(npc.GetControllerInput(0), BABY_CONTROL_REACH);
|
|
|
|
switch (npc.state)
|
|
{
|
|
case NPC_STATE_MOVE:
|
|
baby_wander_update(npc, ticks, toTarget);
|
|
break;
|
|
case NPC_STATE_JUMP:
|
|
baby_blink_update(npc);
|
|
break;
|
|
case NPC_STATE_ATTACK:
|
|
imp_attack_update(npc, ticks);
|
|
break;
|
|
}
|
|
|
|
if (is_imp(npc) && npc.v2.x < 0) npc.v2.x = std::min(npc.speedMultiplier * IMP_RECHARGE_RATE + npc.v2.x, 0.0f);
|
|
if (npc.projectileCooldown < 1)
|
|
{
|
|
npc_push(npc, vector_scale(vector_normalized(toTarget), BABY_DRIFT));
|
|
if (is_imp(npc) && npc.controllerID == -1) imp_dodge(npc, vector_length_squared(toTarget));
|
|
else if (is_imp(npc)) imp_dash(npc, toTarget);
|
|
}
|
|
else if (npc.controllerID != -1) npc_push(npc, vector_scale(vector_normalized(toTarget), BABY_CONTROLLED_DRIFT));
|
|
npc.stateFrame += ticks;
|
|
}
|
|
|
|
// The flies Isaac's summons hold around him: a Pooter 85 out and turned back, an attack fly or Moter 55 out and turned
|
|
// ahead, both easing toward their spot at 6 or 8. With no Isaac left they turn into plain flies.
|
|
constexpr float ORBIT_REACH = 100;
|
|
constexpr float ORBIT_REACH_POOTER = 85;
|
|
constexpr float ORBIT_REACH_FLY = 55;
|
|
constexpr float ISAAC_ORBIT_TURN = 20;
|
|
constexpr float ISAAC_ORBIT_SPEED = 10;
|
|
constexpr float ORBIT_SPEED_POOTER = 6;
|
|
constexpr float ORBIT_SPEED_FLY = 8;
|
|
constexpr float ISAAC_ORBIT_EASE = 0.39999998f;
|
|
|
|
// 004568d0 A fly Isaac summoned circles the nearest Isaac, or becomes a plain fly once none is left.
|
|
void npc_isaac_fly_update(Entity_NPC& npc)
|
|
{
|
|
std::vector<Entity*> isaacs = entity_query(ENTITY_ISAAC_BOSS, -1);
|
|
if (isaacs.empty())
|
|
{
|
|
npc.spawnerType = 0;
|
|
npc.subtype = 0;
|
|
npc.entityGridCollisionClass = GRIDCOLL_WALLS;
|
|
return;
|
|
}
|
|
|
|
Vector center = isaacs.front()->pos;
|
|
Vector offset = vector_sub(center, npc.pos);
|
|
Vector toward = vector_normalized(offset);
|
|
Vector around = vector_make(-offset.x, -offset.y);
|
|
float reach = ORBIT_REACH;
|
|
float speed = ISAAC_ORBIT_SPEED;
|
|
if (npc.subtype == SUMMON_SUBTYPE_POOTER || npc.subtype == SUMMON_SUBTYPE)
|
|
{
|
|
bool isPooter = npc.subtype == SUMMON_SUBTYPE_POOTER;
|
|
float turn = isPooter ? -ISAAC_ORBIT_TURN : ISAAC_ORBIT_TURN;
|
|
around = vector_make(around.x + toward.y * turn, around.y - toward.x * turn);
|
|
reach = isPooter ? ORBIT_REACH_POOTER : ORBIT_REACH_FLY;
|
|
speed = isPooter ? ORBIT_SPEED_POOTER : ORBIT_SPEED_FLY;
|
|
}
|
|
npc.targetPosition = vector_add(center, vector_resized(around, reach));
|
|
|
|
Vector step = vector_sub(npc.targetPosition, npc.pos);
|
|
if (vector_length(step) > speed) step = vector_resized(step, speed);
|
|
float ease = 1 - timescale_factor(ISAAC_ORBIT_EASE, npc.speedMultiplier);
|
|
npc.velocity = vector_make(npc.velocity.x + (step.x - npc.velocity.x) * ease,
|
|
npc.velocity.y + (step.y - npc.velocity.y) * ease);
|
|
npc.entityGridCollisionClass = GRIDCOLL_NONE;
|
|
}
|