Curation round 13: grid entities, more enemies, Caves, boss helpers and five bosses, chests and costumes, curses and alt stages, the Lua API
This commit is contained in:
1 parent
f8ce24fc6c
commit
8ae02a8422
160 files changed
+16231
-1689
No files matched your search
@@ -0,0 +1,111 @@
|
||||
#include "npc_basement.h"
|
||||
#include "boss_ai.h"
|
||||
#include "entity_player.h"
|
||||
#include "score_sheet.h"
|
||||
|
||||
// A ring of flies circles its leader's spot 40 to 70 out, breathing by 0.5 a frame, turning with the ring's speed. The
|
||||
// leader's spot drifts at 2 toward its target (2.5 along its controller's input).
|
||||
constexpr float RING_FLY_RADIUS_MIN = 40;
|
||||
constexpr float RING_FLY_RADIUS_MAX = 70;
|
||||
constexpr float RING_FLY_BREATH = 0.5f;
|
||||
constexpr float RING_FLY_TURN = 0.09424778f;
|
||||
constexpr float RING_FLY_DRIFT = 2;
|
||||
constexpr float RING_FLY_STEER = 2.5f;
|
||||
constexpr float RING_FLY_SNAP_SQUARED = 100;
|
||||
constexpr float RING_FLY_SPEED = 6;
|
||||
constexpr float RING_FLY_REGEN = 4;
|
||||
|
||||
// Lord of the Flies takes a fly as a blue fly of its own. Whether it did.
|
||||
bool npc_fly_beelzebub_take(Entity_NPC& npc)
|
||||
{
|
||||
Entity_Player* beelzebub = g_game->playerManager.GetRandomPlayer(npc.initSeed);
|
||||
if (!beelzebub || npc.isDead) return false;
|
||||
|
||||
g_game->scoreSheet.AddKilledEnemy(npc);
|
||||
npc.Remove();
|
||||
beelzebub->AddBlueFlies(1, npc.pos, nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
// The leader moves the ring's spot, breathes its radius and turns it, by the ring's average speed.
|
||||
static void ring_fly_lead(Entity_NPC& npc, const Vector& toward, float ringSpeed)
|
||||
{
|
||||
Vector drift = npc.controllerID == -1 ? vector_scale(vector_normalized(toward), RING_FLY_DRIFT)
|
||||
: vector_scale(npc.GetControllerInput(0), RING_FLY_STEER);
|
||||
npc.targetPosition = vector_add(npc.targetPosition, vector_scale(drift, npc.speedMultiplier));
|
||||
|
||||
if (npc.i1 == 0)
|
||||
{
|
||||
npc.v1.y -= RING_FLY_BREATH;
|
||||
if (npc.v1.y < RING_FLY_RADIUS_MIN) npc.i1 = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
npc.v1.y += RING_FLY_BREATH;
|
||||
if (npc.v1.y > RING_FLY_RADIUS_MAX) npc.i1 = 0;
|
||||
}
|
||||
|
||||
npc.v2.x -= ringSpeed * RING_FLY_TURN;
|
||||
while (npc.v2.x < -PI_F) npc.v2.x += PI_F * 2;
|
||||
}
|
||||
|
||||
// 0053bae0 The ring of flies' AI: Lord of the Flies takes it and Skatole tames it. The flies of a ring share the first
|
||||
// one's spot and take their places evenly around it, the leader drifting toward the target.
|
||||
void npc_ring_fly_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc_fly_beelzebub_take(npc)) return;
|
||||
if (g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_SKATOLE, LAZARUS_SHARE_CHECK) && !npc.IsFriendly())
|
||||
{
|
||||
npc.Morph(ENTITY_FLY, 0, 0, -1);
|
||||
npc.v2 = {};
|
||||
npc.v1 = {};
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<Entity*> ring = entity_query(ENTITY_RING_OF_FLIES, -1);
|
||||
if (!npc.parent && !ring.empty()) npc.parent = ring.front();
|
||||
if (npc.subtype == 1 && npc.health > npc.maxHitPoints)
|
||||
npc.health = std::max(npc.health - RING_FLY_REGEN, npc.maxHitPoints);
|
||||
|
||||
if (npc.state == NPC_STATE_INIT)
|
||||
{
|
||||
npc.entityGridCollisionClass = GRIDCOLL_NONE;
|
||||
npc.targetPosition = npc.parent.get() == &npc ? npc.pos : npc.parent->targetPosition;
|
||||
npc.i1 = 1;
|
||||
npc.v1.y = RING_FLY_RADIUS_MIN;
|
||||
npc.state = NPC_STATE_MOVE;
|
||||
return;
|
||||
}
|
||||
if (npc.state != NPC_STATE_MOVE) return;
|
||||
|
||||
if (!npc.sprite.IsPlaying()) npc.sprite.Play("Fly");
|
||||
Vector toward = vector_sub(npc.CalcTargetPosition(0), npc.pos);
|
||||
|
||||
int ringSize = 0;
|
||||
int slot = 0;
|
||||
float ringSpeed = 0;
|
||||
for (Entity* fly : ring)
|
||||
{
|
||||
if (fly == &npc) slot = ringSize;
|
||||
if (fly->parent.get() != npc.parent.get()) continue;
|
||||
ringSpeed += fly->speedMultiplier;
|
||||
ringSize++;
|
||||
}
|
||||
if (ringSize > 0) ringSpeed /= (float)ringSize;
|
||||
|
||||
if (npc.parent.get() == &npc) ring_fly_lead(npc, toward, ringSpeed);
|
||||
else if (npc.parent)
|
||||
{
|
||||
npc.targetPosition = npc.parent->targetPosition;
|
||||
npc.v1.y = npc.ParentNPC()->v1.y;
|
||||
npc.v2.x = npc.ParentNPC()->v2.x;
|
||||
}
|
||||
|
||||
npc.v1.x = (float)slot * PI_F * 2 / (float)ringSize;
|
||||
float angle = npc.v1.x + npc.v2.x;
|
||||
Vector place = vector_make(std::cos(angle) * npc.v1.y, std::sin(angle) * npc.v1.y);
|
||||
Vector step = vector_sub(vector_add(npc.targetPosition, place), npc.pos);
|
||||
if (vector_length_squared(step) > RING_FLY_SNAP_SQUARED)
|
||||
step = vector_scale(vector_normalized(step), RING_FLY_SPEED);
|
||||
npc.velocity = step;
|
||||
}
|
||||
Reference in new issue
Block a user