Sort src/ into subsystem folders (engine, game, level, level/grid, entity with player, npc, boss, familiar, effect, pickup and weapon, ui, ui/menu, lua, online), drop each folder's prefix from file names, include by path from src/, glob src/ recursively
This commit is contained in:
1 parent
9254158eef
commit
7d3cf33c20
706 files changed
+5337
-5336
No files matched your search
@@ -0,0 +1,240 @@
|
||||
#include "entity/pickup/item_overlay.h"
|
||||
#include "entity/player/player.h"
|
||||
#include "game/game.h"
|
||||
#include "engine/kage_graphics.h"
|
||||
#include "level/level.h"
|
||||
#include "engine/log.h"
|
||||
#include "game/manager.h"
|
||||
#include "engine/render_passes.h"
|
||||
#include "level/room.h"
|
||||
#include <cmath>
|
||||
|
||||
constexpr int SLEEP_SOUL_HEARTS = 6;
|
||||
constexpr int EVENT_COUNTER_SLEEPS = 202;
|
||||
constexpr const char* EVENT_SOUND = "Sound";
|
||||
constexpr const char* EVENT_SLEEP_FILL_HP = "SleepFillHP";
|
||||
constexpr const char* EVENT_TRANSITION = "Transition";
|
||||
constexpr const char* EVENT_STATIC = "Static";
|
||||
constexpr const char* ANIMATION_TRANSFORM = "Transform";
|
||||
|
||||
// Home's stage and room: the bedroom that turns into the night of Dogma, and the stage bar icon it takes.
|
||||
constexpr int HOME_BEDROOM_SUBTYPE = 2;
|
||||
constexpr int STAGE_ICON_HOME_GREED = 18;
|
||||
|
||||
// Mega Mush's transformation: the dim over the screen, and where the player shows on it, nearer the middle.
|
||||
constexpr float MEGA_MUSH_DIM = 0.4f;
|
||||
constexpr float MEGA_MUSH_WIDTH = 338;
|
||||
constexpr float MEGA_MUSH_HEIGHT = 182;
|
||||
constexpr float MEGA_MUSH_ORIGIN_X = 60;
|
||||
constexpr float MEGA_MUSH_ORIGIN_Y = 140;
|
||||
constexpr float MEGA_MUSH_SCALE = 0.65f;
|
||||
|
||||
// A sound of Mega Mush's transformation on one of its frames.
|
||||
struct TransformSound
|
||||
{
|
||||
int frame;
|
||||
int sound;
|
||||
int frameDelay;
|
||||
float pitch;
|
||||
};
|
||||
|
||||
constexpr TransformSound TRANSFORM_SOUNDS[] = {{1, SOUND_VAMP_GULP, 2, 1},
|
||||
{6, SOUND_THUMBSUP, 1, 0.8f},
|
||||
{11, SOUND_THUMBSUP, 1, 1},
|
||||
{16, SOUND_THUMBSUP, 1, 1.2f}};
|
||||
|
||||
// One step of an overlay sprite: a frame, or its animation's last frame when finishing.
|
||||
static void sprite_step(ANM2& overlay, OverlayUpdate mode)
|
||||
{
|
||||
if (mode == OVERLAY_UPDATE_PLAY)
|
||||
overlay.Update();
|
||||
else if (overlay.animState.animData)
|
||||
overlay.animState.AdvancePosition(overlay.animState.animData->length - 1);
|
||||
}
|
||||
|
||||
// Whether an overlay sprite's animation still plays.
|
||||
static bool is_sprite_playing(const ANM2& overlay)
|
||||
{
|
||||
return overlay.animState.animData && overlay.animState.isPlaying;
|
||||
}
|
||||
|
||||
// A sound at a frame delay and pitch, after the seed's fart override.
|
||||
static void overlay_sound_play(int sound, int frameDelay, float pitch)
|
||||
{
|
||||
seed_fart_sound_override(&sound);
|
||||
g_manager->sfxManager.Play(sound, {.frameDelay = frameDelay, .pitch = pitch});
|
||||
}
|
||||
|
||||
// Sleeping's healing: each player but Tainted Soul fills its red hearts, or takes three soul hearts without heart
|
||||
// containers, with a power up sound unless finishing. The game counts the sleep.
|
||||
static void sleep_heal(OverlayUpdate mode)
|
||||
{
|
||||
for (Entity_Player* player : g_game->playerManager.playerList)
|
||||
{
|
||||
if (player->playerType == PLAYER_THESOUL_B)
|
||||
continue;
|
||||
|
||||
HealthType health = player->GetHealthType();
|
||||
bool isRedOnly = health == HEALTH_SOUL || health == HEALTH_NO_HEALTH;
|
||||
int heartLimit = isRedOnly ? player->maxHearts : player->maxHearts + player->boneHearts * 2;
|
||||
if (heartLimit <= 0)
|
||||
player->AddSoulHearts(SLEEP_SOUL_HEARTS, false);
|
||||
else if (player->redHearts < heartLimit)
|
||||
player->SetFullHearts();
|
||||
else
|
||||
continue;
|
||||
|
||||
if (mode == OVERLAY_UPDATE_PLAY)
|
||||
sound_play(SOUND_POWERUP1);
|
||||
}
|
||||
g_manager->persistentGameData.IncreaseEventCounter(EVENT_COUNTER_SLEEPS, 1);
|
||||
}
|
||||
|
||||
// The nightmare of the bed in Home: its transition queues the nightmare (Dogma's outside Greed mode) unless finishing,
|
||||
// and Home's bedroom turns to night. Its static plays the static sound and the room's music again.
|
||||
static void sleep_nightmare_update(ANM2& overlay, OverlayUpdate mode)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
Manager& manager = *g_manager;
|
||||
bool isPlaying = mode == OVERLAY_UPDATE_PLAY;
|
||||
|
||||
if (overlay.animState.IsEventTriggered(EVENT_TRANSITION))
|
||||
{
|
||||
if (isPlaying)
|
||||
{
|
||||
bool isGreed = game.IsGreedMode();
|
||||
manager.nightmareScene.isDogma = !isGreed;
|
||||
manager.nightmareScene.stageIcons[STAGE_HOME] = isGreed ? STAGE_ICON_HOME_GREED : STAGE_ICON_HOME;
|
||||
manager.isNightmarePending = true;
|
||||
manager.pendingNightmareId = 1;
|
||||
}
|
||||
|
||||
RoomConfig_Room* room = game.room->descriptor->data;
|
||||
bool isBedroom = room && room->stageId == STAGE_ID_HOME && room->subtype == HOME_BEDROOM_SUBTYPE;
|
||||
if (isBedroom && game.stage == STAGE_HOME && game.stageType == STAGETYPE_ORIGINAL)
|
||||
{
|
||||
game.SetStage(STAGE_HOME, STAGETYPE_WOTL);
|
||||
game.room->reload_backdrop();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!overlay.animState.IsEventTriggered(EVENT_STATIC) || !isPlaying)
|
||||
return;
|
||||
|
||||
sound_play(SOUND_STATIC);
|
||||
game.room->PlayMusic();
|
||||
manager.musicManager.EnableLayer(0, LAYER_INSTANT);
|
||||
}
|
||||
|
||||
// 009ad210 Shows a giant book: its .anm2 with the entry's spritesheet and recolored layers, playing its animation, at
|
||||
// once or after a delay. An entry without one (Mega Mush's) leaves the sprite empty.
|
||||
void ItemOverlay::Show(int overlayId, int showDelay, Entity_Player* shown)
|
||||
{
|
||||
if ((unsigned)overlayId >= GIANTBOOK_ENTRY_COUNT)
|
||||
return;
|
||||
|
||||
const GiantbookEntry& entry = g_game->giantbookEntries[overlayId];
|
||||
if (entry.anm2Path.empty())
|
||||
sprite.Reset();
|
||||
else
|
||||
{
|
||||
sprite.Load(entry.anm2Path, GRAPHICS_DEFER);
|
||||
if (!entry.gfxPath.empty())
|
||||
sprite.ReplaceSpritesheet(0, entry.gfxPath);
|
||||
sprite.LoadGraphics();
|
||||
}
|
||||
overlayID = overlayId;
|
||||
player = shown;
|
||||
|
||||
if (sprite.isLoaded)
|
||||
{
|
||||
for (const GiantbookLayer& recolor : entry.layers)
|
||||
for (LayerState& layer : sprite.layerStates)
|
||||
if (layer.layerData && layer.layerData->name == recolor.name)
|
||||
layer.color = recolor.color;
|
||||
sprite.Play(entry.animation);
|
||||
}
|
||||
state = showDelay != 0 ? ITEM_OVERLAY_WAITING : ITEM_OVERLAY_ACTIVE;
|
||||
delay = showDelay;
|
||||
}
|
||||
|
||||
// 009aca90 Counts down the delay, then plays the overlay: Mega Mush's transformation with its sounds (the player shows
|
||||
// again once it ends), or the giant book until its animation stops, with the clicker's sound, sleeping's healing
|
||||
// and the nightmare of the bed in Home. Finishing skips the animations to their end and the sounds.
|
||||
void ItemOverlay::Update(OverlayUpdate mode)
|
||||
{
|
||||
if (state == ITEM_OVERLAY_WAITING)
|
||||
{
|
||||
if (--delay < 1)
|
||||
state = ITEM_OVERLAY_ACTIVE;
|
||||
return;
|
||||
}
|
||||
if (state == ITEM_OVERLAY_INACTIVE)
|
||||
return;
|
||||
|
||||
bool isPlaying = mode == OVERLAY_UPDATE_PLAY;
|
||||
if (megaMushPlayerSprite.isLoaded)
|
||||
{
|
||||
sprite_step(megaMushPlayerSprite, mode);
|
||||
if (player && megaMushPlayerSprite.IsPlaying(ANIMATION_TRANSFORM) && isPlaying)
|
||||
{
|
||||
int frame = megaMushPlayerSprite.GetFrame();
|
||||
for (const TransformSound& sound : TRANSFORM_SOUNDS)
|
||||
if (sound.frame == frame)
|
||||
overlay_sound_play(sound.sound, sound.frameDelay, sound.pitch);
|
||||
}
|
||||
}
|
||||
|
||||
if (!sprite.isLoaded)
|
||||
{
|
||||
if (is_sprite_playing(megaMushPlayerSprite))
|
||||
return;
|
||||
if (player)
|
||||
player->isVisible = true;
|
||||
state = ITEM_OVERLAY_INACTIVE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_sprite_playing(sprite))
|
||||
state = ITEM_OVERLAY_INACTIVE;
|
||||
sprite_step(sprite, mode);
|
||||
if (!sprite.animState.animData)
|
||||
return;
|
||||
|
||||
if (sprite.animState.IsEventTriggered(EVENT_SOUND) && overlayID == GIANTBOOK_CLICKER)
|
||||
sound_play(SOUND_STATIC);
|
||||
if (sprite.animState.IsEventTriggered(EVENT_SLEEP_FILL_HP))
|
||||
sleep_heal(mode);
|
||||
if (overlayID == GIANTBOOK_SLEEP_NIGHTMARE)
|
||||
sleep_nightmare_update(sprite, mode);
|
||||
}
|
||||
|
||||
// 009acfe0 Draws the playing overlay: the giant book in the middle of the screen, or for Mega Mush a dim over the
|
||||
// screen with the player's transformation, nearer the middle than the player stands.
|
||||
void ItemOverlay::Render()
|
||||
{
|
||||
if (state == ITEM_OVERLAY_INACTIVE || state == ITEM_OVERLAY_WAITING)
|
||||
return;
|
||||
|
||||
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
||||
Vector screen = vector_make(g_screenWidth, g_screenHeight);
|
||||
if (sprite.isLoaded)
|
||||
sprite.Render({.position = vector_make(screen.x * 0.5f, screen.y * 0.5f)});
|
||||
else if (overlayID == GIANTBOOK_MEGA_MUSH)
|
||||
{
|
||||
graphics.blend_set(KAGE::Graphics::BLEND_NORMAL);
|
||||
render_color_shader_pass(KAGE::Graphics::color_quad_rect({}, screen, kcolor_rgba(0, 0, 0, MEGA_MUSH_DIM)));
|
||||
if (megaMushPlayerSprite.isLoaded && player)
|
||||
{
|
||||
float pixelScale = g_displayPixelRatio * g_screenPointScale;
|
||||
Vector scroll = g_game->room->renderScrollOffset;
|
||||
auto snap = [&](float value) {
|
||||
return std::floor(value * pixelScale + 0.5f) / pixelScale;
|
||||
};
|
||||
float x = (screen.x - MEGA_MUSH_WIDTH) * 0.5f + (player->pos.x - MEGA_MUSH_ORIGIN_X) * MEGA_MUSH_SCALE;
|
||||
float y = (screen.y - MEGA_MUSH_HEIGHT) * 0.5f + (player->pos.y - MEGA_MUSH_ORIGIN_Y) * MEGA_MUSH_SCALE;
|
||||
megaMushPlayerSprite.Render({.position = vector_make(snap(x) + scroll.x, snap(y) + scroll.y)});
|
||||
}
|
||||
}
|
||||
graphics.shader_default_set();
|
||||
}
|
||||
Reference in new issue
Block a user