1299 lines
55 KiB
C++
1299 lines
55 KiB
C++
#include "entity_effect_combat.h"
|
|
#include "entity_bomb.h"
|
|
#include "entity_player.h"
|
|
#include "fx_layers.h"
|
|
#include "game.h"
|
|
#include "grid_entity_rock.h"
|
|
#include "manager.h"
|
|
#include "npc_ai.h"
|
|
#include "room.h"
|
|
#include "sfx_manager.h"
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <cmath>
|
|
|
|
// The effect variants this file runs (Lua's EffectVariant).
|
|
enum class CombatEffect : int
|
|
{
|
|
BOMB_EXPLOSION = 1,
|
|
BLOOD_EXPLOSION = 2,
|
|
FLY_EXPLOSION = 3,
|
|
ROCK_PARTICLE = 4,
|
|
BLOOD_PARTICLE = 5,
|
|
BLOOD_SPLAT = 7,
|
|
BULLET_POOF = 11,
|
|
TEAR_POOF_A = 12,
|
|
TEAR_POOF_B = 13,
|
|
RIPPLE_POOF = 14,
|
|
POOF01 = 15,
|
|
POOF02 = 16,
|
|
POOF04 = 17,
|
|
BOMB_CRATER = 18,
|
|
WOOD_PARTICLE = 27,
|
|
TOOTH_PARTICLE = 35,
|
|
SPIDER_EXPLOSION = 38,
|
|
BLOOD_GUSH = 42,
|
|
POOP_EXPLOSION = 43,
|
|
BATTERY = 48,
|
|
HEART = 49,
|
|
POOP_PARTICLE = 58,
|
|
DUST_CLOUD = 59,
|
|
ROCK_EXPLOSION = 62,
|
|
WORM = 63,
|
|
BLOOD_DROP = 70,
|
|
LARGE_BLOOD_EXPLOSION = 77,
|
|
TEAR_POOF_SMALL = 79,
|
|
TEAR_POOF_VERYSMALL = 80,
|
|
DIAMOND_PARTICLE = 85,
|
|
NAIL_PARTICLE = 86,
|
|
GOLD_PARTICLE = 95,
|
|
IMPACT = 97,
|
|
COIN_PARTICLE = 98,
|
|
CHAIN_GIB = 163
|
|
};
|
|
|
|
constexpr std::array<CombatEffect, 35> COMBAT_EFFECTS = {
|
|
CombatEffect::BOMB_EXPLOSION, CombatEffect::BLOOD_EXPLOSION, CombatEffect::FLY_EXPLOSION,
|
|
CombatEffect::ROCK_PARTICLE, CombatEffect::BLOOD_PARTICLE, CombatEffect::BLOOD_SPLAT,
|
|
CombatEffect::BULLET_POOF, CombatEffect::TEAR_POOF_A, CombatEffect::TEAR_POOF_B,
|
|
CombatEffect::RIPPLE_POOF, CombatEffect::POOF01, CombatEffect::POOF02,
|
|
CombatEffect::POOF04, CombatEffect::BOMB_CRATER, CombatEffect::WOOD_PARTICLE,
|
|
CombatEffect::TOOTH_PARTICLE, CombatEffect::SPIDER_EXPLOSION, CombatEffect::BLOOD_GUSH,
|
|
CombatEffect::POOP_EXPLOSION, CombatEffect::BATTERY, CombatEffect::HEART,
|
|
CombatEffect::POOP_PARTICLE, CombatEffect::DUST_CLOUD, CombatEffect::ROCK_EXPLOSION,
|
|
CombatEffect::WORM, CombatEffect::BLOOD_DROP, CombatEffect::LARGE_BLOOD_EXPLOSION,
|
|
CombatEffect::TEAR_POOF_SMALL, CombatEffect::TEAR_POOF_VERYSMALL, CombatEffect::DIAMOND_PARTICLE,
|
|
CombatEffect::NAIL_PARTICLE, CombatEffect::GOLD_PARTICLE, CombatEffect::IMPACT,
|
|
CombatEffect::COIN_PARTICLE, CombatEffect::CHAIN_GIB};
|
|
|
|
// The particles that play a gib animation and go once it ends.
|
|
constexpr std::array<CombatEffect, 5> ANIMATED_PARTICLES = {
|
|
CombatEffect::TOOTH_PARTICLE, CombatEffect::DIAMOND_PARTICLE, CombatEffect::NAIL_PARTICLE,
|
|
CombatEffect::GOLD_PARTICLE, CombatEffect::COIN_PARTICLE};
|
|
|
|
// The animations by subtype or at random.
|
|
constexpr std::array<const char*, 6> BLOOD_EXPLOSION_ANIMATIONS = {"Poof_Large", "Poof_Small", "Poof",
|
|
"Poof_Large1", "Poof_Large2", "Poof_Alt"};
|
|
constexpr std::array<const char*, 4> POOF01_ANIMATIONS = {"Poof2", "Poof_Small", "Poof", "Poof_Large"};
|
|
constexpr std::array<const char*, 3> LAVA_SPLASH_ANIMATIONS = {"Poof0", "Poof1", "Poof2"};
|
|
constexpr std::array<const char*, 6> NOTIFY_ANIMATIONS = {"Heart", "Battery", "Betrayal",
|
|
"BatteryDown", "SoulHeart", "BlackHeart"};
|
|
constexpr std::array<const char*, 4> GIB_FRAMES = {"Gib1", "Gib2", "Gib3", "Gib4"};
|
|
constexpr std::array<const char*, 5> GIB_ANIMATIONS = {"Gib01", "Gib02", "Gib03", "Gib04", "Gib05"};
|
|
constexpr std::array<const char*, 3> BLOOD_GIBS = {"BloodGib01", "BloodGib02", "BloodGib03"};
|
|
constexpr std::array<const char*, 2> BONES = {"Bone02", "Bone01"};
|
|
constexpr std::array<const char*, 3> GUTS = {"Guts01", "Guts02", "Liver"};
|
|
constexpr std::array<const char*, 3> FLESH_BREAKS = {"WombBreak1", "WombBreak2", "WombBreak3"};
|
|
constexpr std::array<const char*, 3> WORM_ANIMATIONS = {"WormHori", "MaggotHori", "LeechHori"};
|
|
constexpr std::array<const char*, 6> STAIN_ANIMATIONS = {"Size1BloodStains", "Size2BloodStains", "Size3BloodStains",
|
|
"Size4BloodStains", "Size5BloodStains", "Size6BloodStains"};
|
|
|
|
// The blood stain animation by the scale it was spawned at: the first whose limit is above it, the last past all.
|
|
constexpr std::array<float, 5> STAIN_SCALE_LIMITS = {0.4f, 0.6f, 0.8f, 1.2f, 2.0f};
|
|
|
|
// The blood particle's kinds by subtype.
|
|
enum BloodParticle : int
|
|
{
|
|
BLOOD_PARTICLE_BLOOD,
|
|
BLOOD_PARTICLE_BONE,
|
|
BLOOD_PARTICLE_GUTS,
|
|
BLOOD_PARTICLE_EYE,
|
|
BLOOD_PARTICLE_GIB = 5
|
|
};
|
|
|
|
// The states the falling particles pass: falling to stay, falling to bounce, bounced, sinking into a pit, glowing.
|
|
enum ParticleState : int
|
|
{
|
|
PARTICLE_FALLING = 1,
|
|
PARTICLE_BOUNCING = 2,
|
|
PARTICLE_BOUNCED = 3,
|
|
PARTICLE_SINKING = 10,
|
|
PARTICLE_GLOWING = 1000
|
|
};
|
|
|
|
// A rock particle's subtype: the backdrop whose rocks it shows in its low bits (none for the rock under it), and
|
|
// whether it shows the alternate rubble and bounces. Subtype 1 makes the other particles bounce, mostly.
|
|
constexpr int ROCK_PARTICLE_BACKDROP_MASK = 0xffff;
|
|
constexpr int ROCK_PARTICLE_ALT = 0x10000;
|
|
|
|
constexpr int PARTICLE_BOUNCY = 1;
|
|
constexpr int PARTICLE_STILL_ODDS = 40;
|
|
|
|
// How the falling particles start and fall: their height, rise, gravity, the time scale's drag, and the bounce.
|
|
constexpr float PARTICLE_START_HEIGHT = -23;
|
|
constexpr float PARTICLE_RISE = -5;
|
|
constexpr float PARTICLE_RISE_RANGE = 10;
|
|
constexpr float GIB_FALL = 5;
|
|
constexpr float GIB_RISE_RANGE = 30;
|
|
constexpr float PARTICLE_GRAVITY = 1.3f;
|
|
constexpr float PARTICLE_GROUND_HEIGHT = -5;
|
|
constexpr float PARTICLE_FALL_DRAG = 0.9f;
|
|
constexpr float PARTICLE_FALL_PULL = 0.1f;
|
|
constexpr float PARTICLE_BOUNCE = -0.4f;
|
|
constexpr float PARTICLE_BOUNCE_SLOWDOWN = 0.6f;
|
|
constexpr float PARTICLE_ROOM_MARGIN = 5;
|
|
constexpr float PARTICLE_ROOM_PULL_SQUARED = 100;
|
|
constexpr int PARTICLE_FLOOR_Z = 90;
|
|
constexpr int PARTICLE_SHRINK_DELAY = 10;
|
|
constexpr float PARTICLE_SHRINK = 0.05f;
|
|
constexpr float PARTICLE_SINK_SHRINK = 0.15f;
|
|
constexpr float PARTICLE_SINK_FADE = 0.8f;
|
|
|
|
// A crawlspace's side view: the particles drop past the room's bottom.
|
|
constexpr float CRAWLSPACE_HEIGHT = -100;
|
|
constexpr float CRAWLSPACE_GRAVITY = 0.7f;
|
|
constexpr float CRAWLSPACE_FLOOR_MARGIN = 80;
|
|
|
|
// The blood particle: its drops, the splats and drops it leaves in the air, and the gore it trails in a crawlspace.
|
|
constexpr int BLOOD_DROP_FRAMES = 13;
|
|
constexpr int BLOOD_DROP_GONE_FIRST = 4;
|
|
constexpr int BLOOD_DROP_GONE_LAST = 10;
|
|
constexpr float BLOOD_DROP_RISE_RANGE = 20;
|
|
constexpr int BLOOD_SPLAT_ODDS = 3;
|
|
constexpr float BLOOD_SPLAT_SCALE_MIN = 0.1f;
|
|
constexpr float BLOOD_SPLAT_SCALE_RANGE = 0.3f;
|
|
constexpr int BLOOD_DRIP_FIRST_STATE = 2;
|
|
constexpr int BLOOD_DRIP_LAST_STATE = 4;
|
|
constexpr float BLOOD_DRIP_SPEED = 5;
|
|
constexpr int PARTICLE_GLOW_FRAMES = 15;
|
|
constexpr uint32_t GORE_SPIN_SHIFT = 35;
|
|
constexpr float GORE_SPIN_MIN = 10;
|
|
constexpr float GORE_SPIN_RANGE = 40;
|
|
constexpr int GORE_TRAIL_FRAMES = 4;
|
|
constexpr int GORE_TRAIL_ODDS = 3;
|
|
constexpr int GORE_TRAIL_SUBTYPE = 4;
|
|
constexpr float GORE_TRAIL_SPEED = 0.4f;
|
|
|
|
// How a glowing stain fades: toward these colors, its alpha from full to half.
|
|
constexpr ColorMod PARTICLE_GLOW_FADE = {{0.8f, 0.8f, 0.8f, 1}, {1, 1, 1, 1}, {0.08f, 0.08f, 0.08f}};
|
|
constexpr ColorMod STAIN_GLOW_FADE = {{0.2f, 1, 1, 1}, {0, 0, 0, 0}, {0.08f, 0.08f, 0.08f}};
|
|
constexpr float GLOW_ALPHA_MIN = 0.5f;
|
|
|
|
// The blood stain: its alpha steps, and a glowing one's time and the light it gives.
|
|
constexpr float STAIN_ALPHA_MIN = 0.5f;
|
|
constexpr float STAIN_ALPHA_STEP = 0.1f;
|
|
constexpr int STAIN_ALPHA_STEPS = 6;
|
|
constexpr int STAIN_GLOW_FRAMES = 30;
|
|
constexpr int STAIN_LIGHT_LEAD = 10;
|
|
constexpr float STAIN_LIGHT_SCALE = 0.6f;
|
|
constexpr float STAIN_LIGHT_BOOST = 1.1f;
|
|
constexpr float STAIN_LIGHT_RED = 103;
|
|
constexpr float STAIN_LIGHT_GREEN = 10;
|
|
constexpr float STAIN_LIGHT_BLUE = 11;
|
|
|
|
// One world unit is 0.65 screen pixels. A glowing stain sits on whole pixels.
|
|
constexpr float WORLD_PER_PIXEL = 1.5384616f;
|
|
|
|
// The tear poofs' quarter turns, the ripple's small sizes and the poofs' layers.
|
|
constexpr float RIPPLE_TINY_SCALE = 0.5f;
|
|
constexpr float RIPPLE_SMALL_SCALE = 0.75f;
|
|
constexpr float RIPPLE_TINY_GROWTH = 2;
|
|
constexpr float RIPPLE_SMALL_GROWTH = 1.33333f;
|
|
constexpr int POOF_RENDER_Z = 8000;
|
|
constexpr int POOF01_GFUEL = 11;
|
|
constexpr int POOF01_REPEATING = 100;
|
|
constexpr uint32_t LAVA_SPLASH_SHIFT = 4;
|
|
constexpr int GFUEL_SHAKE = 40;
|
|
constexpr float GFUEL_PITCH_MIN = 0.9f;
|
|
constexpr float GFUEL_PITCH_RANGE = 0.2f;
|
|
|
|
// The blood explosion's floor frame, from 6 to 8, from which it stays on the floor.
|
|
constexpr int BLOOD_EXPLOSION_FLOOR_FRAME = 6;
|
|
constexpr int BLOOD_EXPLOSION_FLOOR_RANGE = 3;
|
|
|
|
// The bomb explosion's sound by the size it was spawned at, and the spawners that play their own.
|
|
constexpr float EXPLOSION_SMALL_SCALE = 0.7f;
|
|
constexpr float EXPLOSION_LARGE_SCALE = 1.4f;
|
|
constexpr float EXPLOSION_SMALL_VOLUME = 0.95f;
|
|
constexpr float EXPLOSION_LARGE_VOLUME = 1.1f;
|
|
constexpr int ENTITY_DUKE_OF_FLIES = 67;
|
|
constexpr const char* GFUEL_EXPLOSION_ANM2 = "gfx/promo/gfuel/effects/explosion3.anm2";
|
|
constexpr float SCISSORS_SCALE_DOUBLE = 0.75f;
|
|
constexpr float SCISSORS_SCALE_TRIPLE = 0.5f;
|
|
|
|
// The bomb crater: its small kind, the darker one in the Dark Room, and a temporary one's fade.
|
|
constexpr float CRATER_SMALL_SCALE = 0.5f;
|
|
constexpr float CRATER_SMALL_GROWTH = 2;
|
|
constexpr uint32_t CRATER_FRAME_SHIFT = 35;
|
|
constexpr float CRATER_ALPHA_MIN = 0.8f;
|
|
constexpr float CRATER_ALPHA_RANGE = 0.2f;
|
|
constexpr float CRATER_DARK_TINT = 0.5f;
|
|
constexpr int CRATER_TEMPORARY = 1;
|
|
constexpr int CRATER_TEMPORARY_FRAMES = 150;
|
|
constexpr int CRATER_FADE_FRAMES = 60;
|
|
|
|
// The dust cloud's start and spread.
|
|
constexpr float DUST_SCALE = 0.5f;
|
|
constexpr float DUST_DARKEN = -0.5f;
|
|
constexpr int DUST_DARK = 1;
|
|
constexpr int DUST_PULSE = 2;
|
|
constexpr float DUST_FRICTION = 0.9f;
|
|
constexpr float DUST_GROWTH = 0.9f;
|
|
constexpr float DUST_PULSE_PEAK = 0.5f;
|
|
constexpr float DUST_PULSE_SHARPNESS = 4;
|
|
|
|
// The blood drop's fall and splat.
|
|
constexpr int DROPLET_KINDS = 3;
|
|
constexpr float DROPLET_SHADOW = 0.04f;
|
|
constexpr float DROPLET_FALL = 1;
|
|
constexpr float DROPLET_RISE_RANGE = 15;
|
|
constexpr float DROPLET_DRAG = 0.9f;
|
|
constexpr float DROPLET_FRICTION = 0.95f;
|
|
|
|
// A backdrop's ground break sheet, and whether it breaks like flesh with its own animations.
|
|
struct GroundBreak
|
|
{
|
|
const char* sheet;
|
|
int backdrop;
|
|
bool isFleshy;
|
|
};
|
|
|
|
constexpr const char* GROUND_BREAK_CAVES = "gfx/Effects/Effect_062_GroundBreakCaves.png";
|
|
constexpr const char* GROUND_BREAK_DEPTHS = "gfx/Effects/Effect_062_GroundBreakDepths.png";
|
|
constexpr const char* GROUND_BREAK_WOMB = "gfx/Effects/Effect_062_GroundBreakWomb.png";
|
|
constexpr const char* GROUND_BREAK_BLUE_WOMB = "gfx/Effects/Effect_062_GroundBreakBlueWomb.png";
|
|
constexpr const char* GROUND_BREAK_MINES = "gfx/Effects/Effect_062_GroundBreakMines.png";
|
|
constexpr const char* GROUND_BREAK_MINES_LAVA = "gfx/Effects/Effect_062_GroundBreakMinesLava.png";
|
|
constexpr const char* GROUND_BREAK_MAUSOLEUM = "gfx/Effects/Effect_062_GroundBreakMausoleum.png";
|
|
constexpr const char* GROUND_BREAK_CORPSE = "gfx/Effects/Effect_062_GroundBreakCorpse.png";
|
|
constexpr const char* GROUND_BREAK_CORPSE2 = "gfx/Effects/Effect_062_GroundBreakCorpse2.png";
|
|
constexpr std::array<GroundBreak, 17> GROUND_BREAKS = {{
|
|
{GROUND_BREAK_CAVES, 4, false}, {GROUND_BREAK_CAVES, 5, false}, {GROUND_BREAK_DEPTHS, 7, false},
|
|
{GROUND_BREAK_DEPTHS, 8, false}, {GROUND_BREAK_DEPTHS, 9, false}, {GROUND_BREAK_WOMB, 10, true},
|
|
{GROUND_BREAK_WOMB, 11, true}, {GROUND_BREAK_WOMB, 12, true}, {GROUND_BREAK_BLUE_WOMB, 13, true},
|
|
{GROUND_BREAK_MAUSOLEUM, 33, false}, {GROUND_BREAK_CORPSE, 34, true}, {GROUND_BREAK_MAUSOLEUM, 40, false},
|
|
{GROUND_BREAK_MAUSOLEUM, 41, false}, {GROUND_BREAK_MAUSOLEUM, 42, false}, {GROUND_BREAK_CORPSE2, 43, true},
|
|
{GROUND_BREAK_WOMB, 44, true}, {GROUND_BREAK_MINES_LAVA, 46, false}}};
|
|
|
|
// The rock explosion's sparks, and its glow over lava.
|
|
constexpr int ROCK_EXPLOSION_SPARK_FRAME = 1;
|
|
constexpr int ROCK_EXPLOSION_SPARK_ODDS = 5;
|
|
constexpr float ROCK_EXPLOSION_SPARK_SPEED = 5;
|
|
constexpr ColorMod LAVA_GLOW_COLOR = {{1, 0.6f, 0.2f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
constexpr int LAVA_GLOW_FRAMES = 22;
|
|
constexpr float LAVA_GLOW_SCALE = 0.5f;
|
|
|
|
constexpr int LIGHT_FADE_DEFAULT = 6;
|
|
|
|
// The worm: how it wanders, crawls, turns from walls and the nearest player, and dies under feet or tears.
|
|
constexpr float WORM_IDLE_WOBBLE = 5;
|
|
constexpr float WORM_CRAWL_WOBBLE = 20;
|
|
constexpr float WORM_FALL_DRAG = 0.9f;
|
|
constexpr float WORM_FRICTION = 0.9f;
|
|
constexpr float WORM_GROUND_FRICTION = 0.5f;
|
|
constexpr float WORM_SHADOW_HEIGHT = -20;
|
|
constexpr float WORM_SHADOW = 0.07f;
|
|
constexpr float WORM_INNER_MARGIN = -2;
|
|
constexpr float WORM_WALL_MARGIN = 40;
|
|
constexpr float WORM_WALL_TURN = 0.05f;
|
|
constexpr std::array<float, 3> WORM_PUSHES = {0.2f, 0.1f, 0.05f};
|
|
constexpr int WORM_CRAWL_ODDS = 30;
|
|
constexpr int WORM_CRAWL_RANGE = 120;
|
|
constexpr int WORM_CRAWL_MIN = 15;
|
|
constexpr int WORM_NUDGE_ODDS = 10;
|
|
constexpr float WORM_FLEE_RANGE_SQUARED = 10000;
|
|
constexpr int WORM_FLEE_ODDS = 3;
|
|
constexpr float WORM_FLEE_TURN = 0.2f;
|
|
constexpr float WORM_FLEE_PUSH = 4;
|
|
constexpr int WORM_FLEE_RANGE = 100;
|
|
constexpr int WORM_FLEE_MIN = 30;
|
|
constexpr float WORM_CELL_EDGE = 20;
|
|
constexpr float WORM_EDGE_SLOWDOWN = 0.1f;
|
|
constexpr float WORM_SPLAT_SCALE = 0.3f;
|
|
constexpr float WORM_STEP_RANGE_SQUARED = 100;
|
|
constexpr float WORM_STEP_SPEED_SQUARED = 1;
|
|
constexpr float WORM_TEAR_RANGE = 5;
|
|
constexpr float WORM_STILL_SPEED_SQUARED = 1;
|
|
|
|
constexpr float SPRITE_UP = 90;
|
|
|
|
static CombatEffect variant_get(const Entity_Effect& effect)
|
|
{
|
|
return static_cast<CombatEffect>(effect.variant);
|
|
}
|
|
|
|
template <size_t N>
|
|
static bool is_listed(const std::array<CombatEffect, N>& list, CombatEffect variant)
|
|
{
|
|
return std::find(list.begin(), list.end(), variant) != list.end();
|
|
}
|
|
|
|
bool is_combat_effect(int variant)
|
|
{
|
|
return is_listed(COMBAT_EFFECTS, static_cast<CombatEffect>(variant));
|
|
}
|
|
|
|
// normalize_angle_degrees 00682740: an angle wrapped into -180 to 180.
|
|
static float angle_wrap(float angle)
|
|
{
|
|
if (std::fabs(angle) > FULL_TURN_DEGREES) angle = std::fmod(angle, FULL_TURN_DEGREES);
|
|
if (angle > HALF_TURN_DEGREES) return angle - FULL_TURN_DEGREES;
|
|
if (angle < -HALF_TURN_DEGREES) return angle + FULL_TURN_DEGREES;
|
|
return angle;
|
|
}
|
|
|
|
// Plays a sound through the fart seeds.
|
|
static void sound_play(int sound, float volume, float pitch)
|
|
{
|
|
seed_fart_sound_override(&sound);
|
|
g_manager->sfxManager.Play(sound, {.volume = volume, .pitch = pitch});
|
|
}
|
|
|
|
// Spawns a still effect with no spawner or subtype on a fresh seed.
|
|
static Entity_Effect* effect_spawn(const Vector& position, int variant)
|
|
{
|
|
uint32_t seed = Random();
|
|
return static_cast<Entity_Effect*>(g_game->Spawn({position, {}, nullptr, 0, ENTITY_EFFECT, variant, seed}));
|
|
}
|
|
|
|
// Spawns a blood stain of a color under an effect.
|
|
static Entity_Effect* stain_spawn(const Entity_Effect& effect)
|
|
{
|
|
Entity_Effect* stain = effect_spawn(effect.pos, static_cast<int>(CombatEffect::BLOOD_SPLAT));
|
|
stain->SetColor(effect.splatColor, -1, 255, false, true);
|
|
return stain;
|
|
}
|
|
|
|
// Snaps a position onto whole screen pixels.
|
|
static Vector pixel_snap(Vector position)
|
|
{
|
|
return vector_make(std::floor(position.x / WORLD_PER_PIXEL + HALF) * WORLD_PER_PIXEL,
|
|
std::floor(position.y / WORLD_PER_PIXEL + HALF) * WORLD_PER_PIXEL);
|
|
}
|
|
|
|
// 00703330 Game::SpawnParticles: throws effects out at a speed in random directions, flattened to the floor's
|
|
// perspective, tinted, from a height unless it is PARTICLE_HEIGHT_KEPT.
|
|
void game_particles_spawn(const ParticleSpawn& spawn)
|
|
{
|
|
for (int i = 0; i < spawn.count; i++)
|
|
{
|
|
uint32_t seed = Random();
|
|
float angle = random_unit() * PI_ROUGH;
|
|
angle += angle;
|
|
Vector velocity = vector_make(std::cos(angle) * spawn.speed, std::sin(angle) * HALF * spawn.speed);
|
|
auto* particle = static_cast<Entity_Effect*>(
|
|
g_game->Spawn({spawn.position, velocity, nullptr, spawn.subType, ENTITY_EFFECT, spawn.variant, seed}));
|
|
|
|
particle->SetColor(spawn.color, -1, 255, false, true);
|
|
if (spawn.height != PARTICLE_HEIGHT_KEPT) particle->height = spawn.height;
|
|
if (g_game->roomTransition.is_active()) particle->AddEntityFlags(FLAG_TRANSITION_UPDATE);
|
|
particle->Update();
|
|
}
|
|
}
|
|
|
|
// 0060af70 Entity_Effect::CreateLight: a light of a color and size that lasts its timeout and fades over its fade
|
|
// frames, following its parent if it has one.
|
|
Entity_Effect* effect_light_create(const LightSpawn& light)
|
|
{
|
|
Entity_Effect* effect = effect_spawn(light.position, EFFECT_LIGHT);
|
|
ColorMod color = {{light.color._red, light.color._green, light.color._blue, light.color._alpha}, {}, {}};
|
|
|
|
effect->SetColor(color, -1, 255, false, true);
|
|
effect->SetTimeout(light.timeout > 0 ? light.timeout : -1);
|
|
effect->sprite.scale = vector_make(light.scale, light.scale);
|
|
effect->state = light.fadeFrames > 0 ? light.fadeFrames : LIGHT_FADE_DEFAULT;
|
|
if (light.parent) effect->FollowParent(light.parent);
|
|
return effect;
|
|
}
|
|
|
|
// Safety Scissors shrink an explosion no player set off: to three quarters with two, to half with three or more.
|
|
static void explosion_shrink(Entity_Effect& effect)
|
|
{
|
|
Entity* spawner = effect.spawnerEntity;
|
|
if (spawner && (spawner->type == ENTITY_PLAYER || spawner->GetPlayerAncestor())) return;
|
|
|
|
int multiplier = g_game->playerManager.GetTrinketMultiplier(TRINKET_SAFETY_SCISSORS);
|
|
if (multiplier < 2) return;
|
|
float shrink = multiplier == 2 ? SCISSORS_SCALE_DOUBLE : SCISSORS_SCALE_TRIPLE;
|
|
effect.sprite.scale = vector_scale(effect.sprite.scale, shrink);
|
|
}
|
|
|
|
// A falling particle 23 high and rising, on a random gib frame or animation by its kind.
|
|
static void particle_init(Entity_Effect& effect)
|
|
{
|
|
CombatEffect variant = variant_get(effect);
|
|
|
|
effect.fallingAcceleration = PARTICLE_GRAVITY;
|
|
effect.height = PARTICLE_START_HEIGHT;
|
|
effect.posOffset.y = PARTICLE_START_HEIGHT;
|
|
effect.fallingSpeed = PARTICLE_RISE - random_unit() * PARTICLE_RISE_RANGE;
|
|
if (variant == CombatEffect::WOOD_PARTICLE || variant == CombatEffect::CHAIN_GIB)
|
|
effect.sprite.SetFrame(GIB_FRAMES[Random() & 3], 0);
|
|
if (!is_listed(ANIMATED_PARTICLES, variant)) return;
|
|
|
|
const char* animation = GIB_ANIMATIONS[Random() & 3];
|
|
bool isStill = Random() % 3 == 0 && variant != CombatEffect::DIAMOND_PARTICLE;
|
|
if (isStill) effect.sprite.SetFrame(animation, 0);
|
|
else effect.sprite.Play(animation);
|
|
}
|
|
|
|
// A poop particle 23 high and rising, turned and on a random gib animation.
|
|
static void poop_particle_init(Entity_Effect& effect)
|
|
{
|
|
effect.fallingAcceleration = PARTICLE_GRAVITY;
|
|
effect.height = PARTICLE_START_HEIGHT;
|
|
effect.sprite.GetLayer(0)->rotation = random_unit() * FULL_TURN_DEGREES;
|
|
effect.sprite.Play(GIB_ANIMATIONS[Random() % GIB_ANIMATIONS.size()]);
|
|
effect.fallingSpeed = GIB_FALL - random_unit() * GIB_RISE_RANGE;
|
|
}
|
|
|
|
// A poof's animation by its subtype. POOF01 and POOF02's large kinds draw over everything, POOF02's small kinds lie
|
|
// on the floor outside a crawlspace, and its lava splashes face a seeded side.
|
|
static void poof_init(Entity_Effect& effect)
|
|
{
|
|
int subtype = effect.subtype;
|
|
|
|
if (variant_get(effect) == CombatEffect::POOF01)
|
|
{
|
|
if (subtype >= 1 && subtype < (int)POOF01_ANIMATIONS.size()) effect.sprite.Play(POOF01_ANIMATIONS[subtype]);
|
|
effect.renderZOffset = POOF_RENDER_Z;
|
|
return;
|
|
}
|
|
|
|
if (subtype == 1 || subtype == 3)
|
|
{
|
|
if (g_game->room->roomType != ROOM_DUNGEON) effect.sortingLayer = SORTING_BACKGROUND;
|
|
effect.sprite.Play("Poof");
|
|
}
|
|
else if (subtype == 2 || subtype == 4 || subtype == 5)
|
|
{
|
|
effect.renderZOffset = POOF_RENDER_Z;
|
|
effect.sprite.Play("Poof");
|
|
}
|
|
else if (subtype == POOF02_LAVA_SPLASH || subtype == POOF02_LAVA_SPLASH_LARGE)
|
|
{
|
|
RNG rng = rng_make(effect.initSeed, LAVA_SPLASH_SHIFT);
|
|
uint32_t roll = rng.Next() % LAVA_SPLASH_ANIMATIONS.size();
|
|
effect.sprite.Play(subtype == POOF02_LAVA_SPLASH ? LAVA_SPLASH_ANIMATIONS[roll] : "PoofLarge");
|
|
effect.sprite.isFlipX = !(effect.initSeed & 1);
|
|
}
|
|
}
|
|
|
|
// A dust cloud on a random frame, side and turn at half size over everything, darkened as subtype 1.
|
|
static void dust_cloud_init(Entity_Effect& effect)
|
|
{
|
|
const AnimationData* clouds = effect.sprite.GetAnimationData("Clouds");
|
|
if (!clouds) return;
|
|
|
|
int frame = clouds->length == 0 ? 0 : (int)(Random() % (uint32_t)clouds->length);
|
|
effect.sprite.SetFrame(clouds->name, frame);
|
|
effect.sprite.isFlipX = !(Random() & 1);
|
|
effect.sprite.rotation = random_unit() * FULL_TURN_DEGREES - HALF_TURN_DEGREES;
|
|
effect.sprite.scale = vector_make(DUST_SCALE, DUST_SCALE);
|
|
effect.renderZOffset = POOF_RENDER_Z;
|
|
if (effect.subtype == DUST_DARK) effect.sprite.color = {{1, 1, 1, 1}, {}, {DUST_DARKEN, DUST_DARKEN, DUST_DARKEN}};
|
|
}
|
|
|
|
// A rock explosion's ground break on a random side, in the sheet of its backdrop. Fleshy floors break with their
|
|
// own animations.
|
|
static void rock_explosion_init(Entity_Effect& effect)
|
|
{
|
|
Room& room = *g_game->room;
|
|
|
|
effect.sprite.isFlipX = !(Random() & 1);
|
|
if (room.backdropType == BACKDROP_MINES)
|
|
{
|
|
bool isLava = room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_HAS_WATER;
|
|
effect.sprite.ReplaceSpritesheet(0, isLava ? GROUND_BREAK_MINES_LAVA : GROUND_BREAK_MINES);
|
|
return;
|
|
}
|
|
|
|
auto found = std::find_if(GROUND_BREAKS.begin(), GROUND_BREAKS.end(),
|
|
[&room](const GroundBreak& entry) { return entry.backdrop == room.backdropType; });
|
|
if (found == GROUND_BREAKS.end()) return;
|
|
effect.sprite.ReplaceSpritesheet(0, found->sheet);
|
|
if (found->isFleshy) effect.sprite.Play(FLESH_BREAKS[effect.dropRNG.Next() % FLESH_BREAKS.size()]);
|
|
}
|
|
|
|
// A worm, maggot or leech facing a random way and rising. A crawlspace has none.
|
|
static void worm_init(Entity_Effect& effect)
|
|
{
|
|
if (g_game->room->roomType == ROOM_DUNGEON) return effect.Remove();
|
|
|
|
if (effect.subtype >= 0 && effect.subtype < (int)WORM_ANIMATIONS.size())
|
|
effect.sprite.Play(WORM_ANIMATIONS[effect.subtype]);
|
|
effect.rotation = angle_wrap(random_unit() * FULL_TURN_DEGREES);
|
|
effect.sprite.rotation = effect.rotation;
|
|
effect.sortingLayer = SORTING_DOOR;
|
|
effect.fallingAcceleration = PARTICLE_GRAVITY;
|
|
effect.fallingSpeed = GIB_FALL - random_unit() * GIB_RISE_RANGE;
|
|
}
|
|
|
|
void combat_effect_init(Entity_Effect& effect)
|
|
{
|
|
ANM2& sprite = effect.sprite;
|
|
int subtype = effect.subtype;
|
|
|
|
switch (variant_get(effect))
|
|
{
|
|
case CombatEffect::BOMB_EXPLOSION:
|
|
explosion_shrink(effect);
|
|
sprite.isFlipX = !(Random() & 1);
|
|
break;
|
|
case CombatEffect::BOMB_CRATER:
|
|
effect.sortingLayer = SORTING_BACKGROUND;
|
|
explosion_shrink(effect);
|
|
break;
|
|
case CombatEffect::BLOOD_SPLAT:
|
|
effect.sortingLayer = SORTING_BACKGROUND;
|
|
break;
|
|
case CombatEffect::RIPPLE_POOF:
|
|
effect.sortingLayer = SORTING_BACKGROUND;
|
|
sprite.isFlipX = Random() & 1;
|
|
break;
|
|
case CombatEffect::TEAR_POOF_A:
|
|
case CombatEffect::TEAR_POOF_B:
|
|
case CombatEffect::TEAR_POOF_SMALL:
|
|
case CombatEffect::TEAR_POOF_VERYSMALL:
|
|
effect.rotation = (float)(Random() & 3) * RIGHT_ANGLE_DEGREES;
|
|
effect.isUnknown176 = true;
|
|
break;
|
|
case CombatEffect::IMPACT:
|
|
effect.rotation = (float)(Random() & 3) * RIGHT_ANGLE_DEGREES;
|
|
effect.isUnknown176 = true;
|
|
sprite.isFlipX = !(Random() & 1);
|
|
break;
|
|
case CombatEffect::BLOOD_EXPLOSION:
|
|
if (subtype >= 1 && subtype < (int)BLOOD_EXPLOSION_ANIMATIONS.size())
|
|
sprite.Play(BLOOD_EXPLOSION_ANIMATIONS[subtype]);
|
|
effect.isUnknown176 = true;
|
|
break;
|
|
case CombatEffect::HEART:
|
|
if (subtype >= 0 && subtype < (int)NOTIFY_ANIMATIONS.size()) sprite.Play(NOTIFY_ANIMATIONS[subtype]);
|
|
break;
|
|
case CombatEffect::BLOOD_DROP:
|
|
sprite.SetFrame("Droplets", random_below(DROPLET_KINDS));
|
|
effect.fallingAcceleration = PARTICLE_GRAVITY;
|
|
effect.fallingSpeed = DROPLET_FALL - random_unit() * DROPLET_RISE_RANGE;
|
|
effect.shadowSize = DROPLET_SHADOW;
|
|
break;
|
|
case CombatEffect::ROCK_PARTICLE:
|
|
case CombatEffect::WOOD_PARTICLE:
|
|
case CombatEffect::TOOTH_PARTICLE:
|
|
case CombatEffect::DIAMOND_PARTICLE:
|
|
case CombatEffect::NAIL_PARTICLE:
|
|
case CombatEffect::GOLD_PARTICLE:
|
|
case CombatEffect::COIN_PARTICLE:
|
|
case CombatEffect::CHAIN_GIB:
|
|
particle_init(effect);
|
|
break;
|
|
case CombatEffect::POOP_PARTICLE: poop_particle_init(effect); break;
|
|
case CombatEffect::POOF01:
|
|
case CombatEffect::POOF02:
|
|
poof_init(effect);
|
|
break;
|
|
case CombatEffect::DUST_CLOUD: dust_cloud_init(effect); break;
|
|
case CombatEffect::ROCK_EXPLOSION: rock_explosion_init(effect); break;
|
|
case CombatEffect::WORM: worm_init(effect); break;
|
|
default: break;
|
|
}
|
|
}
|
|
|
|
// Turns a poof by its rotation, mirrored unless flipped, and removes it once its animation ends. G FUEL's poof
|
|
// booms on its event, and POOF01's subtype 100 leaves a plain poof behind.
|
|
static void poof_update(Entity_Effect& effect)
|
|
{
|
|
bool isPoof01 = variant_get(effect) == CombatEffect::POOF01;
|
|
|
|
effect.sprite.rotation = effect.sprite.isFlipX ? effect.rotation : -effect.rotation;
|
|
if (isPoof01 && effect.subtype == POOF01_GFUEL && effect.sprite.IsEventTriggered("GFuelExplosion"))
|
|
{
|
|
sound_play(SOUND_GFUEL_EXPLOSION_BIG, 1, random_unit() * GFUEL_PITCH_RANGE + GFUEL_PITCH_MIN);
|
|
game_shake_screen(GFUEL_SHAKE);
|
|
}
|
|
if (!effect.sprite.IsFinished()) return;
|
|
|
|
if (isPoof01 && effect.subtype == POOF01_REPEATING) effect_spawn(effect.pos, effect.variant)->Update();
|
|
effect.Remove();
|
|
}
|
|
|
|
// A bomb explosion's sound on its first frame, by what set it off and its size. With G FUEL!, an unturned one turns
|
|
// into its promo explosion.
|
|
static void explosion_sound_play(Entity_Effect& effect)
|
|
{
|
|
if (effect.spawnerType == ENTITY_DUKE_OF_FLIES || effect.spawnerType == ENTITY_RAG_MEGA || effect.state != 0)
|
|
return;
|
|
effect.state++;
|
|
|
|
if (effect.rotation == 0 && g_game->playerManager.GetGFuelCount() >= 1)
|
|
{
|
|
effect.sprite.Load(GFUEL_EXPLOSION_ANM2, GRAPHICS_LOAD);
|
|
effect.sprite.Play("Idle");
|
|
bool isLarge = effect.sprite.scale.x >= EXPLOSION_LARGE_SCALE;
|
|
return sound_play(isLarge ? SOUND_EXPLOSION_STRONG : SOUND_GFUEL_EXPLOSION, 1, 1);
|
|
}
|
|
|
|
Entity* spawner = effect.spawnerEntity;
|
|
auto* bomb = spawner && spawner->is_bomb() ? static_cast<Entity_Bomb*>(spawner) : nullptr;
|
|
float size = effect.sprite.scale.x;
|
|
if (bomb && bomb->tearFlags.test(TEAR_GLITTER_BOMB)) sound_play(SOUND_GLITTER_BOMB, 1, 1);
|
|
else if (size < EXPLOSION_SMALL_SCALE) sound_play(SOUND_EXPLOSION_WEAK, EXPLOSION_SMALL_VOLUME, 1);
|
|
else if (size > EXPLOSION_LARGE_SCALE) sound_play(SOUND_EXPLOSION_STRONG, EXPLOSION_LARGE_VOLUME, 1);
|
|
else if (bomb && bomb->IsRocket()) sound_play(SOUND_ROCKET_EXPLOSION, 1, 1);
|
|
else sound_play(SOUND_BOSS_EXPLOSION, 1, 1);
|
|
}
|
|
|
|
// A blood or poop explosion and POOF04: random flips and a floor frame at first, then laid on the floor from that
|
|
// frame on (its subtype 0 only), and removed when done.
|
|
static void blood_explosion_update(Entity_Effect& effect)
|
|
{
|
|
bool isBlood = variant_get(effect) == CombatEffect::BLOOD_EXPLOSION;
|
|
ANM2& sprite = effect.sprite;
|
|
|
|
if (effect.state == 0)
|
|
{
|
|
bool isFlipX = random_below(2) == 0;
|
|
bool isFlipY = random_below(2) == 0;
|
|
|
|
// The original sets layer 0's flips once for each layer.
|
|
if (!sprite.layerStates.empty())
|
|
{
|
|
sprite.GetLayer(0)->isFlipX = isFlipX;
|
|
sprite.GetLayer(0)->isFlipY = isFlipY;
|
|
}
|
|
effect.state = random_below(BLOOD_EXPLOSION_FLOOR_RANGE) + BLOOD_EXPLOSION_FLOOR_FRAME;
|
|
}
|
|
|
|
if (sprite.GetFrame() == effect.state && effect.subtype == 0)
|
|
{
|
|
effect.AddEntityFlags(FLAG_RENDER_FLOOR);
|
|
if (isBlood) effect.AddEntityFlags(FLAG_NO_REMOVE_ON_TEX_RENDER);
|
|
}
|
|
else if (isBlood) effect.ClearEntityFlags(FLAG_RENDER_FLOOR | FLAG_NO_REMOVE_ON_TEX_RENDER);
|
|
if (sprite.IsFinished()) effect.Remove();
|
|
}
|
|
|
|
// Falls a particle by its speed and gravity at the room's time scale, its height shown as its offset.
|
|
static void particle_fall(Entity_Effect& effect)
|
|
{
|
|
float timeScale = effect.speedMultiplier;
|
|
|
|
effect.fallingSpeed *= timescale_factor(PARTICLE_FALL_DRAG, timeScale);
|
|
effect.fallingSpeed += timeScale * PARTICLE_FALL_PULL;
|
|
effect.fallingSpeed += effect.fallingAcceleration * timeScale;
|
|
effect.height += effect.fallingSpeed * timeScale;
|
|
effect.posOffset.y = effect.height;
|
|
}
|
|
|
|
// A crawlspace's side view: the particle drops flat until it is past the room's bottom, where it goes.
|
|
static void particle_drop(Entity_Effect& effect)
|
|
{
|
|
effect.height = CRAWLSPACE_HEIGHT;
|
|
effect.friction = 1;
|
|
effect.entityGridCollisionClass = GRIDCOLL_NONE;
|
|
effect.entityCollisionClass = ENTCOLL_NONE;
|
|
effect.posOffset = {};
|
|
effect.velocity.y += effect.speedMultiplier * CRAWLSPACE_GRAVITY;
|
|
if (effect.velocity.y > 0 && effect.pos.y > g_game->room->bottomRightPos.y + CRAWLSPACE_FLOOR_MARGIN)
|
|
effect.Remove();
|
|
}
|
|
|
|
// Lays a particle still on the floor, drawn into it.
|
|
static void particle_land(Entity_Effect& effect)
|
|
{
|
|
effect.velocity = {};
|
|
effect.sortingLayer = SORTING_BACKGROUND;
|
|
effect.renderZOffset = PARTICLE_FLOOR_Z;
|
|
effect.AddEntityFlags(FLAG_RENDER_FLOOR);
|
|
}
|
|
|
|
// 005d29b0 Pulls a falling particle back inside the walls, by under 10 a frame, while it falls.
|
|
static void particle_room_pull(Entity_Effect& effect)
|
|
{
|
|
float margin = effect.height + PARTICLE_ROOM_MARGIN;
|
|
Vector inside = g_game->room->GetClampedPositionImpl(effect.pos, margin, margin, margin, margin);
|
|
Vector pull = vector_sub(inside, effect.pos);
|
|
float distance = vector_length_squared(pull);
|
|
|
|
if (distance <= 0 || distance >= PARTICLE_ROOM_PULL_SQUARED || effect.fallingSpeed <= 0) return;
|
|
effect.velocity = pull;
|
|
effect.pos = inside;
|
|
}
|
|
|
|
// A rock particle's first frame: the sheet and rubble of the rock under it, or of its backdrop's rocks, on a random
|
|
// rubble frame, set to bounce by its subtype.
|
|
// The original reads past the backdrops for a subtype's backdrop over the last. It takes the room's own.
|
|
static void rock_particle_start(Entity_Effect& effect)
|
|
{
|
|
Room& room = *g_game->room;
|
|
Backdrop& backdrop = room.backdrop;
|
|
int subtype = effect.subtype;
|
|
uint32_t backdropId = subtype & ROCK_PARTICLE_BACKDROP_MASK;
|
|
std::string_view rubble = "rubble";
|
|
GridEntity* under = backdropId == 0 ? room.GetGridEntity((uint32_t)room.GetGridIndex(effect.pos)) : nullptr;
|
|
|
|
if (auto* rock = dynamic_cast<GridEntity_Rock*>(under))
|
|
{
|
|
effect.sprite = rock->sprite;
|
|
rubble = rock->rubbleAnim;
|
|
}
|
|
else
|
|
{
|
|
uint32_t id = backdropId == 0 || backdropId >= BACKDROP_COUNT ? backdrop.backdropId : backdropId;
|
|
effect.sprite.ReplaceSpritesheet(0, backdrop.configs[id].rocks);
|
|
effect.sprite.LoadGraphics();
|
|
if (backdropId != 0 && (subtype & ROCK_PARTICLE_ALT)) rubble = "rubble_alt";
|
|
}
|
|
|
|
if (const AnimationData* data = effect.sprite.GetAnimationData(rubble))
|
|
effect.sprite.SetFrame(rubble, random_below(data->length));
|
|
effect.state = (subtype & ROCK_PARTICLE_BOUNCY) ? PARTICLE_BOUNCING : PARTICLE_FALLING;
|
|
}
|
|
|
|
// A falling particle's frame: it falls, lands on the floor or bounces off it while pulled inside the walls, and an
|
|
// animated one goes when its animation ends. A rock particle shrinks away after bouncing, faster in a pit.
|
|
static EffectUpdateEnd particle_update(Entity_Effect& effect)
|
|
{
|
|
CombatEffect variant = variant_get(effect);
|
|
bool isRock = variant == CombatEffect::ROCK_PARTICLE;
|
|
bool isCrawlspace = g_game->room->roomType == ROOM_DUNGEON;
|
|
|
|
if (effect.state == 0)
|
|
{
|
|
bool isBouncing = effect.subtype == PARTICLE_BOUNCY && random_below(PARTICLE_STILL_ODDS) != 0;
|
|
effect.state = isBouncing ? PARTICLE_BOUNCING : PARTICLE_FALLING;
|
|
}
|
|
if (is_listed(ANIMATED_PARTICLES, variant) && effect.sprite.IsFinished() && effect.sprite.GetFrame() > 0)
|
|
effect.Remove();
|
|
if (isCrawlspace) particle_drop(effect);
|
|
else particle_fall(effect);
|
|
|
|
if (effect.state > PARTICLE_BOUNCING && isRock && effect.FrameCount() > PARTICLE_SHRINK_DELAY)
|
|
{
|
|
float shrink = PARTICLE_SHRINK;
|
|
if (effect.state == PARTICLE_SINKING)
|
|
{
|
|
effect.sprite.GetLayer(0)->color._tint[3] *= PARTICLE_SINK_FADE;
|
|
shrink = PARTICLE_SINK_SHRINK;
|
|
}
|
|
|
|
Vector scale = vector_sub(effect.sprite.scale, vector_make(shrink, shrink));
|
|
if (scale.x <= 0 || scale.y <= 0)
|
|
{
|
|
effect.Remove();
|
|
return EFFECT_UPDATE_RETURN;
|
|
}
|
|
effect.sprite.scale = scale;
|
|
}
|
|
|
|
if (isCrawlspace) return EFFECT_UPDATE_FINISH;
|
|
if (effect.height <= PARTICLE_GROUND_HEIGHT)
|
|
{
|
|
if (!isRock || effect.state < PARTICLE_BOUNCING) particle_room_pull(effect);
|
|
return EFFECT_UPDATE_FINISH;
|
|
}
|
|
if (isRock && (room_grid_collision_at(effect.pos) == COLLISION_PIT || effect.state == PARTICLE_SINKING))
|
|
{
|
|
effect.state = PARTICLE_SINKING;
|
|
return EFFECT_UPDATE_FINISH;
|
|
}
|
|
if (effect.state < PARTICLE_BOUNCING)
|
|
{
|
|
particle_land(effect);
|
|
return EFFECT_UPDATE_FINISH;
|
|
}
|
|
|
|
if (!isRock) particle_room_pull(effect);
|
|
effect.height = PARTICLE_GROUND_HEIGHT;
|
|
effect.posOffset.y = PARTICLE_GROUND_HEIGHT;
|
|
effect.fallingSpeed *= PARTICLE_BOUNCE;
|
|
effect.velocity = vector_scale(effect.velocity, PARTICLE_BOUNCE_SLOWDOWN);
|
|
effect.state = PARTICLE_BOUNCED;
|
|
if (!effect.sprite.IsPlaying() && !isRock) effect.sprite.Play(effect.sprite.GetAnimation(), PLAY_FORCED);
|
|
return EFFECT_UPDATE_FINISH;
|
|
}
|
|
|
|
// A blood particle is a drop when another blood particle spat it.
|
|
static bool is_blood_drop(const Entity_Effect& effect)
|
|
{
|
|
return effect.spawnerType == effect.type && (int)effect.spawnerVariant == effect.variant;
|
|
}
|
|
|
|
// A blood particle's gib animation by its subtype. Past the known kinds it shows nothing.
|
|
static const char* blood_particle_animation(Entity_Effect& effect)
|
|
{
|
|
switch (effect.subtype)
|
|
{
|
|
case BLOOD_PARTICLE_BLOOD: return BLOOD_GIBS[random_below((int)BLOOD_GIBS.size())];
|
|
case BLOOD_PARTICLE_BONE: return BONES[random_below((int)BONES.size())];
|
|
case BLOOD_PARTICLE_GUTS: return GUTS[random_below((int)GUTS.size())];
|
|
case BLOOD_PARTICLE_EYE: return "Eye";
|
|
case BLOOD_PARTICLE_GIB: return GIB_ANIMATIONS[random_below((int)GIB_ANIMATIONS.size())];
|
|
default:
|
|
effect.isVisible = false;
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
// A blood particle's first frame: 23 high and rising, a drop on a random frame or a gib turned at random.
|
|
static void blood_particle_start(Entity_Effect& effect)
|
|
{
|
|
effect.fallingAcceleration = PARTICLE_GRAVITY;
|
|
effect.height = PARTICLE_START_HEIGHT;
|
|
effect.posOffset.y = effect.height;
|
|
if (is_blood_drop(effect))
|
|
{
|
|
effect.sprite.SetFrame("Particle", random_below(BLOOD_DROP_FRAMES));
|
|
effect.fallingSpeed = GIB_FALL - random_unit() * BLOOD_DROP_RISE_RANGE;
|
|
}
|
|
else
|
|
{
|
|
effect.sprite.GetLayer(0)->rotation = random_unit() * FULL_TURN_DEGREES;
|
|
if (const char* animation = blood_particle_animation(effect)) effect.sprite.Play(animation);
|
|
effect.fallingSpeed = GIB_FALL - random_unit() * GIB_RISE_RANGE;
|
|
}
|
|
effect.state++;
|
|
}
|
|
|
|
// A blood gib in the air leaves splats under it now and then, and drops in its first frames.
|
|
static void blood_particle_spatter(Entity_Effect& effect)
|
|
{
|
|
bool isSplashing = !effect.HasEntityFlags(FLAG_NO_BLOOD_SPLASH);
|
|
|
|
if (random_below(BLOOD_SPLAT_ODDS) == 0 && isSplashing)
|
|
{
|
|
Entity_Effect* stain = stain_spawn(effect);
|
|
float size = random_unit() * BLOOD_SPLAT_SCALE_RANGE + BLOOD_SPLAT_SCALE_MIN;
|
|
stain->sprite.scale = vector_make(size, size);
|
|
stain->Update();
|
|
}
|
|
|
|
bool isDripping = effect.state >= BLOOD_DRIP_FIRST_STATE && effect.state <= BLOOD_DRIP_LAST_STATE;
|
|
for (int i = 0; isDripping && isSplashing && effect.isVisible && i < random_below(effect.state); i++)
|
|
{
|
|
uint32_t seed = Random();
|
|
Vector velocity = vector_scale(random_direction(), BLOOD_DRIP_SPEED);
|
|
Entity* drop = g_game->Spawn({effect.pos, velocity, &effect, 0, ENTITY_EFFECT,
|
|
static_cast<int>(CombatEffect::BLOOD_PARTICLE), seed});
|
|
drop->SetColor(effect.splatColor, -1, 255, false, true);
|
|
}
|
|
effect.state++;
|
|
}
|
|
|
|
// A blood particle on the floor: one an effect spat stays out of its middle frames, a hidden gib goes, a shown one
|
|
// lies on its last frame. One that glows (an alpha over 1) fades from the floor instead, on whole pixels.
|
|
static void blood_particle_land(Entity_Effect& effect)
|
|
{
|
|
if (effect.spawnerType == effect.type)
|
|
{
|
|
int frame = effect.sprite.GetFrame();
|
|
if (frame >= BLOOD_DROP_GONE_FIRST && frame <= BLOOD_DROP_GONE_LAST) effect.Remove();
|
|
else
|
|
{
|
|
effect.AddEntityFlags(FLAG_RENDER_FLOOR);
|
|
effect.sortingLayer = SORTING_BACKGROUND;
|
|
}
|
|
}
|
|
else if (!effect.isVisible) effect.Remove();
|
|
else
|
|
{
|
|
effect.sprite.SetLastFrame();
|
|
particle_land(effect);
|
|
}
|
|
|
|
if (!effect.HasEntityFlags(FLAG_RENDER_FLOOR) || effect.color._tint[3] <= 1) return;
|
|
effect.ClearEntityFlags(FLAG_RENDER_FLOOR);
|
|
effect.state = PARTICLE_GLOWING;
|
|
effect.SetTimeout(PARTICLE_GLOW_FRAMES);
|
|
effect.fallingSpeed = 0;
|
|
effect.posOffset.y = 0;
|
|
effect.pos = pixel_snap(effect.pos);
|
|
}
|
|
|
|
// A gory blood particle spins as it drops through a crawlspace, its blood, eye and guts trailing blood.
|
|
static void blood_gore_spin(Entity_Effect& effect)
|
|
{
|
|
RNG rng = rng_make(effect.initSeed, GORE_SPIN_SHIFT);
|
|
float side = rng.RandomInt(2) == 0 ? -1.0f : 1.0f;
|
|
float spin = (rng.RandomFloat() * GORE_SPIN_RANGE + GORE_SPIN_MIN) * side;
|
|
bool isTrailing = effect.subtype == BLOOD_PARTICLE_BLOOD || effect.subtype == BLOOD_PARTICLE_EYE ||
|
|
effect.subtype == BLOOD_PARTICLE_GUTS;
|
|
|
|
effect.sprite.rotation += spin * effect.speedMultiplier;
|
|
if (!isTrailing || !effect.IsFrame(GORE_TRAIL_FRAMES, 0) || random_below(GORE_TRAIL_ODDS) != 0) return;
|
|
|
|
uint32_t seed = Random();
|
|
Vector velocity = vector_scale(effect.velocity, GORE_TRAIL_SPEED);
|
|
Entity* trail = g_game->Spawn({effect.pos, velocity, nullptr, GORE_TRAIL_SUBTYPE, ENTITY_EFFECT,
|
|
static_cast<int>(CombatEffect::BLOOD_EXPLOSION), seed});
|
|
trail->SetColor(effect.splatColor, -1, 255, false, true);
|
|
trail->Update();
|
|
}
|
|
|
|
// A glowing stain fading toward a color and half its alpha over its timeout, drawn into the floor at its end.
|
|
static void glow_fade(Entity_Effect& effect, const ColorMod& fade)
|
|
{
|
|
float t = (float)effect.timeout / (float)effect.lifespan;
|
|
|
|
effect.sprite.color = color_lerp(fade, effect.color, t);
|
|
effect.sprite.color._tint[3] = effect.color._tint[3] * ((1 - GLOW_ALPHA_MIN) * t + GLOW_ALPHA_MIN);
|
|
if (effect.isDead) effect.AddEntityFlags(FLAG_RENDER_FLOOR);
|
|
}
|
|
|
|
// A blood particle's frame: a gib or drop falls, spattering in the air, and lands. In a crawlspace it drops through.
|
|
static void blood_particle_update(Entity_Effect& effect)
|
|
{
|
|
if (effect.state == 0) return blood_particle_start(effect);
|
|
if (effect.state == PARTICLE_GLOWING) return glow_fade(effect, PARTICLE_GLOW_FADE);
|
|
|
|
if (g_game->room->roomType == ROOM_DUNGEON)
|
|
{
|
|
if (effect.HasEntityFlags(FLAG_EXTRA_GORE)) blood_gore_spin(effect);
|
|
return particle_drop(effect);
|
|
}
|
|
|
|
particle_fall(effect);
|
|
if (effect.height > PARTICLE_GROUND_HEIGHT) return blood_particle_land(effect);
|
|
if (effect.spawnerType != effect.type) blood_particle_spatter(effect);
|
|
particle_room_pull(effect);
|
|
}
|
|
|
|
// A poop particle falls, pulled inside the walls, and lies on its last frame on the floor.
|
|
static void poop_particle_update(Entity_Effect& effect)
|
|
{
|
|
if (g_game->room->roomType == ROOM_DUNGEON) return particle_drop(effect);
|
|
|
|
particle_fall(effect);
|
|
if (effect.height <= PARTICLE_GROUND_HEIGHT) return particle_room_pull(effect);
|
|
effect.sprite.SetLastFrame();
|
|
particle_land(effect);
|
|
}
|
|
|
|
// A blood stain settles on its first update: the stain animation for the scale it was spawned at on a random frame,
|
|
// its own scale, random flips, a random strength for an opaque color, and the floor to be drawn into. A glowing one
|
|
// (an alpha over 1) instead sits on whole pixels and fades with a light of its color.
|
|
static void stain_update(Entity_Effect& effect)
|
|
{
|
|
if (effect.state != 0) return glow_fade(effect, STAIN_GLOW_FADE);
|
|
|
|
ANM2& sprite = effect.sprite;
|
|
float spawnScale = sprite.scale.x;
|
|
sprite.scale = vector_make(effect.scale, effect.scale);
|
|
|
|
auto limit = std::find_if(STAIN_SCALE_LIMITS.begin(), STAIN_SCALE_LIMITS.end(),
|
|
[spawnScale](float scaleLimit) { return spawnScale < scaleLimit; });
|
|
const char* animation = STAIN_ANIMATIONS[limit - STAIN_SCALE_LIMITS.begin()];
|
|
if (const AnimationData* data = sprite.GetAnimationData(animation))
|
|
sprite.SetFrame(animation, random_below(data->length));
|
|
sprite.isFlipX = random_below(2) == 0;
|
|
sprite.isFlipY = random_below(2) == 0;
|
|
|
|
bool isGlowing = effect.color._tint[3] > 1;
|
|
if (sprite.color._tint[3] >= 1)
|
|
sprite.color._tint[3] = (float)random_below(STAIN_ALPHA_STEPS) * STAIN_ALPHA_STEP + STAIN_ALPHA_MIN;
|
|
if (!isGlowing) return effect.AddEntityFlags(FLAG_RENDER_FLOOR);
|
|
|
|
effect.state = 1;
|
|
effect.SetTimeout(random_below(STAIN_GLOW_FRAMES) + STAIN_GLOW_FRAMES);
|
|
effect.pos = pixel_snap(effect.pos);
|
|
|
|
const ColorMod& glow = effect.color;
|
|
float red = (glow._tint[0] * STAIN_LIGHT_RED / COLOR_CHANNEL_MAX + glow._offset[0]) * STAIN_LIGHT_BOOST;
|
|
float green = (glow._tint[1] * STAIN_LIGHT_GREEN / COLOR_CHANNEL_MAX + glow._offset[1]) * STAIN_LIGHT_BOOST;
|
|
float blue = (glow._tint[2] * STAIN_LIGHT_BLUE / COLOR_CHANNEL_MAX + glow._offset[2]) * STAIN_LIGHT_BOOST;
|
|
int lightFrames = effect.timeout - STAIN_LIGHT_LEAD;
|
|
effect_light_create({.color = kcolor_rgba(red, green, blue, 1),
|
|
.position = effect.pos,
|
|
.scale = spawnScale * STAIN_LIGHT_SCALE,
|
|
.fadeFrames = lightFrames,
|
|
.timeout = lightFrames});
|
|
}
|
|
|
|
// A ripple first draws its small sizes larger with their own animations, then turns and ends as a poof.
|
|
static void ripple_update(Entity_Effect& effect)
|
|
{
|
|
ANM2& sprite = effect.sprite;
|
|
|
|
if (effect.state == 0)
|
|
{
|
|
if (sprite.scale.x <= RIPPLE_TINY_SCALE)
|
|
{
|
|
sprite.scale = vector_scale(sprite.scale, RIPPLE_TINY_GROWTH);
|
|
sprite.Play("Poof_Tiny");
|
|
}
|
|
else if (sprite.scale.x <= RIPPLE_SMALL_SCALE)
|
|
{
|
|
sprite.scale = vector_scale(sprite.scale, RIPPLE_SMALL_GROWTH);
|
|
sprite.Play("Poof_Small");
|
|
}
|
|
effect.state = 1;
|
|
}
|
|
poof_update(effect);
|
|
}
|
|
|
|
// A bomb crater settles on its first update: its small kind drawn twice as big, a seeded frame, a random strength, a
|
|
// darker tint in the Dark Room, and the floor to be drawn into, or 150 frames for a temporary one, which fades out
|
|
// over its last 60.
|
|
static void crater_update(Entity_Effect& effect)
|
|
{
|
|
ANM2& sprite = effect.sprite;
|
|
bool isTemporary = effect.subtype == CRATER_TEMPORARY;
|
|
|
|
if (effect.state == 0)
|
|
{
|
|
Vector scale = sprite.scale;
|
|
if (scale.x > CRATER_SMALL_SCALE) sprite.SetAnimation("Idle");
|
|
else
|
|
{
|
|
sprite.SetAnimation("IdleSmall");
|
|
scale = vector_scale(scale, CRATER_SMALL_GROWTH);
|
|
}
|
|
sprite.scale = scale;
|
|
|
|
RNG rng = rng_make(effect.initSeed, CRATER_FRAME_SHIFT);
|
|
uint32_t frame = rng.RandomInt((uint32_t)sprite.animState.GetAnimationLength());
|
|
sprite.color._tint[3] = random_unit() * CRATER_ALPHA_RANGE + CRATER_ALPHA_MIN;
|
|
sprite.SetFrame((float)frame);
|
|
if (g_game->room->backdropType == BACKDROP_DARK_ROOM)
|
|
{
|
|
float* tint = sprite.GetLayer(0)->color._tint;
|
|
std::fill(tint, tint + 3, CRATER_DARK_TINT);
|
|
tint[3] = 1;
|
|
}
|
|
|
|
if (effect.subtype == 0) effect.AddEntityFlags(FLAG_RENDER_FLOOR);
|
|
else effect.SetTimeout(CRATER_TEMPORARY_FRAMES);
|
|
effect.state++;
|
|
}
|
|
|
|
if (!isTemporary || effect.timeout >= CRATER_FADE_FRAMES) return;
|
|
sprite.color._tint[3] = std::max(sprite.color._tint[3] - 1.0f / CRATER_FADE_FRAMES, 0.0f);
|
|
if (sprite.color._tint[3] <= 0) effect.Remove();
|
|
}
|
|
|
|
// A dust cloud turns, slows, grows and fades over its timeout, subtype 2 thickest halfway, and goes when it dies.
|
|
static void dust_cloud_update(Entity_Effect& effect)
|
|
{
|
|
ANM2& sprite = effect.sprite;
|
|
float lifespan = (float)effect.lifespan;
|
|
float t = 1 - (float)effect.timeout / lifespan;
|
|
|
|
sprite.rotation += effect.rotation;
|
|
effect.friction *= DUST_FRICTION;
|
|
if (effect.subtype == DUST_PULSE)
|
|
{
|
|
float fromPeak = t - DUST_PULSE_PEAK;
|
|
t = 1 - std::clamp(1 - fromPeak * DUST_PULSE_SHARPNESS * fromPeak, 0.0f, 1.0f);
|
|
}
|
|
sprite.scale = vector_add(sprite.scale, vector_make(DUST_GROWTH / lifespan, DUST_GROWTH / lifespan));
|
|
sprite.color._tint[3] = effect.color._tint[3] * (1 - t);
|
|
if (effect.isDead) effect.Remove();
|
|
}
|
|
|
|
// A rock explosion throws a rock particle now and then on its second frame, glowing over lava, and goes when done.
|
|
static void rock_explosion_update(Entity_Effect& effect)
|
|
{
|
|
if (effect.sprite.GetFrame() == ROCK_EXPLOSION_SPARK_FRAME)
|
|
{
|
|
int count = random_below(ROCK_EXPLOSION_SPARK_ODDS) == 0 ? 1 : 0;
|
|
game_particles_spawn({.position = effect.pos,
|
|
.speed = ROCK_EXPLOSION_SPARK_SPEED,
|
|
.count = count,
|
|
.variant = static_cast<int>(CombatEffect::ROCK_PARTICLE)});
|
|
if (g_game->room->HasLava())
|
|
{
|
|
Entity_Effect* glow = effect_spawn(effect.pos, EFFECT_LIGHT);
|
|
glow->sprite.color = LAVA_GLOW_COLOR;
|
|
glow->SetTimeout(LAVA_GLOW_FRAMES);
|
|
glow->sprite.scale = vector_make(LAVA_GLOW_SCALE, LAVA_GLOW_SCALE);
|
|
glow->parent = &effect;
|
|
}
|
|
}
|
|
if (effect.sprite.IsFinished()) effect.Remove();
|
|
}
|
|
|
|
// Whether a dead tear lies within reach of a position (EntityList::QueryRadius over the tears).
|
|
static bool is_dead_tear_near(const Vector& position, float radius)
|
|
{
|
|
EntityList_EL shots;
|
|
g_game->room->entityList.partitions[PARTITION_SHOTS].query_box(shots, position, vector_make(radius, radius));
|
|
|
|
for (Entity* shot : shots)
|
|
{
|
|
float reach = radius + shot->size;
|
|
bool isNear = vector_length_squared(vector_sub(shot->pos, position)) < reach * reach;
|
|
if (!shot->HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && isNear && shot->type == ENTITY_TEAR && shot->isDead)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Pushes a worm out of the grid entity under it, other than a rock, to its cell's nearest edge. Still in a pit, it
|
|
// steps back and turns, nudged off at random when that is a pit too.
|
|
static void worm_grid_push(Entity_Effect& effect)
|
|
{
|
|
Room& room = *g_game->room;
|
|
if (room_grid_collision_at(effect.pos) == COLLISION_NONE) return;
|
|
|
|
int cellIndex = room.GetGridIndex(effect.pos);
|
|
GridEntity* grid = room.GetGridEntity((uint32_t)cellIndex);
|
|
if (!grid || grid->type == GRID_ROCK) return;
|
|
|
|
Vector cell = room.GetGridPosition(cellIndex);
|
|
Vector toCell = vector_sub(cell, effect.pos);
|
|
if (std::fabs(toCell.x) <= std::fabs(toCell.y))
|
|
{
|
|
effect.pos.y = cell.y + (toCell.y <= 0 ? WORM_CELL_EDGE : -WORM_CELL_EDGE);
|
|
effect.velocity.y *= WORM_EDGE_SLOWDOWN;
|
|
}
|
|
else
|
|
{
|
|
effect.pos.x = cell.x + (toCell.x <= 0 ? WORM_CELL_EDGE : -WORM_CELL_EDGE);
|
|
effect.velocity.x *= WORM_EDGE_SLOWDOWN;
|
|
}
|
|
|
|
if (grid->type != GRID_PIT || room_grid_collision_at(effect.pos) == COLLISION_NONE) return;
|
|
effect.pos = effect.targetPosition;
|
|
effect.rotation = angle_wrap(random_unit() * FULL_TURN_DEGREES);
|
|
if (room_grid_collision_at(effect.pos) == COLLISION_PIT) effect.pos = vector_add(effect.pos, random_direction());
|
|
}
|
|
|
|
// A worm's frame: it wobbles and falls, turns from the walls, idles or crawls in bursts, crawls away from a player
|
|
// close by, keeps off grid entities, and splats when it dies: stepped on by a walking player or hit by a tear.
|
|
static void worm_update(Entity_Effect& effect)
|
|
{
|
|
Room& room = *g_game->room;
|
|
float wobble = effect.state < 1 ? WORM_IDLE_WOBBLE : WORM_CRAWL_WOBBLE;
|
|
|
|
effect.rotation = angle_wrap(random_unit() * wobble + effect.rotation - wobble * HALF);
|
|
effect.sprite.rotation = effect.rotation;
|
|
effect.pos = room.GetClampedPosition(effect.pos, WORM_INNER_MARGIN);
|
|
if (effect.posOffset.y >= 0)
|
|
{
|
|
effect.friction *= WORM_GROUND_FRICTION;
|
|
effect.shadowSize = 0;
|
|
}
|
|
else
|
|
{
|
|
effect.fallingSpeed = effect.fallingSpeed * WORM_FALL_DRAG + effect.fallingAcceleration;
|
|
effect.posOffset.y = std::min(effect.posOffset.y + effect.fallingSpeed, 0.0f);
|
|
effect.rotation = vector_angle(effect.velocity);
|
|
effect.friction *= WORM_FRICTION;
|
|
effect.shadowSize = std::min(effect.posOffset.y / WORM_SHADOW_HEIGHT * WORM_SHADOW, WORM_SHADOW);
|
|
}
|
|
|
|
Vector inside = room.GetClampedPosition(effect.pos, WORM_WALL_MARGIN);
|
|
if (!vector_is_zero(vector_sub(inside, effect.pos)))
|
|
effect.rotation = angle_lerp(effect.rotation, vector_angle(vector_sub(inside, effect.pos)), WORM_WALL_TURN);
|
|
|
|
float push = effect.subtype >= 1 && effect.subtype <= 2 ? WORM_PUSHES[effect.subtype] : WORM_PUSHES[0];
|
|
if (effect.state >= 1)
|
|
{
|
|
effect.AddVelocity_divided(vector_scale(vector_from_angle(effect.rotation), random_unit() * push + push), false);
|
|
effect.state--;
|
|
}
|
|
else if (random_below(WORM_CRAWL_ODDS) == 0) effect.state = random_below(WORM_CRAWL_RANGE) + WORM_CRAWL_MIN;
|
|
else if (random_below(WORM_NUDGE_ODDS) == 0)
|
|
effect.AddVelocity_divided(vector_scale(vector_from_angle(effect.rotation), random_unit() * push), false);
|
|
|
|
Entity_Player* player = game_nearest_player(effect.pos);
|
|
float distance = vector_length_squared(vector_sub(effect.pos, player->pos));
|
|
if (distance < WORM_FLEE_RANGE_SQUARED && random_below(WORM_FLEE_ODDS) == 0)
|
|
{
|
|
float closeness = 1 - distance / WORM_FLEE_RANGE_SQUARED;
|
|
float away = vector_angle(vector_sub(effect.pos, player->pos));
|
|
effect.rotation = angle_lerp(effect.rotation, away, WORM_FLEE_TURN);
|
|
Vector flee = vector_scale(vector_from_angle(effect.rotation), push * closeness * WORM_FLEE_PUSH);
|
|
effect.AddVelocity_divided(flee, false);
|
|
effect.state = random_below(WORM_FLEE_RANGE) + WORM_FLEE_MIN;
|
|
}
|
|
|
|
worm_grid_push(effect);
|
|
effect.targetPosition = effect.pos;
|
|
if (effect.isDead)
|
|
{
|
|
Entity_Effect* stain = stain_spawn(effect);
|
|
stain->scale = WORM_SPLAT_SCALE;
|
|
stain->Update();
|
|
effect.Remove();
|
|
}
|
|
|
|
bool isWalking = vector_length_squared(player->velocity) > WORM_STEP_SPEED_SQUARED;
|
|
if (distance < WORM_STEP_RANGE_SQUARED && isWalking && !player->IsFlying()) effect.isDead = true;
|
|
if (is_dead_tear_near(effect.pos, WORM_TEAR_RANGE)) effect.isDead = true;
|
|
|
|
if (vector_length_squared(effect.velocity) <= WORM_STILL_SPEED_SQUARED) effect.sprite.Stop();
|
|
else if (effect.subtype >= 0 && effect.subtype < (int)WORM_ANIMATIONS.size())
|
|
effect.sprite.Play(WORM_ANIMATIONS[effect.subtype]);
|
|
}
|
|
|
|
// A blood drop falls on its own speed until it lands, randomly flipped, splats there or off the room's edge, and
|
|
// faces its motion.
|
|
static void blood_drop_update(Entity_Effect& effect)
|
|
{
|
|
ANM2& sprite = effect.sprite;
|
|
|
|
if (effect.posOffset.y < 0)
|
|
{
|
|
effect.fallingSpeed = effect.fallingSpeed * DROPLET_DRAG + effect.fallingAcceleration;
|
|
effect.posOffset.y = std::min(effect.posOffset.y + effect.fallingSpeed, 0.0f);
|
|
}
|
|
else if (!effect.isDead)
|
|
{
|
|
effect.isDead = true;
|
|
sprite.isFlipX = random_below(2) == 0;
|
|
sprite.isFlipY = random_below(2) == 0;
|
|
}
|
|
|
|
if (effect.isDead)
|
|
{
|
|
effect.sortingLayer = SORTING_BACKGROUND;
|
|
effect.velocity = {};
|
|
sprite.Play("Splat");
|
|
if (sprite.IsFinished()) effect.Remove();
|
|
Vector inside = g_game->room->GetClampedPosition(effect.pos, 0);
|
|
if (inside.x != effect.pos.x || inside.y != effect.pos.y) effect.Remove();
|
|
}
|
|
effect.friction *= DROPLET_FRICTION;
|
|
sprite.rotation = vector_angle(vector_add(effect.velocity, vector_make(0, effect.fallingSpeed))) - SPRITE_UP;
|
|
}
|
|
|
|
EffectUpdateEnd combat_effect_update(Entity_Effect& effect)
|
|
{
|
|
ANM2& sprite = effect.sprite;
|
|
|
|
switch (variant_get(effect))
|
|
{
|
|
case CombatEffect::BOMB_EXPLOSION:
|
|
explosion_sound_play(effect);
|
|
poof_update(effect);
|
|
break;
|
|
case CombatEffect::BLOOD_EXPLOSION:
|
|
case CombatEffect::POOF04:
|
|
case CombatEffect::POOP_EXPLOSION:
|
|
blood_explosion_update(effect);
|
|
break;
|
|
case CombatEffect::ROCK_PARTICLE:
|
|
if (effect.state == 0) rock_particle_start(effect);
|
|
return particle_update(effect);
|
|
case CombatEffect::WOOD_PARTICLE:
|
|
case CombatEffect::TOOTH_PARTICLE:
|
|
case CombatEffect::DIAMOND_PARTICLE:
|
|
case CombatEffect::NAIL_PARTICLE:
|
|
case CombatEffect::GOLD_PARTICLE:
|
|
case CombatEffect::COIN_PARTICLE:
|
|
case CombatEffect::CHAIN_GIB:
|
|
return particle_update(effect);
|
|
case CombatEffect::BLOOD_PARTICLE: blood_particle_update(effect); break;
|
|
case CombatEffect::BLOOD_SPLAT: stain_update(effect); break;
|
|
case CombatEffect::RIPPLE_POOF: ripple_update(effect); break;
|
|
case CombatEffect::BOMB_CRATER: crater_update(effect); break;
|
|
case CombatEffect::POOP_PARTICLE: poop_particle_update(effect); break;
|
|
case CombatEffect::DUST_CLOUD: dust_cloud_update(effect); break;
|
|
case CombatEffect::ROCK_EXPLOSION: rock_explosion_update(effect); break;
|
|
case CombatEffect::WORM: worm_update(effect); break;
|
|
case CombatEffect::BLOOD_DROP: blood_drop_update(effect); break;
|
|
case CombatEffect::BLOOD_GUSH:
|
|
if (!effect.parent) effect.Remove();
|
|
break;
|
|
case CombatEffect::LARGE_BLOOD_EXPLOSION:
|
|
if (!sprite.IsFinished()) break;
|
|
sprite.Play("Idle");
|
|
effect.sortingLayer = SORTING_BACKGROUND;
|
|
effect.AddEntityFlags(FLAG_RENDER_FLOOR);
|
|
break;
|
|
default: poof_update(effect); break;
|
|
}
|
|
return EFFECT_UPDATE_FINISH;
|
|
}
|