Third and final layer of the Sump finale, a large round heart chamber. Builds the shell, the heart, hanging signal threads, the causeway and three answer pillars, then runs the stage machine: approach with the question arriving in pieces, the misfits' ceremony answers, the player's choice at a pillar, the heart's reply, and the closing procession loop.
using System;
using System.Collections.Generic;
/// <summary>
/// Layer three, THE HEART: one vast round chamber with the heart hanging in the middle of it,
/// beating slowly (light, size and sound all follow <see cref="SumpFinale.HeartPulse"/>). Every
/// signal the planet ever swallowed hangs here as a thread with a mote of light sliding down it.
/// Along the path in are the misfits' own lost orders, and near the end of it the lizard's: the
/// order fragment from the opening, whole at last.
///
/// There is nothing to get past here. The play idea is the ANSWER:
/// 1. Walking in, the question arrives in pieces (<see cref="FinaleWriting.Question"/>).
/// 2. At the dais the Sump answers together: each healed misfit steps up in turn, the thing it
/// clings to lights, and it gives its orders back as its own answer. The cells come to
/// watch, and nobody runs.
/// 3. The player answers last, by walking to one of three lights and choosing: "We are here"
/// (the cells part and go back to work), "Let us go" (every swallowed signal is released
/// upward in a column of light), "We are staying" (the heart takes on the Sump's colours).
/// All three are always offered; the one that fits how the descent was played burns brighter.
/// 4. The finale takes it from there (closing card, saving, the way back up), while the
/// procession walks slowly round the heart.
/// </summary>
public sealed class FinaleHeart : FinaleLayer
{
// ---- Tuning ---------------------------------------------------------------------------------
public float Radius = 2500f, FloorRadius = 2200f, HeartHeight = 820f, HeartSize = 330f;
public float EntranceDistance = 1900f;
public int Threads = 46;
/// <summary>The question's pieces arrive as the player comes within these distances of the middle.</summary>
public float[] QuestionAt = { 1750f, 1400f, 1050f, 720f, 420f };
/// <summary>Never less than this many seconds between two pieces of it.</summary>
public float QuestionGap = 5.5f;
/// <summary>Seconds each misfit has to give its answer.</summary>
public float AnswerSeconds = 6.5f;
/// <summary>Seconds between the lines of the heart's reply, and how long the whole reply takes.</summary>
public float ReplyEvery = 6f, ReplySeconds = 21f;
public int WatchingCells = 14;
public float DaisRadius = 250f, PillarDistance = 300f, PillarReach = 95f;
static readonly Color Dark = new( 0.16f, 0.04f, 0.04f );
static readonly Color WallHot = new( 0.6f, 0.16f, 0.1f );
static readonly Color HeartCold = new( 0.45f, 0.05f, 0.05f );
static readonly Color HeartHot = new( 1f, 0.36f, 0.2f );
static readonly Color HeartLight = new( 1f, 0.3f, 0.14f );
static readonly Color ThreadTint = new( 0.4f, 0.6f, 0.6f );
static readonly Color OrderGlow = new( 0.35f, 1f, 0.85f ); // the colour of the order fragment in the opening
static readonly Color Pale = new( 0.93f, 0.91f, 0.88f );
public override string Title => "III. THE HEART";
public override string CardLine => "It has been asking the whole time.";
public override IReadOnlyList<string> Chatter => _stage == Stage.Approach ? FinaleWriting.HeartChatter : null;
public override string Objective => _stage switch
{
Stage.Approach => "Go to the heart.",
Stage.Ceremony => "The Sump answers.",
Stage.Choice => "Answer it.",
_ => "",
};
enum Stage { Approach, Ceremony, Choice, Reply, After }
sealed class Thread
{
public GameObject Mote;
public TextRenderer Words;
public Vector3 Foot; // bottom of the thread
public float Length, Speed, Phase;
public Color Colour;
}
sealed class Pillar
{
public GameObject Root;
public PointLight Light;
public Vector3 At;
public string Key, Words, Hint;
public Color Colour;
}
Stage _stage = Stage.Approach;
float _t; // seconds in this stage
readonly List<Thread> _threads = new();
readonly List<FinalePulser> _heartParts = new();
readonly List<FinalePulser> _shell = new();
readonly List<Pillar> _pillars = new();
readonly List<FinaleCell> _watchers = new();
FinaleCellHost _host;
PointLight _heartLight, _floorLight;
GameObject _column;
PointLight _columnLight;
TextRenderer _ownWords;
Vector3 _ownThread;
int _questions;
float _nextQuestion = 1.5f;
bool _ownRead, _saidCells, _saidSuggest;
int _speaker = -1;
float _nextSpeaker;
string _answer = "";
string _suggested = "here";
int _replies;
bool _saidAfter;
Color _patchwork = Color.White;
float _ringTurn;
Vector3 P( float x, float y, float z = 0f ) => Space.Origin + new Vector3( x, y, z );
Vector3 HeartAt => P( 0f, 0f, HeartHeight );
// ---- Building -------------------------------------------------------------------------------
public override void Build()
{
var s = Space;
s.Air( new Color( 0.09f, 0.035f, 0.03f ), new Color( 0.05f, 0.01f, 0.01f ), 900f, 6500f );
s.WaveSpeed = 0.8f;
s.Box( "Heart Floor", P( 0f, 0f, -20f ), new Vector3( Radius * 2f, Radius * 2f, 40f ), (Dark * 0.7f).WithAlpha( 1f ) );
BuildShell();
BuildHeart();
BuildPath();
BuildThreads();
BuildPillars();
_host = s.Root.Components.Create<FinaleCellHost>();
_host.Centre = s.Origin;
_host.HalfX = _host.HalfY = FloorRadius;
_host.FloorZ = s.Origin.z;
_host.Adopt( Player );
_host.Live = false;
// What the Sump looks like as one colour: everybody's own, mixed.
float r = 0f, g = 0f, b = 0f;
int n = 0;
foreach ( var follower in Procession.Followers )
{
var c = follower.Profile?.Primary ?? Color.White;
r += c.r; g += c.g; b += c.b; n++;
}
_patchwork = n > 0 ? new Color( r / n, g / n, b / n ) : new Color( 0.4f, 0.8f, 0.5f );
// Far enough in that the whole column has room to stand behind the player, inside the wall.
Start = P( -EntranceDistance + MathF.Max( Procession.Count - 2, 0 ) * Procession.Spacing, 0f, 4f );
StartYaw = 0f;
PulseFrom = HeartAt;
}
/// <summary>The wall: rings of great swellings, one above the other, closing over the top.</summary>
void BuildShell()
{
var s = Space;
float lump = Radius * 0.175f;
foreach ( float latitude in new[] { 4f, 20f, 36f, 52f, 68f, 84f } )
{
float rad = latitude * MathF.PI / 180f;
float ring = Radius * MathF.Cos( rad );
float z = Radius * MathF.Sin( rad );
int count = Math.Max( 4, (int)MathF.Round( 22f * MathF.Cos( rad ) ) );
for ( int i = 0; i < count; i++ )
{
float yaw = (i + (latitude % 8f) * 0.1f) * 360f / count;
var at = P( 0f, 0f, z ) + Rotation.FromYaw( yaw ).Forward * ring;
var ball = s.Ball( "Heart Wall", at, new Vector3( lump * s.R( 0.95f, 1.15f ), lump * s.R( 0.95f, 1.15f ), lump * s.R( 0.9f, 1.1f ) ), (Dark * s.R( 0.8f, 1.25f )).WithAlpha( 1f ) );
_shell.Add( s.Pulse( ball, WallHot, latitude / 13f + i * 0.05f, 0.04f, 0.55f ) );
}
}
}
void BuildHeart()
{
var s = Space;
var centre = HeartAt;
_heartParts.Add( s.Pulse( s.Ball( "Heart", centre, HeartSize, HeartCold ), HeartHot, 0f, 0.13f, 1f ) );
for ( int i = 0; i < 7; i++ )
{
var off = new Vector3( s.R( -1f, 1f ), s.R( -1f, 1f ), s.R( -0.8f, 0.8f ) ).Normal * (HeartSize * 0.8f);
float size = HeartSize * s.R( 0.45f, 0.7f );
_heartParts.Add( s.Pulse( s.Ball( "Heart Lobe", centre + off, size, (HeartCold * s.R( 0.8f, 1.2f )).WithAlpha( 1f ) ), HeartHot, i * 0.4f, 0.16f, 0.9f ) );
}
// The great vessels: from the heart out to the wall.
for ( int i = 0; i < 6; i++ )
{
float yaw = i * 60f + 25f;
var end = P( 0f, 0f, HeartHeight + s.R( 300f, 1100f ) ) + Rotation.FromYaw( yaw ).Forward * (Radius * 0.9f);
var along = end - centre;
var vessel = s.Box( "Vessel", centre + along * 0.5f, new Vector3( along.Length, 70f, 70f ), (HeartCold * 0.8f).WithAlpha( 1f ), false, Rotation.LookAt( along.Normal, Vector3.Up ) );
_heartParts.Add( s.Pulse( vessel, HeartHot * 0.8f, i * 0.7f, 0.0f, 0.8f ) );
}
_heartLight = s.Light( "Heart Light", centre - Vector3.Up * (HeartSize + 60f), HeartLight * 2.4f, Radius * 1.5f, 1f );
_floorLight = s.Light( "Dais Light", P( 0f, 0f, 220f ), HeartLight * 0.9f, 1300f, 0.7f );
// For "let us go": the column everything leaves by. Dark until then.
_column = s.Box( "Column of Light", P( 0f, 0f, HeartHeight ), new Vector3( 110f, 110f, 50f ), new Color( 0.85f, 1f, 0.95f ), false );
_column.Enabled = false;
_columnLight = s.Light( "Column Light", P( 0f, 0f, HeartHeight + 500f ), Color.Black, Radius * 1.6f );
_columnLight.Enabled = false;
}
/// <summary>The way in: a paler strip of floor from the entrance to a dais under the heart.</summary>
void BuildPath()
{
var s = Space;
float length = EntranceDistance - DaisRadius + 60f;
s.Box( "Causeway", P( -DaisRadius - length * 0.5f + 60f, 0f, 1.5f ), new Vector3( length, 170f, 3f ), (Dark * 1.9f).WithAlpha( 1f ), false );
s.Box( "Dais", P( 0f, 0f, 2.5f ), new Vector3( DaisRadius * 1.7f, DaisRadius * 1.7f, 5f ), (Dark * 2.4f).WithAlpha( 1f ), false, Rotation.FromYaw( 45f ) );
s.Pulse( s.Ball( "Dais Glow", P( 0f, 0f, 3f ), new Vector3( DaisRadius * 0.6f, DaisRadius * 0.6f, 3f ), HeartCold ), HeartHot, 0f, 0.1f, 1f );
// Behind the entrance, the way they came: shut.
s.Box( "Heart Door", P( -EntranceDistance - 170f, 0f, 180f ), new Vector3( 60f, 500f, 400f ), Dark );
}
void BuildThreads()
{
var s = Space;
// Everybody's lost signals, anybody's: thin lines hanging from the dark, a light sliding down each.
for ( int i = 0; i < Threads; i++ )
{
float yaw = s.R( 0f, 360f );
float distance = s.R( DaisRadius + 60f, FloorRadius - 150f );
var foot = P( 0f, 0f ) + Rotation.FromYaw( yaw ).Forward * distance;
var local = foot - s.Origin;
if ( local.x < 0f && MathF.Abs( local.y ) < 260f ) continue; // keep the way in clear
AddThread( foot + Vector3.Up * s.R( 30f, 160f ), s.R( 500f, 1700f ), ThreadTint * s.R( 0.5f, 1f ), null, 0f );
}
// The misfits' own orders, along both sides of the way in, in their own colours.
var followers = Procession.Followers;
for ( int i = 0; i < followers.Count; i++ )
{
var profile = followers[i].Profile;
float x = -EntranceDistance + 320f + i * (EntranceDistance - DaisRadius - 620f) / Math.Max( followers.Count - 1, 1 );
var foot = P( x, (i % 2 == 0 ? 1f : -1f) * 175f, 70f );
AddThread( foot, 1200f, profile.Primary, FinaleWriting.Snippet( profile, s.Rng, 5 ), 11f );
s.Light( "Order Light", foot + Vector3.Up * 60f, profile.Primary * 0.5f, 260f );
}
// And the lizard's. The opening only ever gave "ORDERS... INCOMPLETE".
_ownThread = P( -DaisRadius - 150f, -160f, 60f );
var own = AddThread( _ownThread, 1500f, OrderGlow, "ORDERS... INCOMPLETE", 13f );
_ownWords = own.Words;
s.Light( "Own Order Light", _ownThread + Vector3.Up * 70f, OrderGlow * 0.8f, 380f, 0.3f );
}
Thread AddThread( Vector3 foot, float length, Color colour, string words, float letter )
{
var s = Space;
var tint = colour.WithAlpha( 1f );
s.Box( "Thread", foot + Vector3.Up * (length * 0.5f), new Vector3( 2.5f, 2.5f, length ), tint, false );
var thread = new Thread
{
Mote = s.Ball( "Thread Mote", foot, 5f, Color.Lerp( tint, Color.White, 0.5f ) ),
Foot = foot,
Length = length,
Speed = s.R( 40f, 90f ),
Phase = s.R( 0f, 1f ),
Colour = tint,
};
if ( !string.IsNullOrEmpty( words ) )
thread.Words = s.Words( "Thread Words", foot + Vector3.Up * 75f, words, letter, Color.Lerp( tint, Color.White, 0.3f ) );
_threads.Add( thread );
return thread;
}
/// <summary>The three answers: three lights beyond the dais, dark until it is the player's turn.</summary>
void BuildPillars()
{
var s = Space;
var colours = new[] { Pale, OrderGlow, new Color( 1f, 0.5f, 0.3f ) };
var yaws = new[] { 55f, 0f, -55f };
for ( int i = 0; i < FinaleWriting.Answers.Length; i++ )
{
var answer = FinaleWriting.Answers[i];
var at = P( 0f, 0f ) + Rotation.FromYaw( yaws[i % yaws.Length] ).Forward * PillarDistance;
var colour = colours[i % colours.Length];
var root = s.Group( "Answer " + answer.Key, at );
s.Box( "Answer Thread", at + Vector3.Up * 260f, new Vector3( 5f, 5f, 520f ), colour, false, null, root );
s.Ball( "Answer Foot", at + Vector3.Up * 4f, new Vector3( 46f, 46f, 4f ), colour, root );
s.Words( "Answer Words", at + Vector3.Up * 120f, answer.Words, 17f, colour, root );
var light = s.Light( "Answer Light", at + Vector3.Up * 70f, colour * 0.9f, 420f, 0f, root );
root.Enabled = false;
_pillars.Add( new Pillar { Root = root, Light = light, At = at, Key = answer.Key, Words = answer.Words, Hint = answer.Hint, Colour = colour } );
}
}
// ---- Where things are -------------------------------------------------------------------------
public override float Floor( Vector3 point ) => Space.Origin.z;
public override Vector3 Contain( Vector3 point )
{
var local = point - Space.Origin;
var flat = local.WithZ( 0f );
bool inside = flat.Length <= FloorRadius + 40f && local.z > -40f && local.z < Radius;
if ( inside ) return point;
if ( flat.Length > FloorRadius ) flat = flat.Normal * (FloorRadius - 20f);
return Space.Origin + flat + Vector3.Up * 4f;
}
public override void End()
{
if ( _host.IsValid() ) { _host.Live = false; _host.DropAll(); }
}
// ---- Playing ----------------------------------------------------------------------------------
void Go( Stage stage )
{
_stage = stage;
_t = 0f;
}
public override void Begin()
{
Procession.HurryDistance = 300f;
}
public override void Update( float dt )
{
_t += dt;
var player = Player.WorldPosition;
float distance = (player - Space.Origin).WithZ( 0f ).Length;
AnimateThreads( dt );
foreach ( var cell in _watchers ) cell.Pale( Pale, 0.82f );
switch ( _stage )
{
case Stage.Approach: Approach( player, distance ); break;
case Stage.Ceremony: Ceremony( dt, player ); break;
case Stage.Choice: Choice( player ); break;
case Stage.Reply: Reply( dt, player ); break;
case Stage.After: After( dt ); break;
}
}
// ---- 1. Walking in ----------------------------------------------------------------------------
void Approach( Vector3 player, float distance )
{
// The question, a piece at a time.
if ( _questions < QuestionAt.Length && _questions < FinaleWriting.Question.Length - 1 && distance < QuestionAt[_questions] && _t >= _nextQuestion )
{
_nextQuestion = _t + QuestionGap;
Sump.Say( FinaleWriting.HeartVoice, FinaleWriting.Question[_questions], 6.5f );
Sump.Sfx( "heart_question", HeartAt, 1f );
if ( _heartParts.Count > 0 ) _heartParts[0].Flash = 1f;
_questions++;
}
// The lizard's own orders, whole.
if ( !_ownRead && (player - _ownThread).WithZ( 0f ).Length < 230f )
{
_ownRead = true;
if ( _ownWords.IsValid() ) _ownWords.Text = "ORDERS, COMPLETE";
Sump.Say( "YOUR ORDERS", FinaleWriting.OrdersWhole, 14f );
Sump.Sfx( "order_whole", _ownThread, 1f );
}
else if ( !_ownRead && (player - _ownThread).WithZ( 0f ).Length < 600f )
Sump.Prompt = "That one is yours.";
if ( distance < DaisRadius * 0.7f )
{
Sump.Prompt = "E answer it. Together.";
if ( Input.Pressed( "Use" ) ) StartCeremony( player );
}
}
// ---- 2. The Sump answers ----------------------------------------------------------------------
void StartCeremony( Vector3 player )
{
Player.InputLocked = true;
Player.ForcedWish = null;
Sump.Sfx( "answer_begin", Space.Origin, 1f );
// Everybody takes a place in a half ring behind the player, facing the heart.
var followers = Procession.Followers;
for ( int i = 0; i < followers.Count; i++ )
{
followers[i].Post = RingSpot( i, followers.Count, 215f );
followers[i].Set( FollowerState.Posted );
}
// And the cells come, the way they always do. This time nobody runs.
_host.Live = true;
for ( int i = 0; i < WatchingCells; i++ )
{
float yaw = 30f + i * 300f / Math.Max( WatchingCells - 1, 1 ); // not across the way in
var from = Space.Origin + Rotation.FromYaw( yaw + 180f ).Forward * (FloorRadius - 300f - (i % 3) * 120f);
var to = Space.Origin + Rotation.FromYaw( yaw + 180f ).Forward * (540f + (i % 2) * 70f);
var cell = FinaleCell.Spawn( Space.Root, _host, from, yaw, Color.Lerp( Pale, new Color( 0.75f, 0.8f, 0.85f ), Space.R( 0f, 0.5f ) ), Color.Lerp( Pale, Color.Gray, Space.R( 0.2f, 0.6f ) ), 110f );
cell.Standing = true;
cell.Spot = to;
cell.GoTo( to, 62f, Space.Origin );
_watchers.Add( cell );
}
_speaker = -1;
_nextSpeaker = 5f;
Go( Stage.Ceremony );
}
/// <summary>A place in the half ring on the entrance side of the dais.</summary>
Vector3 RingSpot( int index, int count, float radius )
{
float yaw = count <= 1 ? 180f : 110f + index * 140f / (count - 1);
return Space.Origin + Rotation.FromYaw( yaw ).Forward * radius;
}
void Ceremony( float dt, Vector3 player )
{
Player.InputLocked = true;
var followers = Procession.Followers;
if ( !_saidCells && _t > 2.2f )
{
_saidCells = true;
Procession.SayNearest( player, FinaleWriting.HeartCells, 6f );
}
// Whoever has spoken keeps its keepsake lit; whoever is speaking burns brightest.
for ( int i = 0; i < followers.Count; i++ )
{
float want = i == _speaker ? 1f : i < _speaker ? 0.45f : 0f;
followers[i].GlowLevel += (want - followers[i].GlowLevel) * Math.Clamp( dt * 2.5f, 0f, 1f );
}
if ( _t < _nextSpeaker ) return;
_nextSpeaker = _t + AnswerSeconds;
// The one who has just spoken steps back into the ring.
if ( _speaker >= 0 && _speaker < followers.Count )
followers[_speaker].Post = RingSpot( _speaker, followers.Count, 215f );
_speaker++;
if ( _speaker < followers.Count )
{
var speaker = followers[_speaker];
speaker.Post = RingSpot( _speaker, followers.Count, 120f );
Sump.Say( speaker.Name, MisfitVoice.Speak( speaker.Profile, FinaleWriting.AnswerOf( speaker.Profile ) ), AnswerSeconds + 1.5f );
Sump.Sfx( "answer_voice", speaker.Position, 1f );
if ( speaker.Body.IsValid() ) speaker.Body.Flinch();
// The heart takes a little of each of them as they speak.
var colour = Color.Lerp( HeartLight, speaker.Profile.Primary, 0.5f );
Space.Recolour( _heartLight, colour * 2.4f );
Space.Recolour( _floorLight, colour * 0.9f );
if ( _heartParts.Count > 0 ) _heartParts[0].Flash = 0.8f;
return;
}
// Everybody has spoken. The question, whole, and the player's turn.
Space.Recolour( _heartLight, HeartLight * 2.4f );
Space.Recolour( _floorLight, HeartLight * 0.9f );
Sump.Say( FinaleWriting.HeartVoice, FinaleWriting.Question[^1], 9f );
Sump.Sfx( "heart_question", HeartAt, 1f );
_suggested = Suggest();
foreach ( var pillar in _pillars )
{
if ( pillar.Root.IsValid() ) pillar.Root.Enabled = true;
bool fits = pillar.Key == _suggested;
if ( pillar.Light.IsValid() )
{
pillar.Light.LightColor = (pillar.Colour * (fits ? 2.2f : 0.8f)).WithAlpha( 1f );
pillar.Light.Radius = fits ? 620f : 380f;
}
}
Player.InputLocked = false;
Go( Stage.Choice );
}
/// <summary>The answer that fits how the descent was played. It only burns brighter; all three can be given.</summary>
string Suggest()
{
// Ran, fought and was put out: wants out.
if ( Finale.SentBack > 0 || Finale.RanSeconds > Finale.StillSeconds * 1.5f + 20f ) return "go";
// Brought nearly everybody, and never let one be carried off: the Sump is a body already.
if ( Procession.Count >= 6 || (Finale.Taken == 0 && Procession.Count >= 4) ) return "stay";
// Stood still among them.
return "here";
}
// ---- 3. The player answers --------------------------------------------------------------------
void Choice( Vector3 player )
{
if ( !_saidSuggest && _t > 5f )
{
_saidSuggest = true;
Procession.SayNearest( player, FinaleWriting.HeartSuggest, 7f );
}
Pillar near = null;
foreach ( var pillar in _pillars )
if ( (player - pillar.At).WithZ( 0f ).Length < PillarReach ) near = pillar;
if ( near is null )
{
Sump.Prompt = "Three answers. Walk to the one you mean.";
return;
}
Sump.Prompt = $"E answer: \"{near.Words}\" {near.Hint}";
if ( Input.Pressed( "Use" ) ) Choose( near );
}
void Choose( Pillar chosen )
{
_answer = chosen.Key;
_replies = 0;
Player.InputLocked = true;
Player.ForcedWish = null;
foreach ( var pillar in _pillars )
if ( pillar != chosen && pillar.Root.IsValid() ) pillar.Root.Enabled = false;
if ( chosen.Light.IsValid() ) { chosen.Light.LightColor = (chosen.Colour * 3f).WithAlpha( 1f ); chosen.Light.Radius = 900f; }
Sump.Say( "THE SUMP", chosen.Words, 5f );
Sump.Sfx( "answer_" + _answer, Space.Origin, 1f );
foreach ( var follower in Procession.Followers ) follower.GlowLevel = 1f;
if ( _answer == "go" )
{
_column.Enabled = true;
_columnLight.Enabled = true;
}
Go( Stage.Reply );
}
void Reply( float dt, Vector3 player )
{
Player.InputLocked = true;
// The heart's reply, a line at a time.
var lines = FinaleWriting.HeartReply( _answer );
if ( _replies < lines.Length && _t > 3.5f + _replies * ReplyEvery )
{
Sump.Say( FinaleWriting.HeartVoice, lines[_replies], ReplyEvery + 1f );
Sump.Sfx( "heart_question", HeartAt, 0.8f );
if ( _heartParts.Count > 0 ) _heartParts[0].Flash = 1f;
_replies++;
// The first line is the heart understanding; that is when the cells stand down.
if ( _replies == 1 && _answer == "here" ) PartCells();
}
if ( !_saidAfter && _t > 3.5f + ReplyEvery * 1.5f )
{
_saidAfter = true;
Procession.SayNearest( player, FinaleWriting.FollowerAfter( _answer ), 7f );
}
Effects( dt, Math.Clamp( (_t - 3.5f) / 10f, 0f, 1f ) );
if ( _t < ReplySeconds ) return;
Player.InputLocked = false;
Go( Stage.After );
Finale.EndWith( _answer );
}
/// <summary>"We are here": the cells turn and walk back to the walls. Nobody is infection any more.</summary>
void PartCells()
{
Sump.Sfx( "clot_part", Space.Origin, 1f );
foreach ( var cell in _watchers )
{
if ( !cell.Alive ) continue;
var away = (cell.Position - Space.Origin).WithZ( 0f );
away = away.Length > 1f ? away.Normal : Vector3.Forward;
cell.Spot = Space.Origin + away * (FloorRadius - 200f);
cell.GoTo( cell.Spot, 55f );
}
}
/// <summary>What the chamber does with the answer, growing from 0 to 1.</summary>
void Effects( float dt, float amount )
{
switch ( _answer )
{
case "here":
// It stops straining: the beat slows and the light steadies.
Finale.BeatSlow = 1f + 0.7f * amount;
Space.Recolour( _heartLight, Color.Lerp( HeartLight, new Color( 1f, 0.62f, 0.45f ), amount ) * 2.4f );
break;
case "go":
{
// A column of light from the heart up through the roof, and everything it kept going up it.
float height = 60f + 4200f * amount * amount;
if ( _column.IsValid() )
{
_column.LocalScale = new Vector3( 110f / 50f * (0.4f + 0.6f * amount), 110f / 50f * (0.4f + 0.6f * amount), height / 50f );
_column.WorldPosition = HeartAt + Vector3.Up * (height * 0.5f);
}
if ( _columnLight.IsValid() ) _columnLight.LightColor = (new Color( 0.7f, 1f, 0.9f ) * (3f * amount)).WithAlpha( 1f );
foreach ( var thread in _threads ) thread.Speed = -Lerp( 60f, 900f, amount );
break;
}
case "stay":
{
// The heart takes on the Sump's colour, and the walls after it.
var hot = Color.Lerp( HeartHot, Color.Lerp( _patchwork, Color.White, 0.2f ), amount );
var cold = Color.Lerp( HeartCold, _patchwork * 0.45f, amount ).WithAlpha( 1f );
foreach ( var part in _heartParts ) { part.Hot = hot; part.Tint = cold; }
var wall = Color.Lerp( WallHot, _patchwork * 0.6f, amount * 0.8f ).WithAlpha( 1f );
foreach ( var lump in _shell ) lump.Hot = wall;
Space.Recolour( _heartLight, Color.Lerp( HeartLight, _patchwork, amount ) * 2.4f );
Space.Recolour( _floorLight, Color.Lerp( HeartLight, _patchwork, amount ) * 0.9f );
break;
}
}
}
// ---- 4. Afterwards ----------------------------------------------------------------------------
/// <summary>The patchwork procession: everybody walking slowly round the heart, keepsakes lit.</summary>
void After( float dt )
{
Effects( dt, 1f );
_ringTurn += dt * 7f;
var followers = Procession.Followers;
for ( int i = 0; i < followers.Count; i++ )
{
float yaw = _ringTurn + i * 360f / Math.Max( followers.Count, 1 );
followers[i].Post = Space.Origin + Rotation.FromYaw( yaw ).Forward * 330f;
followers[i].Set( FollowerState.Posted );
followers[i].GlowLevel = 0.8f;
}
}
// ---- The threads ------------------------------------------------------------------------------
void AnimateThreads( float dt )
{
foreach ( var thread in _threads )
{
if ( !thread.Mote.IsValid() ) continue;
// Down the thread and round again (or, once they are let go, up and away).
thread.Phase = (thread.Phase + thread.Speed * dt / MathF.Max( thread.Length, 1f )) % 1f;
if ( thread.Phase < 0f ) thread.Phase += 1f;
thread.Mote.WorldPosition = thread.Foot + Vector3.Up * (thread.Length * (1f - thread.Phase));
}
}
}