Gladiator Idle (MonoGame) – Spiel mit 3D-Gladiatoren
Nur was zum Bauen und Starten nötig ist: Mono/ (Spiel), Game/, Core/, Languages/, Assets/ (Bilder, Clips, 3D-Figuren, Ton), build-release.bat. Bauen: build-release.bat → Spiel\GladiatorIdle.exe Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
186
Mono/Arena/IntroScene.cs
Normal file
186
Mono/Arena/IntroScene.cs
Normal file
@@ -0,0 +1,186 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using GladiatorIdle.Gfx;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using D = GladiatorIdle.Gfx.Draw;
|
||||
|
||||
namespace GladiatorIdle.Arena
|
||||
{
|
||||
/// <summary>
|
||||
/// Intro als kurzer Film: Schwarz mit Glut → erster Satz → fünf Kapitel (Wan-Clips mit
|
||||
/// Kamerafahrt, Kinobalken, Untertitel, Erzählstimme) → Titel mit Schlusssatz → "Weiter".
|
||||
/// Die Kapitellänge richtet sich nach den gesprochenen Sätzen. Überspringen jederzeit.
|
||||
/// </summary>
|
||||
internal sealed class IntroScene
|
||||
{
|
||||
public static readonly string[] Scenes = { "intro_village", "intro_chains", "intro_market", "intro_ludus", "intro_colosseum" };
|
||||
|
||||
static bool Voiced => SoundManager.Enabled && AppSettings.Narration;
|
||||
static float Longest(params string[] keys) => Voiced ? keys.Max(k => SoundManager.VoiceSeconds(k)) : 0f;
|
||||
|
||||
const float LINE1_AT = 1.2f, FADE_OUT = 0.6f;
|
||||
readonly float _lineLen, _storyAt, _chapter, _storyEnd, _titleAt, _promptAt, _autoClose;
|
||||
readonly (float At, string Key)[] _voice;
|
||||
readonly Ui _ui = new();
|
||||
readonly Particles _fx = new();
|
||||
readonly Texture2D? _finale = Assets.Sprite("intro_colosseum", "jpg");
|
||||
float _t, _closeAt = -1;
|
||||
int _voicePlayed;
|
||||
|
||||
public bool Done { get; private set; }
|
||||
|
||||
public IntroScene()
|
||||
{
|
||||
_lineLen = Math.Max(4.5f, 0.2f + SoundManager.VoiceDelay(0) + Longest("intro.line1") + 1.2f);
|
||||
_storyAt = LINE1_AT + _lineLen;
|
||||
_chapter = Math.Max(6.0f, 0.4f + SoundManager.VoiceDelay(0)
|
||||
+ Longest(Enumerable.Range(1, Scenes.Length).Select(i => $"intro.story.{i}").ToArray()) + 1.4f);
|
||||
_storyEnd = _storyAt + Scenes.Length * _chapter;
|
||||
_titleAt = _storyEnd + 0.3f;
|
||||
_promptAt = _titleAt + Math.Max(4f, Longest("intro.line2") + 2.2f);
|
||||
_autoClose = _promptAt + 12f;
|
||||
_voice = Enumerable.Range(0, Scenes.Length)
|
||||
.Select(i => (_storyAt + i * _chapter + 0.4f, $"intro.story.{i + 1}"))
|
||||
.Prepend((LINE1_AT + 0.1f, "intro.line1"))
|
||||
.Append((_titleAt + 1.2f, "intro.line2"))
|
||||
.ToArray();
|
||||
SoundManager.PreloadVoice(_voice.Select(v => v.Key));
|
||||
foreach (var s in Scenes) ClipCache.Video(s);
|
||||
SoundManager.PlayMusic("music_intro", loop: false);
|
||||
}
|
||||
|
||||
/// Testläufe: Zeitpunkte zum Aufnehmen (erster Satz, Mitte jedes Kapitels, Titel).
|
||||
public float[] CaptureTimes() =>
|
||||
new[] { LINE1_AT + 2f }.Concat(Enumerable.Range(0, Scenes.Length).Select(i => _storyAt + (i + 0.55f) * _chapter)).Append(_promptAt + 0.5f).ToArray();
|
||||
|
||||
public float Time { get => _t; set => _t = value; }
|
||||
|
||||
void Close()
|
||||
{
|
||||
SoundManager.StopVoice();
|
||||
if (_closeAt < 0) _closeAt = _t;
|
||||
}
|
||||
|
||||
public void Update(float dt, Input input, Matrix ui)
|
||||
{
|
||||
_t += dt;
|
||||
_ui.Begin(input, ui);
|
||||
while (_closeAt < 0 && _voicePlayed < _voice.Length && _t >= _voice[_voicePlayed].At)
|
||||
SoundManager.PlayVoice(_voice[_voicePlayed++].Key);
|
||||
if (input.Pressed(Microsoft.Xna.Framework.Input.Keys.Escape) || input.Pressed(Microsoft.Xna.Framework.Input.Keys.Enter)
|
||||
|| input.Pressed(Microsoft.Xna.Framework.Input.Keys.Space)) Close();
|
||||
if (_closeAt < 0 && _t >= _autoClose) Close();
|
||||
if (_closeAt >= 0 && _t - _closeAt >= FADE_OUT) Done = true;
|
||||
_fx.Motes(AppSettings.ReduceMotion ? 0 : 60, Camera.W, Camera.H);
|
||||
_fx.Update(dt);
|
||||
}
|
||||
|
||||
// ── Zeichnen ────────────────────────────────────────────────
|
||||
|
||||
public void Draw(SpriteBatch sb, float scale, Vector2 offset)
|
||||
{
|
||||
D.UiScale = scale;
|
||||
var ui = Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0);
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
|
||||
if (_t < _storyAt) DrawLine(sb, L.t("intro.line1"), (_t - LINE1_AT) / _lineLen);
|
||||
else if (_t < _storyEnd) DrawStory(sb);
|
||||
else DrawFinale(sb);
|
||||
sb.End();
|
||||
if (_t < _storyAt || _t >= _storyEnd)
|
||||
{
|
||||
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);
|
||||
DrawSkip(sb);
|
||||
if (_closeAt >= 0) D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), Color.Black * Clamp01((_t - _closeAt) / FADE_OUT));
|
||||
sb.End();
|
||||
}
|
||||
|
||||
static void DrawLine(SpriteBatch sb, string text, float p)
|
||||
{
|
||||
if (p <= 0 || p >= 1) return;
|
||||
float a = EaseOut(Clamp01(p < 0.2f ? p / 0.2f : p > 0.8f ? (1 - p) / 0.2f : 1));
|
||||
D.Text(sb, Assets.Serif, 50, text, new Vector2(Camera.W / 2, Camera.H * 0.45f - p * 20), new Color(240, 222, 186) * a, Align.Center);
|
||||
}
|
||||
|
||||
void DrawStory(SpriteBatch sb)
|
||||
{
|
||||
float local = _t - _storyAt;
|
||||
int idx = Math.Min(Scenes.Length - 1, (int)(local / _chapter));
|
||||
float p = (local - idx * _chapter) / _chapter;
|
||||
|
||||
// Clip "cover" auf 110 %, langsame Kamerafahrt abwechselnd nach links/rechts
|
||||
var frames = ClipCache.Video(Scenes[idx]);
|
||||
var tex = frames != null ? frames[Math.Min(frames.Length - 1, (int)(p * (frames.Length - 1)))] : Assets.Sprite(Scenes[idx], "jpg");
|
||||
if (tex != null)
|
||||
{
|
||||
float k = 1.1f * MathF.Max(Camera.W / tex.Width, Camera.H / tex.Height);
|
||||
float e = EaseInOut(p), over = tex.Width * k - Camera.W;
|
||||
float x = -over * (idx % 2 == 0 ? e : 1 - e);
|
||||
sb.Draw(tex, new Vector2(x, (Camera.H - tex.Height * k) / 2), null, Color.White, 0, Vector2.Zero, k, SpriteEffects.None, 0);
|
||||
}
|
||||
|
||||
// Kinobalken, Abblende zwischen den Kapiteln
|
||||
float barIn = Clamp01(local / 0.6f) * Clamp01((_storyEnd - _t) / 0.6f);
|
||||
float bar = Camera.H * 0.11f * EaseOut(barIn);
|
||||
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 dip = p < 0.1f ? 1 - p / 0.1f : p > 0.92f ? (p - 0.92f) / 0.08f : 0f;
|
||||
if (dip > 0) D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), Color.Black * Clamp01(dip));
|
||||
|
||||
// Kapitel und Satz im unteren Drittel
|
||||
float ta = Clamp01((p - 0.1f) / 0.12f) * Clamp01((0.92f - p) / 0.08f);
|
||||
if (ta <= 0) return;
|
||||
D.Glow(sb, new Vector2(Camera.W / 2, Camera.H * 0.78f), new Vector2(Camera.W * 1.6f, Camera.H * 0.6f), Color.Black * (0.75f * ta));
|
||||
D.Text(sb, Assets.Serif, 26, $"{idx + 1} / {Scenes.Length} · {L.t($"intro.chapter.{idx + 1}").ToUpperInvariant()}", // i18n-ok
|
||||
new Vector2(Camera.W / 2, Camera.H * 0.665f), D.Gold * ta, Align.Center);
|
||||
DrawCentered(sb, L.t($"intro.story.{idx + 1}"), Camera.H * 0.745f, 42, new Color(245, 236, 214) * ta);
|
||||
}
|
||||
|
||||
/// Satz zentriert, bei Bedarf auf zwei Zeilen umbrochen.
|
||||
static void DrawCentered(SpriteBatch sb, string text, float y, float px, Color c)
|
||||
{
|
||||
float max = Camera.W * 0.8f;
|
||||
if (D.Measure(Assets.Serif, px, text).X <= max) { D.Text(sb, Assets.Serif, px, text, new Vector2(Camera.W / 2, y), c, Align.Center); return; }
|
||||
var words = text.Split(' ');
|
||||
int split = words.Length / 2;
|
||||
for (int i = 1; i < words.Length; i++)
|
||||
if (D.Measure(Assets.Serif, px, string.Join(' ', words[..i])).X > max * 0.55f) { split = i; break; }
|
||||
D.Text(sb, Assets.Serif, px, string.Join(' ', words[..split]), new Vector2(Camera.W / 2, y - px * 0.6f), c, Align.Center);
|
||||
D.Text(sb, Assets.Serif, px, string.Join(' ', words[split..]), new Vector2(Camera.W / 2, y + px * 0.6f), c, Align.Center);
|
||||
}
|
||||
|
||||
void DrawFinale(SpriteBatch sb)
|
||||
{
|
||||
float bg = Clamp01((_t - _storyEnd) / 1.2f);
|
||||
if (_finale != null)
|
||||
{
|
||||
float k = 1.08f * MathF.Max(Camera.W / _finale.Width, Camera.H / _finale.Height);
|
||||
sb.Draw(_finale, new Vector2(Camera.W / 2, Camera.H / 2), null, new Color(0.5f, 0.47f, 0.43f) * bg, 0,
|
||||
new Vector2(_finale.Width / 2f, _finale.Height / 2f), k, SpriteEffects.None, 0);
|
||||
}
|
||||
float p = Clamp01((_t - _titleAt) / 1.0f);
|
||||
if (p <= 0) return;
|
||||
float e = EaseOut(p);
|
||||
D.Glow(sb, new Vector2(Camera.W / 2, Camera.H * 0.36f), new Vector2(1600, 420), D.Gold * (0.12f * e));
|
||||
D.Text(sb, Assets.Serif, 130, L.t("app.title").ToUpperInvariant(), new Vector2(Camera.W / 2, Camera.H * 0.36f), D.Gold * e, Align.Center, 1.3f - 0.3f * e);
|
||||
float lp = Clamp01((_t - _titleAt - 1.2f) / 0.8f);
|
||||
DrawCentered(sb, L.t("intro.line2"), Camera.H * 0.62f, 38, new Color(245, 236, 214) * lp);
|
||||
}
|
||||
|
||||
void DrawSkip(SpriteBatch sb)
|
||||
{
|
||||
if (_t < 1f || _closeAt >= 0) return;
|
||||
bool end = _t >= _promptAt;
|
||||
var r = new RectangleF(Camera.W - 300, Camera.H - 100, 260, 60);
|
||||
if (_ui.Button(sb, r, L.t(end ? "intro.continue" : "intro.skip"), selected: end, size: 22)) Close();
|
||||
}
|
||||
|
||||
static float Clamp01(float v) => v < 0 ? 0 : v > 1 ? 1 : v;
|
||||
static float EaseOut(float v) => 1 - MathF.Pow(1 - v, 3);
|
||||
static float EaseInOut(float v) => v < 0.5f ? 2 * v * v : 1 - MathF.Pow(-2 * v + 2, 2) / 2;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user