159 lines
7.9 KiB
C#
159 lines
7.9 KiB
C#
|
|
using System;
|
||
|
|
using GladiatorIdle.Gfx;
|
||
|
|
using Microsoft.Xna.Framework;
|
||
|
|
using Microsoft.Xna.Framework.Graphics;
|
||
|
|
using Microsoft.Xna.Framework.Input;
|
||
|
|
using D = GladiatorIdle.Gfx.Draw;
|
||
|
|
|
||
|
|
namespace GladiatorIdle.Arena
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// Schwur nach der Erstellung: der neue Gladiator steht in einer kleinen Arena, die Kamera fährt
|
||
|
|
/// von unten langsam hoch und um ihn herum, er spricht seine Rede mit dem eigenen Namen
|
||
|
|
/// (<see cref="NameVoice.Kind.Oath"/>, Untertitel je Satz). Beim letzten Satz reckt er die Waffe,
|
||
|
|
/// das Publikum ruft seinen Namen. Klick, Leertaste oder Esc überspringt.
|
||
|
|
/// </summary>
|
||
|
|
internal sealed class OathScene
|
||
|
|
{
|
||
|
|
readonly GameState _game;
|
||
|
|
readonly Stage3D _stage = new(1, AppSettings.ReduceMotion);
|
||
|
|
readonly FighterView _hero;
|
||
|
|
readonly DuelFighter _dummy = new() { IsPlayer = true, Facing = 1, MaxHp = 1, Hp = 1 };
|
||
|
|
readonly Particles _fx = new();
|
||
|
|
const float HERO_X = 960, WAIT = 3.4f, SILENT_LINE = 3.2f, PRELUDE = 1.8f;
|
||
|
|
float _t, _start = -1, _length, _endAt = -1;
|
||
|
|
int _shown = -1;
|
||
|
|
bool _voiced, _cheered;
|
||
|
|
float[] _times = Array.Empty<float>();
|
||
|
|
string[] _lines = Array.Empty<string>();
|
||
|
|
|
||
|
|
public bool Done { get; private set; }
|
||
|
|
|
||
|
|
public OathScene(GameState game)
|
||
|
|
{
|
||
|
|
_game = game;
|
||
|
|
string hero = Art.Hero(game.Class, game.Look.Preset);
|
||
|
|
_hero = Assets.Has(hero) ? new FighterView(hero, 0, game.Look.Color) : new FighterView(Art.Fighter(game.Class), 0, -1, game.Look.Color);
|
||
|
|
_fx.Calm = AppSettings.ReduceMotion;
|
||
|
|
_stage.Cam.CinePivot = new Vector3(HERO_X, Stage.FloorY - Stage.FigH * 0.6f, 0);
|
||
|
|
// Atmosphäre: schwere Trommeln und Bläser, Publikum in der Ferne; die Rede setzt nach dem Vorspiel ein
|
||
|
|
SoundManager.StopAll();
|
||
|
|
SoundManager.PlayMusic("music_oath", loop: false);
|
||
|
|
SoundManager.PlayAmbience("amb_crowd");
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Testläufe: Zeit der Rede setzen (Aufnahmen).
|
||
|
|
public float Time => _start < 0 ? -1 : _t - _start;
|
||
|
|
|
||
|
|
void Begin()
|
||
|
|
{
|
||
|
|
_lines = NameVoice.OathLines;
|
||
|
|
var pcm = AppSettings.Narration ? NameVoice.Get(NameVoice.Kind.Oath) : null;
|
||
|
|
if (pcm != null && NameVoice.OathTimes.Length == _lines.Length)
|
||
|
|
{
|
||
|
|
_times = NameVoice.OathTimes;
|
||
|
|
_length = pcm.Length / 2f / 44100f;
|
||
|
|
SoundManager.PlayPcm("oath", pcm);
|
||
|
|
_voiced = true;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
// ohne Stimme: nur Untertitel
|
||
|
|
_times = new float[_lines.Length];
|
||
|
|
for (int i = 0; i < _times.Length; i++) _times[i] = i * SILENT_LINE;
|
||
|
|
_length = _lines.Length * SILENT_LINE;
|
||
|
|
}
|
||
|
|
_start = _t;
|
||
|
|
// Kamera: nah von unten, langsam hoch und herum, am Ende aufziehen
|
||
|
|
_stage.Cam.Shot(new Camera.Key(0, -25, -24, 1750), new Camera.Key(_length * 0.55f, 35, -13, 1450),
|
||
|
|
new Camera.Key(_length + 0.6f, 85, -6, 900), new Camera.Key(_length + 4, 110, -4, 700));
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Update(float dt, Input input)
|
||
|
|
{
|
||
|
|
_t += dt;
|
||
|
|
if (_start < 0 && _t >= PRELUDE && (NameVoice.Get(NameVoice.Kind.Oath) != null || _t > WAIT || !NameVoice.OathAvailable)) Begin();
|
||
|
|
float s = Time;
|
||
|
|
if (s >= 0)
|
||
|
|
{
|
||
|
|
int line = 0;
|
||
|
|
while (line < _times.Length - 1 && s >= _times[line + 1]) line++;
|
||
|
|
if (line != _shown) _shown = line;
|
||
|
|
// letzter Satz: Waffe hoch, Menge jubelt, danach ruft sie den Namen
|
||
|
|
if (_lines.Length > 0 && line == _lines.Length - 1 && _dummy.State != DuelState.Victory) _dummy.Set(DuelState.Victory);
|
||
|
|
if (!_cheered && s >= _length + 0.2f)
|
||
|
|
{
|
||
|
|
_cheered = true;
|
||
|
|
SoundManager.PlayCheer();
|
||
|
|
NameVoice.Play(NameVoice.Kind.Chant, 1f, 0);
|
||
|
|
_endAt = _t + 4.2f;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
_dummy.StateTime += dt;
|
||
|
|
_hero.Update(dt, dt, _dummy, HERO_X, AppSettings.ReduceMotion);
|
||
|
|
_stage.Cam.CinePivot = new Vector3(HERO_X, Stage.FloorY - Stage.FigH * 0.6f, 0);
|
||
|
|
_stage.Cam.Update(dt, HERO_X, HERO_X, AppSettings.ReduceMotion);
|
||
|
|
Span<Vector3> pts = stackalloc Vector3[] { new(HERO_X - 90, Stage.FloorY - Stage.FigH * 1.1f, 0), new(HERO_X + 90, Stage.FloorY + 12, 0) };
|
||
|
|
_stage.Cam.KeepInView(pts, _stage.LastScale, _stage.LastOffset, _stage.LastW, _stage.LastH, dt);
|
||
|
|
_fx.Motes(AppSettings.ReduceMotion ? 0 : 50, Camera.W, Camera.H);
|
||
|
|
_fx.Update(dt);
|
||
|
|
if (_endAt > 0 && _t >= _endAt) Done = true;
|
||
|
|
if (input.LeftClick || input.Pressed(Keys.Space) || input.Pressed(Keys.Escape) || input.Pressed(Keys.Enter))
|
||
|
|
{
|
||
|
|
if (_voiced) SoundManager.CutEffects(); // Rede weich ausblenden
|
||
|
|
Done = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Draw(GraphicsDevice gd, SpriteBatch sb, BasicEffect fx, float scale, Vector2 offset)
|
||
|
|
{
|
||
|
|
D.UiScale = scale;
|
||
|
|
var ui = Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0);
|
||
|
|
_stage.Prepare(gd, scale, offset);
|
||
|
|
_stage.DrawSet(gd, sb, _t, _cheered ? 1f : 0.35f);
|
||
|
|
_stage.Shadows(gd, sb, 0, _hero);
|
||
|
|
_stage.FloorLight(sb, HERO_X, 900, 0.25f);
|
||
|
|
Stage3D.BeginFigures(gd);
|
||
|
|
_stage.Use(_hero);
|
||
|
|
_hero.DrawBody(gd, fx, _dummy, AppSettings.ReduceMotion);
|
||
|
|
|
||
|
|
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, ui);
|
||
|
|
_fx.DrawAdd(sb);
|
||
|
|
sb.End();
|
||
|
|
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
|
||
|
|
// Kinobalken oben und unten
|
||
|
|
float bar = Camera.H * 0.09f;
|
||
|
|
D.Rect(sb, new RectangleF(0, 0, Camera.W, bar), Color.Black);
|
||
|
|
D.Rect(sb, new RectangleF(0, Camera.H - bar, Camera.W, bar), Color.Black);
|
||
|
|
float s = Time;
|
||
|
|
if (s >= 0 && _shown >= 0 && _shown < _lines.Length && s < _length + 0.4f)
|
||
|
|
{
|
||
|
|
float since = s - _times[_shown];
|
||
|
|
float a = MathHelper.Clamp(since / 0.35f, 0, 1);
|
||
|
|
D.Glow(sb, new Vector2(Camera.W / 2, Camera.H - 170), new Vector2(1900, 230), Color.Black * (0.55f * a));
|
||
|
|
// mittig, bei Bedarf in zwei Zeilen (am Leerzeichen nahe der Mitte geteilt)
|
||
|
|
string text = _lines[_shown];
|
||
|
|
var col = new Color(250, 238, 210) * a;
|
||
|
|
if (D.Measure(Assets.Serif, 38, text).X <= 1600)
|
||
|
|
D.Text(sb, Assets.Serif, 38, text, new Vector2(Camera.W / 2, Camera.H - 170), col, Align.Center);
|
||
|
|
else
|
||
|
|
{
|
||
|
|
int mid = text.Length / 2, cut = text.LastIndexOf(' ', mid);
|
||
|
|
int after = text.IndexOf(' ', mid);
|
||
|
|
if (cut < 0 || (after >= 0 && after - mid < mid - cut)) cut = after;
|
||
|
|
if (cut < 0) cut = mid;
|
||
|
|
D.Text(sb, Assets.Serif, 38, text[..cut].Trim(), new Vector2(Camera.W / 2, Camera.H - 196), col, Align.Center);
|
||
|
|
D.Text(sb, Assets.Serif, 38, text[cut..].Trim(), new Vector2(Camera.W / 2, Camera.H - 146), col, Align.Center);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (_cheered)
|
||
|
|
{
|
||
|
|
float k = MathHelper.Clamp((s - _length - 0.2f) / 0.6f, 0, 1);
|
||
|
|
D.Text(sb, Assets.Serif, 110, _game.Name.ToUpperInvariant(), new Vector2(Camera.W / 2, Camera.H * 0.3f), D.Gold * k, Align.Center, 1 + 0.25f * (1 - k));
|
||
|
|
}
|
||
|
|
D.Text(sb, Assets.Sans, 17, L.t("oath.skip"), new Vector2(Camera.W - 40, Camera.H - bar / 2), D.Dim, Align.Right);
|
||
|
|
sb.End();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|