Files
isaac-port/src/grid_entity_web.cpp
T

78 lines
2.8 KiB
C++

#include "grid_entity_web.h"
#include "entity_player.h"
#include "game.h"
#include <algorithm>
#include <cmath>
// How often a web slows the players in it, how near they must be, and how much and how long it slows them, tinted
// blue. A web turns in quarter turns.
constexpr int WEB_CHECK_FRAMES = 4;
constexpr float WEB_REACH = 21;
constexpr int WEB_SLOW_FRAMES = 4;
constexpr float WEB_SLOW = 0.75f;
constexpr ColorMod WEB_SLOW_COLOR = {{1, 1, 1.3f, 1}, {0, 0, 0, 0}, {0.15686275f, 0.15686275f, 0.15686275f}};
constexpr uint32_t WEB_TURNS = 3;
constexpr float WEB_TURN_DEGREES = 90;
// 00721540 Loads the web, burnt on its first bombed frame or swaying from a random frame, flipped and turned at
// random.
void GridEntity_Web::subclass_init()
{
collisionClass = COLLISION_NONE;
sprite.Load("gfx/grid/grid_web.anm2", GRAPHICS_LOAD);
if (state != WEB_STATE_STANDING) return sprite.SetFrame("Bombed", 0);
sprite.Play("Swaying");
const AnimationData* data = sprite.animState.animData;
int length = data ? data->length : 0;
int frame = length == 0 ? 0 : (int)(Random() % (uint32_t)length);
if (sprite.animState.animData)
{
sprite.animState.SetFrameFloat((float)frame);
sprite.animState.isPlaying = false;
}
sprite.isFlipX = (Random() & 1) == 0;
sprite.rotation = (float)(Random() & WEB_TURNS) * WEB_TURN_DEGREES;
}
// 00721780 Every fourth frame slows the walking players in a standing web (but not with Evil Charm), tinted blue.
void GridEntity_Web::Update()
{
if (state == WEB_STATE_STANDING && g_game->frameCount % WEB_CHECK_FRAMES == 0)
{
Vector position = Position();
for (Entity_Player* player : g_game->playerManager.playerList)
{
if (player->entityGridCollisionClass <= GRIDCOLL_WALLS) continue;
bool isCharmed = player->HasCollectible(COLLECTIBLE_EVIL_CHARM) ||
player->temporaryEffects.HasCollectibleEffect(COLLECTIBLE_EVIL_CHARM);
if (isCharmed && type == GRID_SPIDERWEB) continue;
float reach = std::max(std::abs(player->pos.y - position.y), std::abs(player->pos.x - position.x));
if (reach < WEB_REACH) player->AddSlowing(EntityRef(), WEB_SLOW_FRAMES, WEB_SLOW, WEB_SLOW_COLOR, false);
}
}
sprite.Update();
}
// 00721a10 Burns a standing web away, stopped on its first bombed frame.
bool GridEntity_Web::Destroy(bool, const EntityRef&)
{
if (state != WEB_STATE_STANDING)
return false;
state = WEB_STATE_BOMBED;
if (sprite.SetAnimation("Bombed") && sprite.animState.animData)
{
sprite.animState.SetFrameFloat(0);
sprite.animState.isPlaying = false;
}
return true;
}
// 00714750 Water lies flat over the web.
WaterClipInfo GridEntity_Web::GetWaterClipInfo()
{
return {WATER_CLIP_FLAT, 0};
}