using System; using System.Collections.Generic; using GladiatorIdle.Gfx; using D = GladiatorIdle.Gfx.Draw; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace GladiatorIdle.Arena { /// Eingaben eines Bilds (vom Spiel gesammelt). internal sealed class Input { public KeyboardState Keys, PrevKeys; public MouseState Mouse, PrevMouse; public bool Down(params Keys[] ks) { foreach (var k in ks) if (Keys.IsKeyDown(k)) return true; return false; } public bool Pressed(Keys k) => Keys.IsKeyDown(k) && !PrevKeys.IsKeyDown(k); public bool LeftClick => Mouse.LeftButton == ButtonState.Pressed && PrevMouse.LeftButton == ButtonState.Released; public bool RightHeld => Mouse.RightButton == ButtonState.Pressed; } /// /// Ein Echtzeit-Duell in der Arena: Logik aus , Darstellung mit Kamera, /// Trefferstopp, Zeitlupe, Partikeln, Publikum und knappem HUD. /// internal sealed class DuelScene { enum Phase { Intro, Countdown, Fight, End } const float COUNTDOWN = 2.2f, SPREAD = 1.3f; readonly GameState _game; readonly Enemy _enemy; public Duel Duel { get; } readonly FighterView _pv, _ev; readonly Camera _cam = new(); readonly Particles _fx = new(); readonly Crowd _crowd; readonly Texture2D? _backdrop; readonly string? _loopName; readonly bool _calm = AppSettings.ReduceMotion; readonly AbilityBar _bar = new(); /// Medaillon des Spezialschlags der Klasse. static string SpecialIcon(Special s) => s switch { Special.ShieldBash => "skill_shieldbash2", Special.Net => "skill_widenet", Special.Sica => "skill_sicawhirl", _ => "skill_endure2" }; Phase _phase = Phase.Countdown; readonly string? _introClip; // Auftritt des Champions (Wan-Clip), sonst gleich der Countdown const float INTRO = 6f; public bool InIntro => _phase == Phase.Intro; float _phaseTime, _hitstop, _slowmo, _screenFlash; float _furyDark, _emberIn; // Raserei: Abdunkeln der Arena, Takt der Funken Color _flashColor = Color.White; float _pLag = 1, _eLag = 1; double _time; int _countShown = -1; public bool Paused; public bool Won { get; private set; } public bool Finished => _phase == Phase.End && _phaseTime > 1.2f; public bool Over => _phase == Phase.End; sealed class Floater { public string Text = ""; public Vector2 Pos; public Color Color; public float Size, Age, Life = 1.1f; public bool Big; } readonly List _floaters = new(); /// Testlauf: Bot steuert den Spieler. public DuelBot? Bot; public DuelScene(GameState game, Enemy enemy, int seed) { _game = game; _enemy = enemy; var pc = game.PlayerCombat(); Duel = new Duel(pc.MaxHp, pc.Crit, game.ClassDef.Special, enemy.Hp, game.DuelRatio(enemy), enemy.IsChampion, game.Equipped[(int)ItemSlot.Weapon]?.Base == "trident", new Random(seed), game.Perks); // eigener Gladiator: Vorlage in Teamfarbe (sonst das Klassenbild) string hero = Art.Hero(game.Class, game.Look.Preset); _pv = Assets.Has(hero) ? new FighterView(hero, 0, game.Look.Color) : new FighterView(Art.Fighter(game.Class), 0, -1, game.Look.Color); _pv.Preload(); // 3D: Gegner vorerst mit derselben Figur in einer anderen Teamfarbe (Rot, oder Schwarz gegen Rot) _ev = new FighterView(enemy.Art ?? Art.Enemy(enemy.NameKey), 1.7f, -1, game.Look.Color == 0 ? 6 : 0); _crowd = new Crowd(seed); _fx.Calm = _calm; string arena = Art.Arena(ArenaDef.All[game.Arena]); _backdrop = Assets.Sprite(arena, "jpg"); _loopName = _calm ? null : arena; _cam.Center = new Vector2(Camera.W / 2, Camera.H / 2 + 40); _cam.Zoom = 1.45f; // Auftakt: nah, dann fährt die Kamera auf _crowd.Excite(0.5f); var sl = _bar.Slots; sl[0].Key = "Q"; sl[0].Name = L.t(TextKeys.Of(Duel.PlayerSpecial)); sl[0].Icon = Assets.Sprite(SpecialIcon(Duel.PlayerSpecial)); sl[0].Glow = D.Blue; // i18n-ok sl[1].Key = "W"; sl[1].Name = L.t("skill.heavystrike"); sl[1].Icon = Assets.Sprite("skill_heavystrike"); sl[1].Glow = new Color(255, 150, 40); // i18n-ok sl[2].Key = "E"; sl[2].Name = L.t("skill.shieldwall"); sl[2].Icon = Assets.Sprite("skill_shieldwall"); sl[2].Glow = D.Blue; // i18n-ok sl[1].Learned = Duel.Perks.HeavyStrike; sl[2].Learned = Duel.Perks.ShieldWall; SoundManager.StartAmbient(enemy.IsChampion ? "music_champion" : "music_arena"); if (enemy.IsChampion && enemy.NameKey.StartsWith("champion.")) // Geschichte, kein Effekt: auch bei "Effekte reduzieren" { string clip = "champintro_" + enemy.NameKey["champion.".Length..]; if (Assets.RootDir is string root && System.IO.File.Exists(System.IO.Path.Combine(root, "Video", clip + "_00.jpg"))) { _introClip = clip; ClipCache.Video(clip); // lädt im Hintergrund _phase = Phase.Intro; } } } // ── Takt ──────────────────────────────────────────────────── public void Update(float realDt, Input input) { if (Paused) return; _time += realDt; // Trefferstopp friert die Kämpfer kurz ein, Zeitlupe verlangsamt das Ende float dt = realDt; if (_hitstop > 0) { _hitstop -= realDt; dt = 0; } if (_slowmo > 0) { _slowmo -= realDt; dt *= 0.28f; } _phaseTime += realDt; switch (_phase) { case Phase.Intro: if (_phaseTime >= INTRO || input.LeftClick || input.Pressed(Keys.Space) || input.Pressed(Keys.Enter)) { _phase = Phase.Countdown; _phaseTime = 0; SoundManager.PlayGong(); } return; case Phase.Countdown: int n = 3 - (int)(_phaseTime / (COUNTDOWN / 3)); if (n != _countShown) { _countShown = n; if (n >= 1) SoundManager.PlayTick(); } if (_phaseTime >= COUNTDOWN) { _phase = Phase.Fight; _phaseTime = 0; SoundManager.PlayGong(); _cam.Shake(0.4f); _crowd.Excite(0.6f); Big(L.t("duel.fight"), D.Gold); } break; case Phase.Fight: if (Bot != null) Bot.Act(Duel); else Controls(input); Duel.Step(dt); HandleEvents(); if (Duel.Over) { _phase = Phase.End; _phaseTime = 0; Won = Duel.PlayerWon; _cam.FocusX = Won ? _pv.X : _ev.X; if (Won) SoundManager.PlayVictory(); else SoundManager.PlayDefeat(); } break; case Phase.End: Duel.Step(dt); HandleEvents(); break; } // Anzeige: Abstand um ein Viertel gespreizt (die Figuren sind breiter als ihre Trefferzone) float mid = (float)(Duel.Player.X + Duel.Enemy.X) / 2; float Spread(double x) => mid + ((float)x - mid) * SPREAD; if (_pv.Update(dt, realDt, Duel.Player, Spread(Duel.Player.X), _calm)) _fx.Dust(new Vector2(_pv.X, Stage.FloorY), 2, 30, 30, 40); if (_ev.Update(dt, realDt, Duel.Enemy, Spread(Duel.Enemy.X), _calm)) _fx.Dust(new Vector2(_ev.X, Stage.FloorY), 2, 30, 30, 40); FuryUpdate(realDt); _cam.Update(realDt, _pv.X, _ev.X, _calm); _fx.Motes(_calm ? 0 : 60, Camera.W, Camera.H); _fx.Update(dt > 0 ? dt : realDt * 0.15f); _crowd.Update(realDt); var p = Duel.Player; var sl = _bar.Slots; sl[0].Cooldown = p.SpecialCooldown; sl[0].Total = Duel.SpecialCooldownTotal; sl[1].Cooldown = p.HeavyCd; sl[1].Total = Duel.HEAVY_COOLDOWN; sl[1].Usable = p.Stamina >= Duel.HEAVY_COST; sl[2].Cooldown = p.WallCd; sl[2].Total = Duel.WALL_COOLDOWN; _bar.Update(realDt); _screenFlash = MathF.Max(0, _screenFlash - realDt * 4); _pLag = Lag(_pLag, (float)(Duel.Player.Hp / Duel.Player.MaxHp), realDt); _eLag = Lag(_eLag, (float)(Duel.Enemy.Hp / Duel.Enemy.MaxHp), realDt); for (int i = _floaters.Count - 1; i >= 0; i--) if ((_floaters[i].Age += realDt) >= _floaters[i].Life) _floaters.RemoveAt(i); } /// Raserei: Kamera fährt heran, Arena wird dunkel, Funken wirbeln erst zur Brust (Aufladen) /// und steigen dann als Glut auf; bei voller Wut glimmt der Gladiator. void FuryUpdate(float realDt) { var pl = Duel.Player; bool fury = pl.State == DuelState.Super; _furyDark += ((fury ? 1f : 0f) - _furyDark) * (1 - MathF.Exp(-realDt * (fury ? 7 : 2.5f))); if (fury && _phase == Phase.Fight) _cam.FocusX = (_pv.X + _ev.X) / 2; else if (_phase == Phase.Fight && _cam.FocusX != null) _cam.FocusX = null; if (_calm || !(fury || pl.Rage >= 100)) return; if ((_emberIn -= realDt) > 0) return; var rnd = Random.Shared; var chest = _pv.Chest; float r = Stage.FigH; if (!fury) { _emberIn = 0.09f; // volle Wut: leises Glimmen _fx.Sparks(chest + new Vector2((float)(rnd.NextDouble() - 0.5) * r * 0.5f, (float)rnd.NextDouble() * r * 0.4f), 1, new Color(255, 140, 40), -MathF.PI / 2, 0.4f, 220); return; } _emberIn = 0.016f; if (pl.StateTime < Duel.SUPER_CHARGE) { // Aufladen: Funken strömen von allen Seiten zur Brust for (int i = 0; i < 3; i++) { float a = (float)(rnd.NextDouble() * MathF.Tau); var from = chest + new Vector2(MathF.Cos(a), MathF.Sin(a)) * r * (0.7f + (float)rnd.NextDouble() * 0.5f); _fx.Sparks(from, 1, rnd.Next(2) == 0 ? new Color(255, 170, 50) : new Color(255, 80, 30), a + MathF.PI, 0.15f, 700); } if (rnd.NextDouble() < 0.3) _fx.Dust(new Vector2(_pv.X, Stage.FloorY), 2, 160, 40, 70); } else { // Hiebe: Glut steigt auf, Feuer am Boden _fx.Sparks(chest + new Vector2((float)(rnd.NextDouble() - 0.5) * r * 0.6f, (float)(rnd.NextDouble() - 0.2) * r * 0.6f), 2, rnd.Next(3) == 0 ? new Color(255, 230, 120) : new Color(255, 110, 30), -MathF.PI / 2, 0.6f, 380); } } static float Lag(float lag, float value, float dt) => lag <= value ? value : MathF.Max(value, lag - dt * 0.6f); void Controls(Input i) { Duel.MoveDir = (i.Down(Keys.D, Keys.Right) ? 1 : 0) - (i.Down(Keys.A, Keys.Left) ? 1 : 0); Duel.BlockHeld = i.RightHeld || i.Down(Keys.K, Keys.LeftShift); if (i.LeftClick || i.Pressed(Keys.J)) Duel.PressAttack(); if (i.Pressed(Keys.Space)) Duel.PressLeap(); if (i.Pressed(Keys.S) || i.Pressed(Keys.Down)) Duel.PressDodge(); if (i.Pressed(Keys.R)) Duel.PressSuper(); if (i.Pressed(Keys.Q)) Duel.PressSpecial(); if (i.Pressed(Keys.W)) Duel.PressHeavy(); if (i.Pressed(Keys.E)) Duel.PressWall(); } void HandleEvents() { foreach (var e in Duel.Events) { var targetView = e.ByPlayer ? _ev : _pv; var actorView = e.ByPlayer ? _pv : _ev; var target = e.ByPlayer ? Duel.Enemy : Duel.Player; var at = targetView.Chest - new Vector2(target.Facing * 60, 0); switch (e.Type) { case DuelEventType.Hit: if (e.ByPlayer && Duel.Player.State == DuelState.Super && !_calm) { bool last = Duel.Player.SuperHits >= Duel.SUPER_HITS.Length; _hitstop = Math.Max(_hitstop, last ? 0.22f : 0.14f); _cam.Shake(last ? 1f : 0.75f); _cam.Punch(last ? 0.14f : 0.09f, at); _screenFlash = last ? 0.7f : 0.35f; _flashColor = last ? new Color(255, 240, 210) : new Color(255, 130, 40); _fx.Ring(at, new Color(255, 120, 30), last ? 1100 : 650, last ? 0.7f : 0.4f); _fx.Ring(at, new Color(255, 220, 140), last ? 600 : 360, 0.3f); _fx.Sparks(at, last ? 110 : 55, new Color(255, 160, 50), target.Facing > 0 ? MathF.PI : 0, last ? MathF.PI : 1.4f, last ? 1700 : 1300); _fx.Dust(new Vector2(targetView.X, Stage.FloorY), last ? 26 : 12, 160, 120, 110); _crowd.Excite(last ? 1 : 0.5f); if (last) { _crowd.Wave(); SoundManager.PlayCheer(); } } bool heavy = e.ByPlayer && (Duel.Player.Heavy || Duel.Player.State is DuelState.Leap or DuelState.Super); _hitstop = Math.Max(_hitstop, e.Crit || heavy ? 0.13f : 0.075f); _cam.Shake(e.Crit || heavy ? 0.6f : 0.38f); _cam.Punch(e.Crit ? 0.07f : 0.04f, at); _fx.Sparks(at, e.Crit ? 34 : 18, e.Crit ? D.Gold : new Color(255, 230, 190), target.Facing > 0 ? MathF.PI : 0, 1.1f); _fx.Dust(new Vector2(targetView.X, Stage.FloorY), 6, 50, 80, 70); targetView.Hurt(e.Crit); _crowd.Excite(e.Crit ? 0.45f : 0.2f); Float("-" + NumberFormat.Format(e.Amount) + (e.Crit ? "!" : ""), at - new Vector2(0, 120), e.ByPlayer ? (e.Crit ? D.Gold : Color.White) : D.Red, e.Crit ? 62 : 44); SoundManager.PlayHit(); if (e.Crit) SoundManager.PlayCheer(); break; case DuelEventType.Blocked: var blockerView = e.ByPlayer ? _pv : _ev; var blocker = e.ByPlayer ? Duel.Player : Duel.Enemy; var bp = blockerView.Front; _hitstop = Math.Max(_hitstop, 0.045f); _cam.Shake(0.18f); _fx.Sparks(bp, 14, new Color(190, 215, 255), blocker.Facing > 0 ? 0 : MathF.PI, 0.9f, 700); _fx.Chips(bp, 4, new Color(120, 95, 70), -blocker.Facing); blockerView.Blocked(); Float(L.t("duel.blocked"), bp - new Vector2(0, 150), D.Blue, 30); SoundManager.PlayBlock(); break; case DuelEventType.Parry: var pv = e.ByPlayer ? _pv : _ev; _hitstop = Math.Max(_hitstop, 0.17f); _cam.Shake(0.55f); _cam.Punch(0.08f, pv.Front); _screenFlash = 0.35f; _flashColor = new Color(220, 235, 255); _fx.Ring(pv.Front, new Color(200, 225, 255)); _fx.Sparks(pv.Front, 40, Color.White, 0, MathF.PI, 1100); pv.Parried(); _crowd.Excite(0.6f); Big(L.t("duel.parry"), new Color(220, 235, 255)); SoundManager.PlayBlock(); SoundManager.PlayCheer(); break; case DuelEventType.Dodged: Float(L.t("duel.dodged"), targetView.Chest - new Vector2(0, 180), D.Sand, 30); _fx.Dust(new Vector2(targetView.X, Stage.FloorY), 8, 80, 40, 60); _crowd.Excite(0.15f); break; case DuelEventType.GuardBreak: _cam.Shake(0.45f); _fx.Chips(targetView.Front, 12, new Color(140, 110, 80), target.Facing); Big(L.t("duel.guardbreak"), D.Red); break; case DuelEventType.Special: _cam.Shake(0.3f); _crowd.Excite(0.35f); _fx.Ring(_pv.Chest, D.Blue, 520, 0.45f); Big(L.t(TextKeys.Of(Duel.PlayerSpecial)), D.Blue); SoundManager.PlayCheer(); break; case DuelEventType.Leap: _fx.Dust(new Vector2(_pv.X, Stage.FloorY), 10, 90, 50, 70); _crowd.Excite(0.15f); break; case DuelEventType.Super: _slowmo = _calm ? 0 : 0.9f; _cam.Shake(0.5f); _cam.Punch(0.08f, _pv.Chest); _screenFlash = 0.4f; _flashColor = new Color(255, 170, 60); _fx.Ring(_pv.Chest, new Color(255, 150, 40), 700, 0.6f); _fx.Sparks(_pv.Chest, 50, D.Gold, -MathF.PI / 2, MathF.PI, 1000); Big(L.t("duel.super"), new Color(255, 170, 60)); _fx.Ring(new Vector2(_pv.X, Stage.FloorY), new Color(255, 120, 30), 1400, 0.8f); // Druckwelle am Boden _fx.Dust(new Vector2(_pv.X, Stage.FloorY), 40, 260, 70, 130); _crowd.Wave(petals: false); SoundManager.PlayLevelUp(); SoundManager.PlayCheer(); break; case DuelEventType.SuperReady: Float(L.t("duel.super.ready"), _pv.Chest - new Vector2(0, 230), new Color(255, 170, 60), 34); break; case DuelEventType.Heal: _pv.Heal(); _fx.Sparks(_pv.Chest, 20, D.Green, -MathF.PI / 2, 0.6f, 500); Float("+" + NumberFormat.Format(e.Amount), _pv.Chest - new Vector2(0, 160), D.Green, 40); break; case DuelEventType.Ko: _slowmo = _calm ? 0 : 1.4f; _hitstop = 0.2f; _cam.Shake(0.9f); _cam.Punch(0.12f, at); _screenFlash = 0.5f; _flashColor = Color.White; _fx.Sparks(at, 60, D.Gold, 0, MathF.PI, 1300); _fx.Ring(at, D.Gold, 700, 0.6f); _fx.Dust(new Vector2(targetView.X, Stage.FloorY), 20, 120, 120, 110); _crowd.Excite(1f); if (e.ByPlayer) _crowd.Wave(); if (e.ByPlayer) SoundManager.PlayCheer(); else SoundManager.PlayBoo(); break; } } Duel.Events.Clear(); } /// Auftritt des Champions: Clip bildschirmfüllend mit Kinobalken, Name und Titel. void DrawIntro(SpriteBatch sb, float scale, Vector2 offset) { var ui = Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0); sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui); float p = Math.Clamp(_phaseTime / INTRO, 0, 1); var frames = _introClip != null ? ClipCache.Video(_introClip) : null; var tex = frames != null ? frames[Math.Min(frames.Length - 1, (int)(p * (frames.Length - 1)))] : _backdrop; if (tex != null) { float k = (1.04f + 0.05f * p) * MathF.Max(Camera.W / tex.Width, Camera.H / tex.Height); float fade = Math.Clamp(_phaseTime / 0.5f, 0, 1) * Math.Clamp((INTRO - _phaseTime) / 0.4f, 0, 1); sb.Draw(tex, new Vector2(Camera.W / 2, Camera.H / 2), null, Color.White * fade, 0, new Vector2(tex.Width / 2f, tex.Height / 2f), k, SpriteEffects.None, 0); } float bar = Camera.H * 0.11f; 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 ta = Math.Clamp((_phaseTime - 0.8f) / 0.6f, 0, 1); D.Glow(sb, new Vector2(Camera.W / 2, Camera.H * 0.78f), new Vector2(Camera.W * 1.4f, 380), Color.Black * (0.7f * ta)); D.Text(sb, Assets.SansBold, 26, L.t("duel.champion").ToUpperInvariant(), new Vector2(Camera.W / 2, Camera.H * 0.72f), D.Sand * ta, Align.Center); D.Text(sb, Assets.Serif, 96, _enemy.Name, new Vector2(Camera.W / 2, Camera.H * 0.80f), D.Gold * ta, Align.Center, 1.15f - 0.15f * ta); D.Text(sb, Assets.Sans, 18, L.t("freedom.skip"), new Vector2(Camera.W - 40, Camera.H - bar / 2), D.Sand * 0.6f, Align.Right); sb.End(); } void Float(string text, Vector2 pos, Color c, float size) => _floaters.Add(new Floater { Text = text, Pos = pos, Color = c, Size = size }); void Big(string text, Color c) => _floaters.Add(new Floater { Text = text, Pos = new Vector2(Camera.W / 2, 230), Color = c, Size = 96, Big = true, Life = 1.0f }); // ── Zeichnen ──────────────────────────────────────────────── public void Draw(GraphicsDevice gd, SpriteBatch sb, BasicEffect fx, float scale, Vector2 offset) { D.UiScale = scale; if (_phase == Phase.Intro) { DrawIntro(sb, scale, offset); return; } var view = _cam.View(scale, offset); fx.View = view; fx.Projection = Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 0, 1); // Hintergrund: Arena (Wan-Loop, sonst Standbild) mit Parallaxe, abgedunkelt, Vignette sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, _cam.View(scale, offset, 0.35f)); var loop = _loopName != null ? ClipCache.Video(_loopName) : null; var bg = loop != null ? loop[PingPong(_time * 8, loop.Length)] : _backdrop; if (bg != null) { float k = 1.18f * MathF.Max(Camera.W / bg.Width, Camera.H / bg.Height); sb.Draw(bg, new Vector2(Camera.W / 2, Camera.H / 2), null, new Color(0.66f, 0.62f, 0.58f), 0, new Vector2(bg.Width / 2f, bg.Height / 2f), k, SpriteEffects.None, 0); } sb.End(); // Boden, Schatten, Staub (Kampfebene) sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, view); if (_furyDark > 0.01f) // Raserei: Arena versinkt im Dunkel, nur die Kämpfer bleiben im Licht D.Rect(sb, new RectangleF(-3000, -3000, Camera.W + 6000, Camera.H + 6000), new Color(20, 4, 0) * (0.62f * _furyDark)); D.Rect(sb, new RectangleF(-1200, Stage.FloorY + 30, Camera.W + 2400, 900), Color.Black * 0.35f); D.Glow(sb, new Vector2(Camera.W / 2, Stage.FloorY + 20), new Vector2(3600, 260), Color.Black * 0.45f); _pv.DrawShadow(sb); _ev.DrawShadow(sb); sb.End(); // warmer Lichtkegel auf dem Sand, wo gekämpft wird sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, view); D.Glow(sb, new Vector2((_pv.X + _ev.X) / 2, Stage.FloorY + 10), new Vector2(1500, 230), new Color(255, 180, 110) * 0.22f); if (_furyDark > 0.01f) { float flicker = 0.8f + 0.2f * MathF.Sin((float)_time * 23) * MathF.Sin((float)_time * 7.3f); D.Glow(sb, new Vector2(_pv.X, Stage.FloorY), new Vector2(900, 220), new Color(255, 100, 20) * (0.75f * _furyDark * flicker)); D.Glow(sb, _pv.Chest, new Vector2(Stage.FigH * 2.2f), new Color(255, 120, 30) * (0.35f * _furyDark * flicker)); } sb.End(); sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, view); _fx.DrawSoft(sb); DrawSmear(sb, _pv, Duel.Player); DrawSmear(sb, _ev, Duel.Enemy); sb.End(); // Kämpfer (Gitter auf der GPU) gd.BlendState = BlendState.AlphaBlend; gd.SamplerStates[0] = SamplerState.LinearClamp; gd.RasterizerState = RasterizerState.CullNone; gd.DepthStencilState = DepthStencilState.None; if (_pv.Is3D || _ev.Is3D) gd.Clear(ClearOptions.DepthBuffer, Color.Transparent, 1, 0); // 3D-Figuren verdecken sich richtig var e = Duel.Enemy; var p = Duel.Player; if (e.State == DuelState.Windup) // fair: der Schlag kündigt sich rot an { float k = (float)Math.Min(1, e.StateTime / e.Windup); _ev.DrawAura(gd, fx, new Color(255, 60, 40) * (0.55f * k), 0.035f * k); } if (p.State == DuelState.Wall || p.Invulnerable > 0) _pv.DrawAura(gd, fx, D.Blue * 0.5f, 0.03f); if (p.Heavy && p.State == DuelState.Windup) _pv.DrawAura(gd, fx, new Color(255, 150, 40) * 0.6f, 0.035f); if (p.State == DuelState.Super) // Raserei: lodernde Doppel-Aura { float pulse = 0.65f + 0.35f * MathF.Sin((float)_time * 18); _pv.DrawAura(gd, fx, new Color(255, 60, 10) * (0.45f * pulse), 0.11f); _pv.DrawAura(gd, fx, new Color(255, 170, 50) * (0.8f * pulse), 0.05f); } else if (p.Rage >= 100) _pv.DrawAura(gd, fx, new Color(255, 130, 30) * (0.28f + 0.14f * MathF.Sin((float)_time * 6)), 0.03f); // wer gerade zuschlägt, liegt vorn bool enemyFront = e.State is DuelState.Strike or DuelState.Windup && p.State is not (DuelState.Strike or DuelState.Windup); if (enemyFront) { _pv.DrawBody(gd, fx, p, _calm); _ev.DrawBody(gd, fx, e, _calm); } else { _ev.DrawBody(gd, fx, e, _calm); _pv.DrawBody(gd, fx, p, _calm); } // Licht und Funken (additiv) sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, view); _fx.DrawAdd(sb); if (e.State == DuelState.Windup) { float k = (float)Math.Min(1, e.StateTime / e.Windup); D.Text(sb, Assets.Serif, 90, "!", new Vector2(_ev.X, Stage.FloorY - Stage.FigH - 40), new Color(255, 90, 60) * k, Align.Center, 1 + 0.3f * (1 - k), false); // i18n-ok } if (p.State == DuelState.Stunned || e.State == DuelState.Stunned) foreach (var (v, f) in new[] { (_pv, p), (_ev, e) }) if (f.State == DuelState.Stunned) for (int i = 0; i < 3; i++) { double a = _time * 5 + i * 2.1; D.Glow(sb, new Vector2(v.X + (float)Math.Cos(a) * 60, Stage.FloorY - Stage.FigH + 10 + (float)Math.Sin(a) * 14), new Vector2(34), D.Gold); } sb.End(); // Publikum vorne (Parallaxe > 1), Licht von oben, Vignette sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, _cam.View(scale, offset, 1.35f)); _crowd.Draw(sb, _calm); sb.End(); var ui = Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0); sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui); DrawVignette(sb); // wenig Leben: roter Puls am Rand float low = (float)(Duel.Player.Hp / Duel.Player.MaxHp); if (low < 0.3f && Duel.Player.Alive) { float pulse = (0.3f - low) / 0.3f * (0.55f + 0.45f * MathF.Sin((float)_time * 6)); var red = new Color(160, 10, 0) * (0.6f * pulse); D.Glow(sb, new Vector2(-150, Camera.H / 2), new Vector2(800, 1800), red); D.Glow(sb, new Vector2(Camera.W + 150, Camera.H / 2), new Vector2(800, 1800), red); } sb.End(); sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, ui); D.Glow(sb, new Vector2(Camera.W * 0.5f, -120), new Vector2(2400, 900), new Color(255, 190, 120) * 0.16f); if (_screenFlash > 0) D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), _flashColor * (_screenFlash * 0.5f)); sb.End(); // Zahlen über den Köpfen (Kamera) und HUD (Bildschirm) sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, view); foreach (var f in _floaters) if (!f.Big) DrawFloater(sb, f); sb.End(); sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui); foreach (var f in _floaters) if (f.Big) DrawFloater(sb, f); DrawHud(sb); sb.End(); _bar.Draw(gd, sb, ui); } static int PingPong(double t, int n) { int period = 2 * (n - 1), i = (int)t % period; return i < n ? i : period - i; } void DrawVignette(SpriteBatch sb) { // Ränder abdunkeln: vier weiche, große Flecken außerhalb des Bilds var c = Color.Black * 0.75f; D.Glow(sb, new Vector2(-200, Camera.H / 2), new Vector2(900, 2000), c); D.Glow(sb, new Vector2(Camera.W + 200, Camera.H / 2), new Vector2(900, 2000), c); D.Glow(sb, new Vector2(Camera.W / 2, -160), new Vector2(3200, 520), Color.Black * 0.5f); } /// Wischspur der Waffe beim Schlag: Bogen aus weichen Lichtpunkten vor der Figur. void DrawSmear(SpriteBatch sb, FighterView v, DuelFighter f) { if (_calm || f.State != DuelState.Strike) return; float k = MathHelper.Clamp((float)(f.StateTime / f.StrikeTime), 0, 1); var c = new Vector2(v.X + f.Facing * 60, Stage.FloorY - Stage.FigH * 0.55f); const int N = 16; for (int i = 0; i < N; i++) { float s = i / (float)(N - 1); if (s > k + 0.15f) break; float a = MathHelper.Lerp(-1.9f, 0.7f, s); var pos = c + new Vector2(MathF.Cos(a) * f.Facing, MathF.Sin(a)) * (250 + 20 * s); float fade = MathF.Max(0, 1 - (k - s) * 2.2f) * (f.Heavy ? 0.9f : 0.6f); var col = f.Heavy ? new Color(255, 170, 70) : new Color(255, 245, 225); D.Glow(sb, pos, new Vector2(70, 26), col * fade); } } void DrawFloater(SpriteBatch sb, Floater f) { float k = f.Age / f.Life; float pop = f.Big ? 1 + 0.6f * MathF.Max(0, 1 - f.Age * 6) : 1 + 0.5f * MathF.Max(0, 1 - f.Age * 8); float a = MathHelper.Clamp((1 - k) * 2.5f, 0, 1); var pos = f.Pos - new Vector2(0, f.Big ? 0 : 110 * MathF.Sqrt(k)); D.Text(sb, f.Big ? Assets.Serif : Assets.SansBold, f.Size, f.Text, pos, f.Color * a, Align.Center, pop); } void DrawHud(SpriteBatch sb) { var p = Duel.Player; var e = Duel.Enemy; float a = _phase == Phase.Countdown ? MathHelper.Clamp(_phaseTime * 2, 0, 1) : 1; // Spieler links oben float nx = 70; if (Assets.Sprite(_game.Look.EmblemArt) is Texture2D em) { sb.Draw(em, new Vector2(100, 62), null, Color.White * a, 0, new Vector2(em.Width / 2f, em.Height / 2f), 64f / em.Width, SpriteEffects.None, 0); nx = 144; } D.Text(sb, Assets.Serif, 34, $"{_game.Name} · {L.t(_game.ClassDef.Key)}", new Vector2(nx, 58), D.Gold * a); D.Bar(sb, new RectangleF(70, 88, 700, 34), (float)(p.Hp / p.MaxHp), _pLag, D.Green); D.Bar(sb, new RectangleF(70, 128, 460, 16), (float)(p.Stamina / 100), (float)(p.Stamina / 100), D.Gold); // Wut: voll → R für den Super-Angriff (pulsiert) bool full = p.Rage >= 100; float pulse = full ? 0.75f + 0.25f * MathF.Sin((float)_time * 8) : 1; D.Bar(sb, new RectangleF(70, 150, 460, 12), (float)(p.Rage / 100), (float)(p.Rage / 100), new Color(255, 140, 40) * pulse); D.Text(sb, Assets.SansBold, 16, L.t(full ? "duel.super.key" : "duel.rage"), new Vector2(544, 156), full ? new Color(255, 170, 60) * pulse : D.Sand * 0.8f); // Gegner rechts oben D.Text(sb, Assets.Serif, 34, _enemy.Name, new Vector2(Camera.W - 70, 58), D.Red * a, Align.Right); D.Bar(sb, new RectangleF(Camera.W - 770, 88, 700, 34), (float)(e.Hp / e.MaxHp), _eLag, D.Red, fromRight: true); D.Text(sb, Assets.Sans, 15, L.t("mono.help"), new Vector2(Camera.W / 2, Camera.H - 13), D.Sand * 0.8f, Align.Center); if (_phase == Phase.Countdown) { int n = 3 - (int)(_phaseTime / (COUNTDOWN / 3)); float k = _phaseTime % (COUNTDOWN / 3) / (COUNTDOWN / 3); if (n >= 1) D.Text(sb, Assets.Serif, 200, n.ToString(NumberFormat.Culture), new Vector2(Camera.W / 2, 420), D.Gold * (1 - k * 0.7f), Align.Center, 1.5f - 0.5f * k); D.Text(sb, Assets.SansBold, 28, L.t(_enemy.Display != null ? "duel.legend" : _enemy.IsChampion ? "duel.champion" : "duel.practice").ToUpperInvariant(), new Vector2(Camera.W / 2, 600), D.Sand, Align.Center); } if (_phase == Phase.End) { float k = MathHelper.Clamp(_phaseTime / 0.6f, 0, 1); D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), Color.Black * (0.35f * k)); D.Text(sb, Assets.Serif, 170, L.t(Won ? "duel.win" : "duel.lose"), new Vector2(Camera.W / 2, 400), (Won ? D.Gold : D.Red) * k, Align.Center, 1 + 0.4f * (1 - k)); if (Finished) D.Text(sb, Assets.SansBold, 30, L.t("mono.next"), new Vector2(Camera.W / 2, 600), Color.White, Align.Center); } if (Paused) { D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), Color.Black * 0.6f); D.Text(sb, Assets.Serif, 110, L.t("duel.pause").ToUpperInvariant(), new Vector2(Camera.W / 2, 420), D.Gold, Align.Center); D.Text(sb, Assets.SansBold, 28, L.t("mono.pausehelp"), new Vector2(Camera.W / 2, 560), Color.White, Align.Center); } } public void GiveUp() { Paused = false; Duel.Surrender(); _phase = Phase.End; _phaseTime = 0; Won = false; SoundManager.PlayDefeat(); } } }