cntrl/src/render/presenter.cpp

556 lines
26 KiB
C++

#include "render/presenter.hpp"
#include "rlgl.h"
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstring>
namespace {
Color projectile_color(WeaponType type) {
switch (type) {
case WeaponType::Spin: return Color{255, 240, 180, 255};
case WeaponType::Shatter: return Color{255, 170, 90, 255};
case WeaponType::Charge: return Color{255, 70, 60, 255};
case WeaponType::Launch: return Color{140, 220, 200, 255};
}
return WHITE;
}
float projectile_size(WeaponType type) {
return type == WeaponType::Charge ? 1.1f : 0.45f;
}
Texture2D load_glow_sprite() {
const char* rel = "assets/sprites/glow.png";
if (FileExists(rel)) return LoadTexture(rel);
const char* alt = TextFormat("%s../assets/sprites/glow.png",
GetApplicationDirectory());
if (FileExists(alt)) return LoadTexture(alt);
return Texture2D{};
}
void draw_blob_shadow(const Vec2& pos, float radius) {
DrawCylinder({pos.x, 0.02f, pos.y}, radius * 1.15f, radius * 1.15f, 0.02f, 12,
Color{0, 0, 0, 80});
}
float actor_flash(float timer, float scale) {
return timer <= 0.0f ? 0.0f : std::min(1.0f, timer * scale);
}
// Glow colors per world-object kind (§4.6): the scene carries a faint
// readable signal so the player can see what they're about to catch.
Color world_object_color(const WorldObject& obj) {
const char* name = obj.name;
if (std::strcmp(name, "SLOW") == 0) return Color{70, 130, 190, 200};
if (std::strcmp(name, "VULNERABLE") == 0) return Color{200, 40, 40, 200};
if (std::strcmp(name, "DOT") == 0) return Color{200, 30, 30, 200};
if (std::strcmp(name, "TAKEN") == 0) return Color{255, 150, 40, 200};
if (std::strcmp(name, "CONFUSE") == 0) return Color{245, 197, 24, 200};
return Color{200, 200, 205, 200};
}
} // namespace
void Presenter::spawn_sparks(Vec2 pos, float height, Color color, int count,
float speed) {
for (int i = 0; i < count && sparks_.size() < 160; ++i) {
const float angle = static_cast<float>(GetRandomValue(0, 360)) * DEG2RAD;
const float jitter = static_cast<float>(GetRandomValue(40, 120)) / 100.0f;
const float lift = static_cast<float>(GetRandomValue(120, 320)) / 100.0f;
sparks_.push_back(Spark{
{pos.x + static_cast<float>(GetRandomValue(-10, 10)) / 40.0f, height,
pos.y + static_cast<float>(GetRandomValue(-10, 10)) / 40.0f},
{std::cos(angle) * speed * jitter, lift,
std::sin(angle) * speed * jitter},
color,
0.0f,
static_cast<float>(GetRandomValue(50, 90)) / 100.0f,
static_cast<float>(GetRandomValue(14, 26)) / 100.0f});
}
}
void Presenter::init(float arena_half) {
camera_.position = {0.0f, 18.0f, 14.0f};
camera_.target = {0.0f, 0.0f, 0.0f};
camera_.up = {0.0f, 1.0f, 0.0f};
camera_.fovy = 48.0f; // wide tactical view: horde awareness over detail
camera_.projection = CAMERA_PERSPECTIVE;
Image img = GenImageGradientRadial(64, 64, 0.0f, WHITE, Color{255, 255, 255, 0});
soft_disc_ = LoadTextureFromImage(img);
UnloadImage(img);
spr_glow_ = load_glow_sprite();
models_.init();
concrete_.init(arena_half);
aura_.init();
damage_numbers_.reserve(64);
sparks_.reserve(160);
}
void Presenter::shutdown() {
aura_.shutdown();
concrete_.shutdown();
models_.shutdown();
if (spr_glow_.id != 0) UnloadTexture(spr_glow_);
UnloadTexture(soft_disc_);
}
void Presenter::draw_environment(const Game& game) {
const float arena = game.config.arena_half;
const float corruption = game.corruption.value();
// All concrete (floor, curbs, pillars, door frame) is one merged, triplanar
// mesh using the same 2K PBR maps as the Blender diorama.
concrete_.draw(corruption, camera_.position);
const bool concrete_fallback = !concrete_.ready();
if (concrete_fallback) {
DrawCube({0.0f, -0.5f, 0.0f}, arena * 2.0f + 40.0f, 1.0f,
arena * 2.0f + 40.0f, Color{43, 43, 47, 255});
}
// Painted walkway lines.
const Color line{150, 147, 138, 255};
DrawCube({-12.0f, 0.012f, 0.0f}, 0.18f, 0.024f, arena * 2.0f, line);
DrawCube({12.0f, 0.012f, 0.0f}, 0.18f, 0.024f, arena * 2.0f, line);
DrawCube({0.0f, 0.012f, -12.0f}, arena * 2.0f, 0.024f, 0.18f, line);
DrawCube({0.0f, 0.012f, 12.0f}, arena * 2.0f, 0.024f, 0.18f, line);
// Signal-red carpet runners: deep pile, worn lanes and panel seams.
const Color carpet{112, 12, 22, 255};
const Color carpet_edge{62, 6, 12, 255};
DrawCube({0.0f, 0.03f, 5.0f}, 6.0f, 0.06f, 26.0f, carpet);
DrawCube({0.0f, 0.034f, 11.0f}, 26.0f, 0.068f, 5.0f, carpet);
DrawCube({-2.82f, 0.033f, 5.0f}, 0.34f, 0.066f, 26.0f, carpet_edge);
DrawCube({2.82f, 0.033f, 5.0f}, 0.34f, 0.066f, 26.0f, carpet_edge);
DrawCube({0.0f, 0.036f, 8.4f}, 26.0f, 0.072f, 0.34f, carpet_edge);
DrawCube({0.0f, 0.036f, 13.6f}, 26.0f, 0.072f, 0.34f, carpet_edge);
for (float z = -6.0f; z <= 16.0f; z += 4.0f) {
DrawCube({0.0f, 0.061f, z}, 5.7f, 0.004f, 0.05f,
Color{66, 7, 13, 255});
}
for (float x = -11.0f; x <= 11.0f; x += 4.0f) {
DrawCube({x, 0.07f, 11.0f}, 0.06f, 0.004f, 4.6f,
Color{66, 7, 13, 255});
}
for (float x : {-1.35f, 1.35f}) {
DrawCube({x, 0.063f, 5.0f}, 0.7f, 0.003f, 24.0f,
Color{90, 9, 17, 255});
}
const float carpet_scuffs[][4] = {
{-1.2f, -2.0f, 0.75f, 0.6f}, {1.5f, 2.4f, 0.55f, 0.5f},
{-0.9f, 7.5f, 0.9f, 0.7f}, {1.1f, 13.5f, 0.65f, 0.6f},
{-2.0f, 16.0f, 0.5f, 0.5f}, {-6.5f, 11.0f, 0.8f, 0.6f},
{4.0f, 11.0f, 0.7f, 0.5f}, {8.5f, 11.0f, 0.9f, 0.7f},
};
for (const auto& s : carpet_scuffs) {
DrawCylinder({s[0], 0.067f, s[1]}, s[2], s[2] * 1.2f, 0.006f, 9,
Color{64, 6, 13, static_cast<unsigned char>(120 * s[3])});
}
// Spilled toner / scorched stains and redacted paper scraps break up the
// otherwise uniform concrete without touching the tactical lanes.
const float stains[][4] = {
{-9.0f, -14.0f, 1.8f, 0.7f}, {8.0f, -11.0f, 1.2f, 0.5f},
{-16.0f, 4.0f, 2.2f, 0.6f}, {12.5f, 12.0f, 1.6f, 0.8f},
{-5.0f, 18.0f, 1.4f, 0.5f}, {17.0f, -3.0f, 1.9f, 0.7f},
{-19.0f, -8.0f, 1.5f, 0.6f}, {3.0f, -20.0f, 2.1f, 0.7f},
};
for (const auto& s : stains) {
DrawCylinder({s[0], 0.016f, s[1]}, s[2], s[2], 0.012f, 10,
Color{28, 12, 14, static_cast<unsigned char>(55 * s[3])});
}
const float scraps[][2] = {
{-7.5f, -9.0f}, {-6.8f, -9.6f}, {5.5f, -15.0f}, {9.5f, 6.5f},
{10.2f, 7.1f}, {-14.0f, 11.5f}, {15.5f, -9.0f}, {-17.0f, -13.0f},
{2.0f, 20.0f}, {-3.0f, -17.0f}, {12.0f, 19.0f}, {-11.0f, 1.5f},
};
for (int i = 0; i < 12; ++i) {
const float x = scraps[i][0], z = scraps[i][1];
DrawCube({x, 0.022f, z}, 0.28f, 0.012f, 0.38f,
(i % 3 == 0) ? Color{90, 20, 26, 255} : Color{198, 192, 176, 255});
}
for (const float x : {-8.6f, 8.6f}) {
DrawCube({x, 0.03f, 0.0f}, 0.09f, 0.03f, 34.0f,
Color{20, 20, 24, 255});
}
// Perimeter curbs (the textured versions live in ConcreteMaterial).
if (concrete_fallback) {
const Color wall{58, 58, 64, 255};
DrawCube({0.0f, 0.6f, -(arena + 1.0f)}, arena * 2.0f + 4.0f, 1.2f, 1.0f, wall);
DrawCube({0.0f, 0.6f, arena + 1.0f}, arena * 2.0f + 4.0f, 1.2f, 1.0f, wall);
DrawCube({-(arena + 1.0f), 0.6f, 0.0f}, 1.0f, 1.2f, arena * 2.0f + 4.0f, wall);
DrawCube({arena + 1.0f, 0.6f, 0.0f}, 1.0f, 1.2f, arena * 2.0f + 4.0f, wall);
}
// Outer service band: the textured floor continues past the play curb, so
// dress it with dark plant blocks and dim spill. A player hugging a wall
// then sees more facility instead of an empty unlit void.
for (int side = -1; side <= 1; side += 2) {
const float x = side * (arena + 6.0f);
for (float z = -arena; z <= arena + 12.0f; z += 9.0f) {
DrawCube({x, 0.85f, z}, 1.6f, 1.7f, 1.6f, Color{34, 34, 38, 255});
DrawCube({x, 1.75f, z}, 1.8f, 0.12f, 1.8f, Color{56, 56, 61, 255});
}
const float z = side * (arena + 7.0f);
for (float x2 = -arena; x2 <= arena + 10.0f; x2 += 9.0f) {
DrawCube({x2, 0.75f, z}, 1.5f, 1.5f, 1.5f, Color{34, 34, 38, 255});
DrawCube({x2, 1.56f, z}, 1.7f, 0.12f, 1.7f, Color{56, 56, 61, 255});
}
for (float z2 = -arena; z2 <= arena; z2 += 12.0f) {
DrawCylinder({side * (arena + 8.0f), 0.05f, z2}, 3.2f, 3.2f, 0.02f,
12, Color{190, 186, 164, 12});
DrawCylinder({z2, 0.05f, side * (arena + 8.0f)}, 3.2f, 3.2f, 0.02f,
12, Color{190, 186, 164, 12});
}
}
// Fluorescent strips live at curb height — the tactical camera sits above
// the room, so a real ceiling would only occlude the play field. The z=-8
// row is dead: the sector is failing as containment decays. The
// lightswitch ritual (§2.3) revives it when it completes.
const bool lights_revived =
game.ritual_system.type() == RitualType::Lightswitch
&& game.ritual_system.complete();
for (const float z : {-16.0f, -8.0f, 0.0f, 8.0f, 16.0f}) {
const bool dead = ((z == -8.0f && !lights_revived)
|| (z == 16.0f && corruption > 0.7f));
for (const float x : {-arena, arena}) {
const float inward = x > 0.0f ? -1.0f : 1.0f;
DrawCube({x, 1.22f, z}, 0.7f, 0.16f, 6.0f, Color{22, 22, 25, 255});
DrawCube({x + inward * 0.36f, 1.22f, z}, 0.06f, 0.07f, 5.6f,
dead ? Color{90, 26, 28, 255} : Color{205, 202, 186, 255});
if (!dead) {
DrawCylinder({x + inward * 2.2f, 0.05f, z}, 2.6f, 2.6f,
0.02f, 12, Color{220, 214, 190, 10});
}
}
}
// Lightswitch prop (§2.3): a wall plate at the lightswitch, near the dead
// beam strip — reads bright once the lightswitch ritual is complete.
models_.draw(ActorModel::Switch,
{RitualSystem::kLightSwitchPos.x, 0.0f, RitualSystem::kLightSwitchPos.y},
0.0f, 1.0f,
lights_revived ? Color{240, 230, 180, 255} : WHITE);
// Threshold door + hazard stripes (the run's exit).
const float door_z = arena + 0.45f;
if (concrete_fallback) {
DrawCube({0.0f, 2.9f, door_z}, 5.6f, 5.8f, 0.34f, Color{28, 28, 32, 255});
}
DrawCube({0.0f, 2.85f, door_z - 0.2f}, 3.7f, 5.1f, 0.1f,
Color{190, 28, 38, 255}); // Hiss glow bleeding through
for (int i = 0; i < 10; ++i) {
const float x0 = -2.31f + i * 0.462f;
DrawCube({x0, 0.045f, arena - 0.6f}, 0.23f, 0.055f, 1.1f,
(i % 2 == 0) ? Color{198, 153, 13, 255} : Color{20, 20, 22, 255});
}
DrawCube({-10.0f, 2.4f, door_z - 0.2f}, 1.7f, 0.52f, 0.12f,
Color{46, 170, 76, 255});
DrawCube({10.0f, 2.4f, door_z - 0.2f}, 1.7f, 0.52f, 0.12f,
Color{46, 170, 76, 255});
DrawCube({0.0f, 1.45f, arena + 0.5f}, 38.0f, 0.12f, 0.3f,
Color{120, 42, 44, 255});
// Hiss light spill pools widen as the House decays.
const unsigned char hiss_alpha =
static_cast<unsigned char>(std::min<int>(70, 12 + corruption * 28));
DrawCylinder({0.0f, 0.07f, arena - 3.0f}, 5.0f + corruption, 5.0f + corruption,
0.02f, 16, Color{200, 24, 34, hiss_alpha});
DrawCylinder({-arena + 4.0f, 0.07f, -10.0f}, 3.2f, 3.2f, 0.02f, 12,
Color{190, 20, 30, static_cast<unsigned char>(hiss_alpha / 2)});
// Pillars with Hiss bands, dark bases and redacted signage.
const Vector3 pillars[] = {
{-18.0f, 2.0f, -18.0f}, {18.0f, 2.0f, -18.0f},
{-18.0f, 2.0f, 18.0f}, {18.0f, 2.0f, 18.0f},
{0.0f, 2.0f, -21.0f}, {0.0f, 2.0f, 21.0f},
{-21.0f, 2.0f, 0.0f}, {21.0f, 2.0f, 0.0f},
};
for (std::size_t i = 0; i < sizeof(pillars) / sizeof(pillars[0]); ++i) {
const Vector3& pos = pillars[i];
if (concrete_fallback) {
DrawCube(pos, 2.0f, 4.0f, 2.0f, Color{66, 66, 72, 255});
DrawCube({pos.x, 0.22f, pos.z}, 2.5f, 0.44f, 2.5f,
Color{28, 28, 32, 255});
}
DrawCube({pos.x, 2.55f, pos.z}, 2.46f, 0.5f, 2.46f, carpet);
if (i < 4) {
DrawCube({pos.x, 3.35f, pos.z - 1.03f}, 1.3f, 0.42f, 0.05f,
Color{232, 228, 216, 255});
DrawCube({pos.x - 0.2f, 3.35f, pos.z - 1.07f}, 0.7f, 0.1f, 0.02f,
Color{17, 17, 17, 255});
}
}
// S11: Objects of Power + set dressing. Sculpted GLBs share the actor
// shader; fixed placements keep the tactical lanes clear.
const float t = anim_time_;
// Objects of Power get a restrained idle so they feel alive without
// pulling focus from combat. Furniture (cabinets/crates) stays planted.
models_.draw(ActorModel::Hotline,
{-15.0f, std::sin(t * 2.3f) * 0.012f, 16.0f},
std::atan2(15.0f, -16.0f) + std::sin(t * 1.1f) * 0.05f,
1.0f, WHITE);
const float flick = static_cast<unsigned char>(
235.0f + 20.0f * (0.5f + 0.5f * std::sin(t * 13.0f) * std::sin(t * 5.0f)));
models_.draw(ActorModel::TV, {13.0f, 0.0f, 17.0f},
std::atan2(-13.0f, -17.0f) + std::sin(t * 0.8f) * 0.025f,
1.0f,
game.ritual_system.complete() ? Color{255, 250, 220, 255}
: Color{flick, flick, flick, 255});
models_.draw(ActorModel::Pedestal, {-7.0f, 0.0f, 10.5f}, 0.0f,
1.0f + std::sin(t * 1.6f) * 0.012f, WHITE);
models_.draw(ActorModel::Duck,
{7.0f, std::sin(t * 2.0f) * 0.025f, 10.5f},
std::sin(t * 1.4f) * 0.09f, 1.0f, WHITE);
for (const float z : {-6.0f, -4.4f, -2.8f}) {
models_.draw(ActorModel::Cabinet, {21.5f, 0.0f, z}, -1.5708f,
1.0f, WHITE);
}
models_.draw(ActorModel::Crate, {18.0f, 0.0f, 6.0f}, 0.4f, 1.0f, WHITE);
models_.draw(ActorModel::Crate, {-17.5f, 0.0f, 3.0f}, -0.7f, 1.0f, WHITE);
models_.draw(ActorModel::Crate, {16.0f, 0.0f, -12.0f}, 1.1f, 1.0f, WHITE);
// Denser centre-adjacent dressing; the carpet cross and combat lanes stay
// clear, but the arena no longer reads as an empty floor.
models_.draw(ActorModel::Crate, {-11.0f, 0.0f, 8.0f}, 0.25f, 0.85f, WHITE);
models_.draw(ActorModel::Crate, {11.5f, 0.0f, 4.0f}, -0.5f, 0.9f, WHITE);
models_.draw(ActorModel::Cabinet, {-21.6f, 0.0f, -4.0f}, 1.5708f,
1.0f, WHITE);
models_.draw(ActorModel::Cabinet, {-21.6f, 0.0f, -2.6f}, 1.5708f,
1.0f, WHITE);
const float debris_specs[][4] = {
{-14.0f, 0.35f, 9.0f, 1.2f}, {15.0f, 0.35f, -7.0f, 0.3f},
{-12.0f, 0.35f, -12.0f, 2.1f},
};
const float debris_scales[] = {0.6f, 0.65f, 0.55f};
for (int i = 0; i < 3; ++i) {
const auto& d = debris_specs[i];
models_.draw(ActorModel::Debris,
{d[0], d[1] + std::sin(t * 0.9f + i * 2.1f) * 0.035f, d[2]},
d[3] + t * 0.12f, debris_scales[i], WHITE);
}
// Hiss-corrupted slabs drift slowly above the playfield (reference art).
const float slabs[][4] = {
{14.0f, 4.6f, 12.0f, 0.0f}, {-13.0f, 5.2f, 7.0f, 1.7f},
{9.0f, 3.8f, -13.0f, 0.6f}, {-9.0f, 4.2f, -10.0f, 2.3f},
};
for (const auto& s : slabs) {
const float bob = std::sin(anim_time_ * 0.7f + s[3]) * 0.18f;
models_.draw(ActorModel::Debris, {s[0], s[1] + bob, s[2]},
anim_time_ * 0.08f + s[3], 1.0f, WHITE);
}
// Scattered grime patches break up the slab's flat colour.
const Vector3 grime[] = {{-9.0f, 0.0f, -7.0f}, {8.0f, 0.0f, -14.0f},
{-16.0f, 0.0f, 9.0f}, {14.0f, 0.0f, 4.0f}};
for (const Vector3& g : grime) {
DrawCylinder({g.x, 0.016f, g.z}, 1.6f, 1.8f, 0.01f, 9, Color{30, 30, 33, 70});
}
}
void Presenter::draw_scene(Game& game) {
for (int i = 0; i < game.events.count; ++i) {
const GameEvent& e = game.events.items[i];
if (e.type == EventType::PlayerDamaged) {
shake_ = std::max(shake_, 0.45f);
damage_flash_ = 1.0f;
spawn_sparks(e.pos, 1.0f, Color{255, 80, 70, 255}, 6, 3.0f);
} else if (e.type == EventType::EnemyKilled) {
shake_ = std::max(shake_, 0.10f);
spawn_sparks(e.pos, 0.9f, Color{255, 60, 50, 255}, 8, 3.4f);
} else if (e.type == EventType::TierUp) {
shake_ = std::max(shake_, 0.60f);
tier_wave_pending_ = true;
spawn_sparks(game.player.pos, 0.8f, Color{255, 210, 90, 255}, 12, 4.0f);
} else if (e.type == EventType::EnemyHit) {
if (damage_numbers_.size() < 48) {
damage_numbers_.push_back(
{e.pos + Vec2{static_cast<float>(GetRandomValue(-8, 8)) / 20.0f,
static_cast<float>(GetRandomValue(-8, 8)) / 20.0f},
e.magnitude, 0.0f});
}
spawn_sparks(e.pos, 1.1f, Color{255, 240, 200, 255}, 3, 2.4f);
}
}
shake_ = std::max(0.0f, shake_ - 0.06f);
const float frame_dt = GetFrameTime();
anim_time_ += frame_dt;
aura_.update(frame_dt);
damage_flash_ = std::max(0.0f, damage_flash_ - frame_dt * 2.2f);
for (DamageNumber& n : damage_numbers_) n.age += frame_dt;
damage_numbers_.erase(
std::remove_if(damage_numbers_.begin(), damage_numbers_.end(),
[](const DamageNumber& n) { return n.age > 0.8f; }),
damage_numbers_.end());
for (Spark& s : sparks_) {
s.age += frame_dt;
s.pos.x += s.vel.x * frame_dt;
s.pos.y += s.vel.y * frame_dt;
s.pos.z += s.vel.z * frame_dt;
s.vel.y -= 9.0f * frame_dt;
s.vel.x *= 0.96f;
s.vel.z *= 0.96f;
if (s.pos.y < 0.08f) {
s.pos.y = 0.08f;
s.vel.y *= -0.3f;
}
}
sparks_.erase(std::remove_if(sparks_.begin(), sparks_.end(),
[](const Spark& s) { return s.age > s.life; }),
sparks_.end());
const float sx = static_cast<float>(GetRandomValue(-100, 100)) / 100.0f * shake_;
const float sy = static_cast<float>(GetRandomValue(-100, 100)) / 100.0f * shake_;
const Vec2 p = game.player.pos;
// Keep the arena rim out of frame when the player hugs a wall — showing
// the unlit floor beyond the curb breaks the contained-facility illusion.
const float margin = 5.0f;
const float bound = game.config.arena_half - margin;
const float cx = std::clamp(p.x, -bound, bound);
const float cz = std::clamp(p.y, -bound, bound);
camera_.position = {cx + sx * 0.6f, 18.0f + sy * 0.4f, cz + 14.0f};
camera_.target = {cx + sx * 0.3f, 0.0f, cz};
if (tier_wave_pending_) {
// Reusable scene wave: also callable for boss entrances / events.
aura_.spawn_ground({p.x, 0.09f, p.y}, 11.0f, 2.6f, anim_time_);
tier_wave_pending_ = false;
}
models_.begin_frame(anim_time_, game.corruption.value(), camera_.position);
aura_.begin_frame(anim_time_, game.corruption.value());
BeginMode3D(camera_);
draw_environment(game);
// Blob shadows sit under every actor.
draw_blob_shadow(p, 0.8f);
for (const Enemy& e : game.enemy_system.enemies) {
draw_blob_shadow(e.pos, e.radius * 0.85f);
}
// Hiss corruption is now baked into the human Resonant models
// (build_enemies.py) and animated by the actor shader — no detached
// aura blob. Only event ground waves remain here.
rlDisableDepthMask();
aura_.draw_ground_waves();
rlEnableDepthMask();
// Player: derive facing from motion (presentation-only, no sim change).
const Vec2 moved = p - last_player_pos_;
if (length_sq(moved) > 1e-5f) player_yaw_ = std::atan2(moved.x, moved.y);
last_player_pos_ = p;
const float guard_bob = std::sin(anim_time_ * 6.0f) * 0.02f;
const float player_walk = std::min(1.0f, length(moved) * 14.0f);
const float player_flash = actor_flash(game.player.hit_flash, 4.0f);
models_.draw(ActorModel::Guard, {p.x, guard_bob, p.y}, player_yaw_, 1.0f,
WHITE, player_flash, true, player_walk, player_flash,
anim_time_);
// Enemies face the player; Hiss units add a nervous jitter.
for (const Enemy& e : game.enemy_system.enemies) {
const Vec2 dir = p - e.pos;
float yaw = std::atan2(dir.x, dir.y);
const bool mold = e.type == EnemyType::MoldSpore;
if (!mold) yaw += std::sin(e.bob_phase * 3.0f) * 0.11f;
const float bob = std::sin(e.bob_phase) * (mold ? 0.02f : 0.08f);
const ActorModel model = mold ? ActorModel::MoldSpore
: (e.type == EnemyType::HissBrute ? ActorModel::HissBrute
: (e.type == EnemyType::HissGhost ? ActorModel::HissGhost
: ActorModel::HissStaff));
const float flash = actor_flash(e.hit_flash, 6.0f);
const float walk = std::min(1.0f, e.speed / 4.5f);
models_.draw(model, {e.pos.x, bob, e.pos.y}, yaw, 1.0f, WHITE,
flash, !mold, walk, flash, e.bob_phase);
}
// Enemy drops: small cyan Resonance crystals, spun by the crystal rig.
const Texture2D glow = spr_glow_.id != 0 ? spr_glow_ : soft_disc_;
for (const XpShard& s : game.pickup_system.shards) {
const float spin = anim_time_ * 2.6f + s.pos.x * 0.7f;
const float bob = std::sin(spin * 1.3f) * 0.035f;
DrawBillboardRec(camera_, glow,
Rectangle{0.0f, 0.0f, static_cast<float>(glow.width),
static_cast<float>(glow.height)},
{s.pos.x, 0.22f + bob, s.pos.y},
Vector2{0.62f, 0.62f}, Color{70, 225, 255, 110});
models_.draw(ActorModel::Shard, {s.pos.x, 0.18f + bob, s.pos.y}, spin,
0.7f, WHITE, 0.0f, false, 0.0f, 0.0f,
anim_time_ + s.pos.x * 0.7f);
}
// World objects of power: small camera-facing glows (§4.6).
const Texture2D object_glow = spr_glow_.id != 0 ? spr_glow_ : soft_disc_;
for (int i = 0; i < game.buff_system.world_object_count(); ++i) {
const WorldObject& obj = game.buff_system.world_object(i);
const Color c = world_object_color(obj);
DrawBillboardRec(camera_, object_glow,
Rectangle{0.0f, 0.0f, static_cast<float>(object_glow.width),
static_cast<float>(object_glow.height)},
{obj.pos.x, 0.75f, obj.pos.y}, Vector2{0.45f, 0.45f}, c);
}
// Projectile glow remains camera-facing — it is an FX, not a card.
for (const Projectile& pr : game.weapon_system.projectiles) {
const float s = projectile_size(pr.source);
DrawBillboardRec(camera_, glow,
Rectangle{0.0f, 0.0f, static_cast<float>(glow.width),
static_cast<float>(glow.height)},
{pr.pos.x, 1.1f, pr.pos.y}, Vector2{s, s},
projectile_color(pr.source));
}
// Light particles from hits, kills and tier-ups — camera-facing glows.
for (const Spark& s : sparks_) {
const float fade = 1.0f - s.age / s.life;
Color tint = s.color;
tint.a = static_cast<unsigned char>(255.0f * fade * fade);
DrawBillboardRec(camera_, glow,
Rectangle{0.0f, 0.0f, static_cast<float>(glow.width),
static_cast<float>(glow.height)},
s.pos, Vector2{s.size, s.size}, tint);
}
EndMode3D();
// World-object flavor names hover near each glow.
for (int i = 0; i < game.buff_system.world_object_count(); ++i) {
const WorldObject& obj = game.buff_system.world_object(i);
if (obj.name[0] == '\0') continue;
const Vector2 screen = GetWorldToScreen({obj.pos.x, 0.75f, obj.pos.y}, camera_);
DrawText(obj.name, static_cast<int>(screen.x) - MeasureText(obj.name, 12) / 2,
static_cast<int>(screen.y) - 14, 12, Color{255, 255, 255, 200});
}
// World-anchored health bars for damaged enemies.
for (const Enemy& e : game.enemy_system.enemies) {
if (e.hp >= e.max_hp) continue;
const ActorModel model = e.type == EnemyType::MoldSpore ? ActorModel::MoldSpore
: (e.type == EnemyType::HissBrute ? ActorModel::HissBrute
: (e.type == EnemyType::HissGhost ? ActorModel::HissGhost
: ActorModel::HissStaff));
const Vector2 screen = GetWorldToScreen(
{e.pos.x, ModelBank::height(model) + 0.25f, e.pos.y}, camera_);
const float w = 46.0f;
const float frac = std::max(0.0f, e.hp / e.max_hp);
DrawRectangle(screen.x - w / 2.0f, screen.y, w, 5, Color{20, 20, 22, 200});
DrawRectangle(screen.x - w / 2.0f, screen.y, w * frac, 5, Color{200, 60, 60, 235});
}
// Floating damage numbers.
for (const DamageNumber& n : damage_numbers_) {
const float t = n.age / 0.8f;
const Vector2 screen = GetWorldToScreen(
{n.pos.x, 1.6f + n.age * 1.8f, n.pos.y}, camera_);
const unsigned char alpha = static_cast<unsigned char>(255.0f * (1.0f - t));
const char* text = TextFormat("%d", static_cast<int>(n.value + 0.5f));
DrawText(text, static_cast<int>(screen.x) - 10, static_cast<int>(screen.y), 20,
Color{255, 224, 130, alpha});
}
}