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:
151
Mono/Arena/AbilityBar.cs
Normal file
151
Mono/Arena/AbilityBar.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using GladiatorIdle.Gfx;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using D = GladiatorIdle.Gfx.Draw;
|
||||
|
||||
namespace GladiatorIdle.Arena
|
||||
{
|
||||
/// <summary>
|
||||
/// Fähigkeiten-Leiste unten (Q, W, E): Bronze-Unterlage, Medaillons mit Tasten-Abzeichen,
|
||||
/// Abklingzeit als Uhrzeiger-Schatten mit Sekunden, Leuchten und Aufblitzen wenn bereit.
|
||||
/// Nicht gelernte Fähigkeiten sind als dunkle Fassung zu sehen.
|
||||
/// </summary>
|
||||
internal sealed class AbilityBar
|
||||
{
|
||||
public sealed class Slot
|
||||
{
|
||||
public string Key = "", Name = "";
|
||||
public Texture2D? Icon;
|
||||
public double Cooldown, Total = 1;
|
||||
public bool Learned = true, Usable = true;
|
||||
public Color Glow = D.Gold;
|
||||
internal float ReadyFlash;
|
||||
internal bool WasCooling;
|
||||
}
|
||||
|
||||
public readonly Slot[] Slots = { new(), new(), new() };
|
||||
const float SIZE = 118, GAP = 64;
|
||||
|
||||
readonly Texture2D? _bar = Assets.Sprite("hud_bar");
|
||||
BasicEffect? _flat;
|
||||
readonly VertexPositionColor[] _fan = new VertexPositionColor[3 * 64];
|
||||
double _t;
|
||||
|
||||
public void Update(float dt)
|
||||
{
|
||||
_t += dt;
|
||||
foreach (var s in Slots)
|
||||
{
|
||||
bool cooling = s.Cooldown > 0;
|
||||
if (s.WasCooling && !cooling) s.ReadyFlash = 1; // gerade bereit geworden
|
||||
s.WasCooling = cooling;
|
||||
s.ReadyFlash = MathF.Max(0, s.ReadyFlash - dt * 2.2f);
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 Badge(int i) => Center(i) + new Vector2(-SIZE * 0.40f, -SIZE * 0.40f);
|
||||
|
||||
Vector2 Center(int i) => new(Camera.W / 2 + (i - 1) * (SIZE + GAP), Camera.H - 112);
|
||||
|
||||
public void Draw(GraphicsDevice gd, SpriteBatch sb, Matrix ui)
|
||||
{
|
||||
_flat ??= new BasicEffect(gd) { VertexColorEnabled = true, TextureEnabled = false, World = Matrix.Identity };
|
||||
_flat.View = ui;
|
||||
_flat.Projection = Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 0, 1);
|
||||
|
||||
// Unterlage und Medaillons
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
|
||||
if (_bar != null)
|
||||
{
|
||||
float w = 3 * SIZE + 2 * GAP + 190, h = w * _bar.Height / _bar.Width;
|
||||
sb.Draw(_bar, new Vector2(Camera.W / 2, Camera.H - 112), null, Color.White * 0.95f, 0,
|
||||
new Vector2(_bar.Width / 2f, _bar.Height / 2f), w / _bar.Width, SpriteEffects.None, 0);
|
||||
}
|
||||
else D.Glow(sb, new Vector2(Camera.W / 2, Camera.H - 112), new Vector2(760, 240), Color.Black * 0.7f);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var s = Slots[i]; var c = Center(i);
|
||||
D.Glow(sb, c + new Vector2(0, 8), new Vector2(SIZE * 1.25f), Color.Black * 0.7f); // Schatten
|
||||
if (s.Icon != null)
|
||||
{
|
||||
var tint = !s.Learned ? new Color(40, 34, 28) : s.Cooldown > 0 ? new Color(150, 140, 125) : !s.Usable ? new Color(200, 120, 110) : Color.White;
|
||||
float pop = 1 + 0.12f * s.ReadyFlash;
|
||||
sb.Draw(s.Icon, c, null, tint, 0, new Vector2(s.Icon.Width / 2f, s.Icon.Height / 2f), SIZE * pop / s.Icon.Width, SpriteEffects.None, 0);
|
||||
}
|
||||
}
|
||||
sb.End();
|
||||
|
||||
// Abklingzeit: dunkler Uhrzeiger-Schatten über dem Rest
|
||||
gd.BlendState = BlendState.AlphaBlend;
|
||||
gd.RasterizerState = RasterizerState.CullNone;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var s = Slots[i];
|
||||
if (!s.Learned || s.Cooldown <= 0) continue;
|
||||
Pie(gd, Center(i), SIZE * 0.47f, (float)Math.Clamp(s.Cooldown / s.Total, 0, 1), Color.Black * 0.62f);
|
||||
}
|
||||
|
||||
// Tasten-Abzeichen: Münze mit farbigem Rand
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var s = Slots[i];
|
||||
var badge = Badge(i);
|
||||
Pie(gd, badge, 25, 1, Color.Black * 0.8f);
|
||||
Pie(gd, badge, 21, 1, s.Learned ? s.Glow : D.Border);
|
||||
Pie(gd, badge, 17.5f, 1, new Color(22, 16, 10));
|
||||
}
|
||||
|
||||
// Leuchten wenn bereit (additiv)
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, ui);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var s = Slots[i]; var c = Center(i);
|
||||
if (!s.Learned) continue;
|
||||
if (s.Cooldown <= 0 && s.Usable)
|
||||
{
|
||||
float pulse = 0.22f + 0.1f * MathF.Sin((float)_t * 3 + i);
|
||||
D.Glow(sb, c, new Vector2(SIZE * 1.55f), s.Glow * pulse);
|
||||
}
|
||||
if (s.ReadyFlash > 0) D.Glow(sb, c, new Vector2(SIZE * (1.4f + 1.2f * (1 - s.ReadyFlash))), Color.White * (0.8f * s.ReadyFlash));
|
||||
}
|
||||
sb.End();
|
||||
|
||||
// Tasten-Abzeichen, Sekunden, Namen
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var s = Slots[i]; var c = Center(i);
|
||||
var badge = Badge(i);
|
||||
D.Text(sb, Assets.SansBold, 22, s.Key, badge + new Vector2(0, 1), s.Learned ? Color.White : D.Dim, Align.Center, 1, false);
|
||||
if (s.Learned && s.Cooldown > 0)
|
||||
D.Text(sb, Assets.SansBold, 38, Math.Ceiling(s.Cooldown).ToString(NumberFormat.Culture), c, Color.White, Align.Center);
|
||||
if (s.Learned)
|
||||
D.Text(sb, Assets.SansBold, 17, s.Name.ToUpperInvariant(), c + new Vector2(0, SIZE * 0.57f),
|
||||
s.Cooldown <= 0 ? D.Sand : D.Dim, Align.Center);
|
||||
}
|
||||
sb.End();
|
||||
}
|
||||
|
||||
/// Kreisausschnitt ab 12 Uhr im Uhrzeigersinn über <paramref name="frac"/> des Kreises.
|
||||
void Pie(GraphicsDevice gd, Vector2 c, float r, float frac, Color color)
|
||||
{
|
||||
const int SEG = 64;
|
||||
int n = Math.Max(1, (int)MathF.Ceiling(SEG * frac));
|
||||
float start = -MathF.PI / 2, sweep = MathF.Tau * frac;
|
||||
int v = 0;
|
||||
for (int k = 0; k < n; k++)
|
||||
{
|
||||
float a0 = start + sweep * k / n, a1 = start + sweep * (k + 1) / n;
|
||||
_fan[v++] = new VertexPositionColor(new Vector3(c, 0), color);
|
||||
_fan[v++] = new VertexPositionColor(new Vector3(c + new Vector2(MathF.Cos(a0), MathF.Sin(a0)) * r, 0), color);
|
||||
_fan[v++] = new VertexPositionColor(new Vector3(c + new Vector2(MathF.Cos(a1), MathF.Sin(a1)) * r, 0), color);
|
||||
}
|
||||
foreach (var pass in _flat!.CurrentTechnique.Passes)
|
||||
{
|
||||
pass.Apply();
|
||||
gd.DrawUserPrimitives(PrimitiveType.TriangleList, _fan, 0, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
63
Mono/Arena/Camera.cs
Normal file
63
Mono/Arena/Camera.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace GladiatorIdle.Arena
|
||||
{
|
||||
/// <summary>
|
||||
/// Kamera der Arena in Design-Pixeln: folgt den Kämpfern, zoomt bei Nähe heran, ruckt bei
|
||||
/// Treffern (Trauma² als Stärke) und stößt kurz in Richtung des Aufpralls (Punch).
|
||||
/// </summary>
|
||||
internal sealed class Camera
|
||||
{
|
||||
public const float W = 1920, H = 1080;
|
||||
public Vector2 Center = new(W / 2, H / 2);
|
||||
public float Zoom = 1f;
|
||||
float _trauma, _punch;
|
||||
Vector2 _punchAt;
|
||||
double _t;
|
||||
|
||||
public void Shake(float amount) => _trauma = MathF.Min(1, _trauma + amount);
|
||||
|
||||
/// Nach dem Kampf: langsam auf den Sieger zufahren (null = wieder beide zeigen).
|
||||
public float? FocusX;
|
||||
|
||||
public void Punch(float amount, Vector2 at) { _punch = MathF.Max(_punch, amount); _punchAt = at; }
|
||||
|
||||
/// Ziel: Mitte zwischen den Kämpfern, je näher, desto enger.
|
||||
public void Update(float dt, float x1, float x2, bool calm)
|
||||
{
|
||||
_t += dt;
|
||||
float mid = (x1 + x2) / 2, dist = MathF.Abs(x2 - x1);
|
||||
float targetZoom = MathHelper.Clamp(1.2f - dist / 3000f, 1.0f, 1.12f);
|
||||
var target = new Vector2(MathHelper.Clamp(mid, W / 2 - 220, W / 2 + 220), H / 2 + 40);
|
||||
float k = 1 - MathF.Exp(-dt * 3.5f);
|
||||
if (FocusX is float fx) { targetZoom = 1.4f; target = new Vector2(fx, H / 2 + 30); k = 1 - MathF.Exp(-dt * 1.2f); }
|
||||
Center += (target - Center) * k;
|
||||
Zoom += (targetZoom - Zoom) * k;
|
||||
_trauma = MathF.Max(0, _trauma - dt * 1.7f);
|
||||
_punch *= MathF.Exp(-dt * 9f);
|
||||
if (calm) { _trauma = 0; _punch = 0; }
|
||||
}
|
||||
|
||||
/// Kameraverschiebung durch Rütteln (Design-Pixel).
|
||||
Vector2 ShakeOffset()
|
||||
{
|
||||
float s = _trauma * _trauma * 26;
|
||||
return new Vector2(
|
||||
s * (MathF.Sin((float)_t * 71) + 0.6f * MathF.Sin((float)_t * 133 + 1.3f)) / 1.6f,
|
||||
s * (MathF.Cos((float)_t * 89) + 0.6f * MathF.Sin((float)_t * 151 + 0.7f)) / 1.6f);
|
||||
}
|
||||
|
||||
/// Design-Pixel → Bildschirm. <paramref name="parallax"/>: 1 = Ebene der Kämpfer, <1 weiter hinten.
|
||||
public Matrix View(float screenScale, Vector2 offset, float parallax = 1f)
|
||||
{
|
||||
float zoom = 1 + (Zoom - 1) * parallax + _punch * parallax;
|
||||
var c = new Vector2(W / 2, H / 2) + (Center - new Vector2(W / 2, H / 2)) * parallax
|
||||
+ (_punchAt - Center) * _punch * 0.6f * parallax;
|
||||
var shake = ShakeOffset() * parallax;
|
||||
return Matrix.CreateTranslation(-c.X, -c.Y, 0) * Matrix.CreateScale(zoom)
|
||||
* Matrix.CreateTranslation(W / 2 + shake.X, H / 2 + shake.Y, 0)
|
||||
* Matrix.CreateScale(screenScale) * Matrix.CreateTranslation(offset.X, offset.Y, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
308
Mono/Arena/CreatorScene.cs
Normal file
308
Mono/Arena/CreatorScene.cs
Normal file
@@ -0,0 +1,308 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
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>
|
||||
/// Eigenen Gladiator zusammenstellen: Klasse, Vorlage, Teamfarbe, Wappen, Startpunkte,
|
||||
/// Startfähigkeit und Name. Links eine große Vorschau, die ab und zu zuschlägt, blockt und jubelt.
|
||||
/// </summary>
|
||||
internal sealed class CreatorScene
|
||||
{
|
||||
public GladiatorClass Class { get; private set; } = GladiatorClass.Murmillo;
|
||||
public int Preset { get; private set; } = 1;
|
||||
public int Tint { get; private set; }
|
||||
public int Emblem { get; private set; }
|
||||
public int[] Bonus { get; } = new int[4];
|
||||
public string? StartSkill { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public bool Done { get; private set; }
|
||||
|
||||
readonly Ui _ui = new();
|
||||
readonly Particles _fx = new();
|
||||
readonly Texture2D? _backdrop = Assets.Sprite("arena_ludus", "jpg");
|
||||
FighterView _preview = null!;
|
||||
readonly DuelFighter _dummy = new() { IsPlayer = true, X = 0, Facing = 1, MaxHp = 1, Hp = 1 };
|
||||
double _t, _showAt = 2.5;
|
||||
int _show;
|
||||
string? _hoverSkill;
|
||||
|
||||
public Appearance Look => new(Preset, Tint, Emblem);
|
||||
int Left => GameState.CREATE_POINTS - Bonus.Sum();
|
||||
|
||||
public CreatorScene(string name)
|
||||
{
|
||||
Name = name;
|
||||
SetClass(Class);
|
||||
SoundManager.StartAmbient("music_menu");
|
||||
}
|
||||
|
||||
void SetClass(GladiatorClass c)
|
||||
{
|
||||
Class = c;
|
||||
if (StartSkill == null || !GameState.StartSkills(c).Any(s => s.Id == StartSkill))
|
||||
StartSkill = GameState.StartSkills(c).First().Id;
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
void Rebuild() => _preview = new FighterView(Art.Hero(Class, Preset), 0, Tint);
|
||||
|
||||
/// Getippte Zeichen (vom Fenster) für den Namen.
|
||||
public void OnText(char c, Keys key)
|
||||
{
|
||||
if (key == Keys.Back) { if (Name.Length > 0) Name = Name[..^1]; return; }
|
||||
if (key == Keys.Enter) return;
|
||||
if (!char.IsControl(c) && Name.Length < 18) Name += c;
|
||||
}
|
||||
|
||||
// ── Takt ────────────────────────────────────────────────────
|
||||
|
||||
public void Update(float dt, Input input, Matrix ui)
|
||||
{
|
||||
_t += dt;
|
||||
_ui.Begin(input, ui);
|
||||
ShowcaseStep(dt);
|
||||
_preview.Update(dt, dt, _dummy, 0, AppSettings.ReduceMotion);
|
||||
_fx.Motes(AppSettings.ReduceMotion ? 0 : 50, Camera.W, Camera.H);
|
||||
_fx.Update(dt);
|
||||
}
|
||||
|
||||
/// Vorschau: meist ruhig, dazwischen Schlag, Block oder Siegerpose.
|
||||
void ShowcaseStep(float dt)
|
||||
{
|
||||
_dummy.StateTime += dt;
|
||||
if (_dummy.State == DuelState.Ready && _t >= _showAt)
|
||||
{
|
||||
_show++;
|
||||
_dummy.Set(_show % 3 == 0 ? DuelState.Victory : _show % 3 == 1 ? DuelState.Windup : DuelState.Block);
|
||||
}
|
||||
switch (_dummy.State)
|
||||
{
|
||||
case DuelState.Windup when _dummy.StateTime > 0.35: _dummy.Set(DuelState.Strike); break;
|
||||
case DuelState.Strike when _dummy.StateTime > 0.15: _dummy.Set(DuelState.Recover); break;
|
||||
case DuelState.Recover when _dummy.StateTime > 0.5:
|
||||
case DuelState.Block when _dummy.StateTime > 1.2:
|
||||
case DuelState.Victory when _dummy.StateTime > 1.6:
|
||||
_dummy.Set(DuelState.Ready); _showAt = _t + 2.8; break;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Zeichnen ────────────────────────────────────────────────
|
||||
|
||||
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);
|
||||
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
|
||||
if (_backdrop != null)
|
||||
{
|
||||
float k = 1.1f * MathF.Max(Camera.W / _backdrop.Width, Camera.H / _backdrop.Height);
|
||||
sb.Draw(_backdrop, new Vector2(Camera.W / 2, Camera.H / 2), null, new Color(0.42f, 0.38f, 0.34f), 0,
|
||||
new Vector2(_backdrop.Width / 2f, _backdrop.Height / 2f), k, SpriteEffects.None, 0);
|
||||
}
|
||||
D.Glow(sb, new Vector2(-200, Camera.H / 2), new Vector2(900, 2000), Color.Black * 0.7f);
|
||||
D.Glow(sb, new Vector2(Camera.W + 200, Camera.H / 2), new Vector2(900, 2000), Color.Black * 0.7f);
|
||||
D.Text(sb, Assets.Serif, 56, L.t("create.title").ToUpperInvariant(), new Vector2(110, 78), D.Gold);
|
||||
sb.End();
|
||||
|
||||
// Vorschau: eigene Kamera (größer), Lichtkegel, Schatten, Figur
|
||||
var view = Matrix.CreateTranslation(0, -Stage.FloorY, 0) * Matrix.CreateScale(1.25f) * Matrix.CreateTranslation(470, 905, 0) * ui;
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, view);
|
||||
D.Glow(sb, new Vector2(0, Stage.FloorY - 300), new Vector2(900, 1100), new Color(255, 190, 120) * 0.16f);
|
||||
D.Glow(sb, new Vector2(0, Stage.FloorY + 6), new Vector2(700, 120), new Color(255, 180, 110) * 0.25f);
|
||||
sb.End();
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, view);
|
||||
_preview.DrawShadow(sb);
|
||||
sb.End();
|
||||
fx.View = view;
|
||||
fx.Projection = Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 0, 1);
|
||||
gd.BlendState = BlendState.AlphaBlend; gd.SamplerStates[0] = SamplerState.LinearClamp;
|
||||
gd.RasterizerState = RasterizerState.CullNone; gd.DepthStencilState = DepthStencilState.None;
|
||||
_preview.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);
|
||||
DrawNameField(sb);
|
||||
DrawOptions(sb);
|
||||
sb.End();
|
||||
}
|
||||
|
||||
void DrawNameField(SpriteBatch sb)
|
||||
{
|
||||
var r = new RectangleF(170, 968, 600, 68);
|
||||
D.Text(sb, Assets.SansBold, 20, L.t("create.name"), new Vector2(r.X, r.Y - 22), D.Sand);
|
||||
Ui.Panel(sb, r, D.Gold);
|
||||
// Wappen vor dem Namen
|
||||
if (Assets.Sprite(Look.EmblemArt) is Texture2D em)
|
||||
sb.Draw(em, new Vector2(r.X + 36, r.Center.Y), null, Color.White, 0, new Vector2(em.Width / 2f, em.Height / 2f), 54f / em.Width, SpriteEffects.None, 0);
|
||||
bool caret = _t % 1 < 0.55;
|
||||
D.Text(sb, Assets.Serif, 34, Name + (caret ? "|" : " "), new Vector2(r.X + 76, r.Center.Y), Color.White); // i18n-ok
|
||||
}
|
||||
|
||||
static void Header(SpriteBatch sb, string text, float y, float x = 930) =>
|
||||
D.Text(sb, Assets.Serif, 26, text, new Vector2(x, y), D.Gold);
|
||||
|
||||
void DrawOptions(SpriteBatch sb)
|
||||
{
|
||||
Ui.Panel(sb, new RectangleF(900, 40, 940, 900), null, 0.78f);
|
||||
float x0 = 930;
|
||||
|
||||
// Klasse
|
||||
Header(sb, L.t("create.class"), 76);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
var c = (GladiatorClass)i;
|
||||
if (_ui.Button(sb, new RectangleF(x0 + i * 222, 100, 210, 58), L.t(ClassDef.Of(c).Key), selected: Class == c, size: 22))
|
||||
SetClass(c);
|
||||
}
|
||||
|
||||
// Aussehen: drei Vorlagen in der gewählten Farbe
|
||||
Header(sb, L.t("create.look"), 192);
|
||||
for (int p = 1; p <= Appearance.PRESETS; p++)
|
||||
{
|
||||
var r = new RectangleF(x0 + (p - 1) * 160, 214, 148, 170);
|
||||
bool sel = Preset == p, hover = _ui.Hover(r);
|
||||
D.Rect(sb, r, new Color(30, 22, 15) * 0.9f);
|
||||
if (Assets.Sprite(Art.Hero(Class, p)) is Texture2D t)
|
||||
{
|
||||
var painted = Assets.Paint(t, Tint);
|
||||
float k = r.Height * 1.02f / t.Height;
|
||||
sb.Draw(painted, new Vector2(r.Center.X, r.Bottom - 2), null, Color.White, 0,
|
||||
new Vector2(t.Width / 2f, Stage.Feet), k, SpriteEffects.None, 0);
|
||||
}
|
||||
D.Frame(sb, r, sel ? D.Gold : hover ? D.Sand : D.Border, sel ? 3 : 2);
|
||||
if (_ui.Hit(r)) { Preset = p; Rebuild(); }
|
||||
}
|
||||
// Klassenbeschreibung neben den Vorlagen
|
||||
float dy = DrawWrapped(sb, L.t(ClassDef.Of(Class).Key + ".desc"), new RectangleF(x0 + 490, 226, 400, 120), 19, Align.Left);
|
||||
D.Text(sb, Assets.SansBold, 19, string.Format(L.t("select.special"), L.t(TextKeys.Of(ClassDef.Of(Class).Special))),
|
||||
new Vector2(x0 + 490, dy + 18), D.Blue);
|
||||
|
||||
// Farbe
|
||||
Header(sb, L.t("create.color"), 418);
|
||||
for (int i = 0; i < Appearance.Colors.Length; i++)
|
||||
{
|
||||
var tc = Appearance.Colors[i];
|
||||
var center = new Vector2(x0 + 30 + i * 74, 468);
|
||||
var r = new RectangleF(center.X - 30, center.Y - 30, 60, 60);
|
||||
bool sel = Tint == i, hover = _ui.Hover(r);
|
||||
var (cr, cg, cb) = Rgb(tc);
|
||||
Disc(sb, center, sel ? 64 : 56, sel ? D.Gold : hover ? D.Sand : D.Border);
|
||||
Disc(sb, center, sel ? 54 : 48, new Color(cr, cg, cb));
|
||||
if (_ui.Hit(r)) { Tint = i; Rebuild(); }
|
||||
}
|
||||
|
||||
// Wappen
|
||||
Header(sb, L.t("create.emblem"), 530);
|
||||
for (int i = 0; i < Appearance.Emblems.Length; i++)
|
||||
{
|
||||
var center = new Vector2(x0 + 36 + i * 74, 590);
|
||||
var r = new RectangleF(center.X - 34, center.Y - 34, 68, 68);
|
||||
bool sel = Emblem == i, hover = _ui.Hover(r);
|
||||
if (sel) D.Glow(sb, center, new Vector2(110), D.Gold * 0.5f);
|
||||
if (Assets.Sprite("emblem_" + Appearance.Emblems[i]) is Texture2D em)
|
||||
sb.Draw(em, center, null, sel || hover ? Color.White : new Color(160, 150, 140), 0,
|
||||
new Vector2(em.Width / 2f, em.Height / 2f), (sel ? 70f : 62f) / em.Width, SpriteEffects.None, 0);
|
||||
else Disc(sb, center, 56, sel ? D.Gold : D.Border); // Bild fehlt noch
|
||||
if (_ui.Hit(r)) Emblem = i;
|
||||
}
|
||||
if (Emblem >= 0) D.Text(sb, Assets.Sans, 18, L.t(Look.EmblemKey), new Vector2(x0 + 600, 530), D.Sand, Align.Right);
|
||||
|
||||
// Startpunkte
|
||||
Header(sb, string.Format(L.t("create.points"), Left), 662);
|
||||
var start = ClassDef.Of(Class).StartLevels;
|
||||
for (int s = 0; s < 4; s++)
|
||||
{
|
||||
float y = 700 + s * 46;
|
||||
D.Text(sb, Assets.Sans, 21, L.t(TextKeys.Of((Stat)s)), new Vector2(x0, y), D.Sand);
|
||||
D.Text(sb, Assets.SansBold, 24, (start[s] + Bonus[s]).ToString(NumberFormat.Culture), new Vector2(x0 + 260, y),
|
||||
Bonus[s] > 0 ? D.Gold : Color.White, Align.Right);
|
||||
int ss = s;
|
||||
if (_ui.Button(sb, new RectangleF(x0 + 290, y - 18, 44, 36), "−", Bonus[s] > 0, size: 22)) Bonus[ss]--; // i18n-ok
|
||||
if (_ui.Button(sb, new RectangleF(x0 + 342, y - 18, 44, 36), "+", Left > 0, size: 22)) Bonus[ss]++; // i18n-ok
|
||||
}
|
||||
|
||||
// Startfähigkeit
|
||||
Header(sb, L.t("create.skill"), 662, x0 + 450);
|
||||
_hoverSkill = null;
|
||||
var skills = GameState.StartSkills(Class).ToList();
|
||||
for (int i = 0; i < skills.Count; i++)
|
||||
{
|
||||
var sk = skills[i];
|
||||
var center = new Vector2(x0 + 520 + i * 120, 730);
|
||||
var r = new RectangleF(center.X - 46, center.Y - 46, 92, 92);
|
||||
bool sel = StartSkill == sk.Id, hover = _ui.Hover(r);
|
||||
if (hover) _hoverSkill = sk.Id;
|
||||
if (sel) D.Glow(sb, center, new Vector2(150), D.Gold * 0.55f);
|
||||
if (Assets.Sprite(sk.Icon) is Texture2D icon)
|
||||
sb.Draw(icon, center, null, sel || hover ? Color.White : new Color(150, 140, 125), 0,
|
||||
new Vector2(icon.Width / 2f, icon.Height / 2f), (sel ? 92f : 82f) / icon.Width, SpriteEffects.None, 0);
|
||||
if (_ui.Hit(r)) StartSkill = sk.Id;
|
||||
}
|
||||
string shown = _hoverSkill ?? StartSkill ?? skills[0].Id;
|
||||
var def = SkillDef.Get(shown);
|
||||
D.Text(sb, Assets.SansBold, 21, L.t(def.Key), new Vector2(x0 + 640, 806), D.Gold, Align.Center);
|
||||
DrawWrapped(sb, L.t(def.Desc), new RectangleF(x0 + 450, 826, 380, 90), 17);
|
||||
|
||||
// Los
|
||||
if (_ui.Button(sb, new RectangleF(1420, 962, 420, 80), L.t("create.start"), Name.Trim().Length > 0, size: 32))
|
||||
Done = true;
|
||||
}
|
||||
|
||||
void Disc(SpriteBatch sb, Vector2 c, float size, Color color) =>
|
||||
sb.Draw(Assets.Disc, c, null, color, 0, new Vector2(64), size / 128f, SpriteEffects.None, 0);
|
||||
|
||||
/// Einfacher Zeilenumbruch nach Wörtern.
|
||||
/// Liefert die y-Position unter der letzten Zeile.
|
||||
static float DrawWrapped(SpriteBatch sb, string text, RectangleF r, float px, Align align = Align.Center)
|
||||
{
|
||||
float x = align == Align.Left ? r.X : r.Center.X;
|
||||
var words = text.Split(' ');
|
||||
string line = "";
|
||||
float y = r.Y + px * 0.7f;
|
||||
foreach (var w in words)
|
||||
{
|
||||
string test = line.Length == 0 ? w : line + " " + w;
|
||||
if (D.Measure(Assets.Sans, px, test).X > r.Width && line.Length > 0)
|
||||
{
|
||||
D.Text(sb, Assets.Sans, px, line, new Vector2(x, y), D.Sand, align);
|
||||
y += px * 1.35f; line = w;
|
||||
}
|
||||
else line = test;
|
||||
}
|
||||
if (line.Length > 0) D.Text(sb, Assets.Sans, px, line, new Vector2(x, y), D.Sand, align);
|
||||
return y + px * 0.7f;
|
||||
}
|
||||
|
||||
/// Anzeigefarbe einer Teamfarbe (wie ein kräftiges Magenta nach dem Umfärben).
|
||||
static (float, float, float) Rgb(TeamColor c)
|
||||
{
|
||||
float s = MathHelper.Clamp(0.85f * c.Sat, 0, 1), v = MathHelper.Clamp(0.85f * c.Val, 0, 1);
|
||||
float h = c.Hue, ch = v * s, x = ch * (1 - MathF.Abs(h / 60 % 2 - 1)), m = v - ch;
|
||||
var (r, g, b) = h < 60 ? (ch, x, 0f) : h < 120 ? (x, ch, 0f) : h < 180 ? (0f, ch, x) : h < 240 ? (0f, x, ch) : h < 300 ? (x, 0f, ch) : (ch, 0f, x);
|
||||
return (r + m, g + m, b + m);
|
||||
}
|
||||
|
||||
// ── Testläufe ───────────────────────────────────────────────
|
||||
|
||||
/// Testlauf: eine bestimmte Zusammenstellung wählen.
|
||||
public void DevPick(GladiatorClass c, int preset, int color, int emblem)
|
||||
{
|
||||
SetClass(c); Preset = preset; Tint = color; Emblem = emblem;
|
||||
Bonus[0] = 2; Bonus[2] = 3;
|
||||
StartSkill = GameState.StartSkills(c).Last().Id;
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
public void Finish() => Done = true;
|
||||
}
|
||||
}
|
||||
157
Mono/Arena/Crowd.cs
Normal file
157
Mono/Arena/Crowd.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GladiatorIdle.Gfx;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace GladiatorIdle.Arena
|
||||
{
|
||||
/// <summary>
|
||||
/// Publikum im Vordergrund: zwei Reihen dunkler Zuschauer am unteren Rand (Gegenlicht). Jeder
|
||||
/// lebt für sich — atmet, wippt, dreht sich, jubelt mal spontan. Mit der Stimmung springen sie,
|
||||
/// recken die Fäuste (Wechsel ruhig/jubelnd im eigenen Takt) und schwanken; bei großen Momenten
|
||||
/// läuft eine Welle (La Ola) durch die Reihen und Blütenblätter fliegen in die Arena.
|
||||
/// Liegt vor der Kampfebene (Parallaxe > 1).
|
||||
/// </summary>
|
||||
internal sealed class Crowd
|
||||
{
|
||||
sealed class Fan
|
||||
{
|
||||
public Texture2D Calm = null!;
|
||||
public Texture2D? Cheer;
|
||||
public float X, H, Threshold, Phase, Shade, Pump, Temper;
|
||||
public bool Mirror, Cheering;
|
||||
public float Y, Vy, Tilt, Solo; // Sprunghöhe, Tempo nach oben, Neigung, spontaner Jubel (s)
|
||||
}
|
||||
|
||||
sealed class Petal { public Vector2 Pos, Vel; public float Spin, Angle, Life, Size; public Color Color; }
|
||||
|
||||
readonly List<Fan> _fans = new();
|
||||
readonly List<Petal> _petals = new();
|
||||
readonly Random _rng;
|
||||
float _excite;
|
||||
double _t;
|
||||
float _wave = -1; // Fortschritt der Welle (−1: keine)
|
||||
|
||||
public float Excitement => _excite;
|
||||
|
||||
public Crowd(int seed)
|
||||
{
|
||||
_rng = new Random(seed);
|
||||
var kinds = new List<(Texture2D, Texture2D?)>();
|
||||
for (int i = 1; i <= 6; i++)
|
||||
if (Assets.Sprite($"spectator_{i}") is Texture2D calm)
|
||||
kinds.Add((calm, Assets.Sprite($"spectator_{i}_cheer")));
|
||||
if (kinds.Count == 0) return;
|
||||
// zwei Reihen: hinten kleiner und heller, vorne größer und dunkler
|
||||
for (int row = 0; row < 2; row++)
|
||||
for (float x = -260 + _rng.Next(80); x < Camera.W + 260; x += row == 0 ? 95 : 130)
|
||||
{
|
||||
var (calm, cheer) = kinds[_rng.Next(kinds.Count)];
|
||||
_fans.Add(new Fan
|
||||
{
|
||||
Calm = calm, Cheer = cheer, X = x + _rng.Next(-30, 30), H = row == 0 ? 230 : 300,
|
||||
Threshold = 0.12f + (float)_rng.NextDouble() * 0.7f, Phase = (float)_rng.NextDouble() * 6.28f,
|
||||
Shade = row == 0 ? 0.13f : 0.07f, Mirror = _rng.Next(2) == 0,
|
||||
Pump = 2.2f + (float)_rng.NextDouble() * 2.4f, // Fäuste recken: eigener Takt
|
||||
Temper = 0.6f + (float)_rng.NextDouble() * 0.8f // wie wild gesprungen wird
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Stimmung steigern (0..1).
|
||||
public void Excite(float amount) => _excite = MathF.Min(1, _excite + amount);
|
||||
|
||||
/// La-Ola-Welle durch beide Reihen und Blütenblätter (Raserei, Sieg).
|
||||
public void Wave(bool petals = true)
|
||||
{
|
||||
_wave = 0;
|
||||
Excite(1);
|
||||
if (!petals) return;
|
||||
for (int i = 0; i < 70; i++)
|
||||
{
|
||||
var f = _fans.Count > 0 ? _fans[_rng.Next(_fans.Count)] : null;
|
||||
float x = f?.X ?? (float)_rng.NextDouble() * Camera.W;
|
||||
_petals.Add(new Petal
|
||||
{
|
||||
Pos = new Vector2(x, Camera.H + 40), Vel = new Vector2(((float)_rng.NextDouble() - 0.5f) * 500, -700 - (float)_rng.NextDouble() * 650),
|
||||
Spin = ((float)_rng.NextDouble() - 0.5f) * 14, Life = 2.6f + (float)_rng.NextDouble() * 1.4f,
|
||||
Size = 9 + (float)_rng.NextDouble() * 9,
|
||||
Color = _rng.Next(3) switch { 0 => new Color(220, 40, 50), 1 => new Color(255, 235, 220), _ => new Color(240, 170, 40) }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(float dt)
|
||||
{
|
||||
_t += dt;
|
||||
_excite = MathF.Max(0.05f, _excite - dt * 0.18f);
|
||||
float waveX = _wave < 0 ? -9999 : -300 + _wave * 2200;
|
||||
if (_wave >= 0 && (_wave += dt) > 1.4f) _wave = -1;
|
||||
foreach (var f in _fans)
|
||||
{
|
||||
// spontaner Jubel einzelner, auch wenn es ruhig ist
|
||||
if (f.Solo > 0) f.Solo -= dt;
|
||||
else if (_rng.NextDouble() < dt * 0.035) f.Solo = 0.8f + (float)_rng.NextDouble() * 1.2f;
|
||||
bool inWave = MathF.Abs(f.X - waveX) < 170;
|
||||
f.Cheering = inWave || f.Solo > 0 || (f.Cheering ? _excite > f.Threshold - 0.08f : _excite > f.Threshold);
|
||||
|
||||
// Sprünge mit Schwerkraft: jubelnd öfter und höher
|
||||
f.Vy -= 1900 * dt;
|
||||
f.Y = MathF.Max(0, f.Y + f.Vy * dt);
|
||||
if (f.Y <= 0)
|
||||
{
|
||||
f.Vy = 0;
|
||||
float chance = inWave ? 1 : f.Cheering ? 2.2f * f.Temper * dt : 0;
|
||||
if (_rng.NextDouble() < chance)
|
||||
f.Vy = (inWave ? 520 : 260 + 260 * _excite) * (0.7f + 0.5f * (float)_rng.NextDouble());
|
||||
}
|
||||
float tiltTarget = f.Cheering ? MathF.Sin((float)_t * 3.1f + f.Phase) * 0.09f * f.Temper
|
||||
: MathF.Sin((float)_t * 0.7f + f.Phase) * 0.025f;
|
||||
f.Tilt += (tiltTarget - f.Tilt) * MathF.Min(1, dt * 6);
|
||||
}
|
||||
for (int i = _petals.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var p = _petals[i];
|
||||
p.Vel.Y += 520 * dt;
|
||||
p.Vel *= MathF.Exp(-dt * 0.9f);
|
||||
p.Vel.X += MathF.Sin((float)_t * 2 + i) * 40 * dt; // flattern
|
||||
p.Pos += p.Vel * dt;
|
||||
p.Angle += p.Spin * dt;
|
||||
if ((p.Life -= dt) <= 0) _petals.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
/// Zeichnen in der Vordergrund-Ebene (eigene Kamera-Matrix mit Parallaxe).
|
||||
public void Draw(SpriteBatch sb, bool calm)
|
||||
{
|
||||
foreach (var f in _fans)
|
||||
{
|
||||
// jubelnd: Fäuste im eigenen Takt hoch und runter (Wechsel der Bilder)
|
||||
bool armsUp = f.Cheering && f.Cheer != null && (calm || MathF.Sin((float)_t * f.Pump + f.Phase) > -0.35f);
|
||||
var tex = armsUp ? f.Cheer! : f.Calm;
|
||||
float breathe = 1 + MathF.Sin((float)_t * 1.3f + f.Phase) * 0.012f;
|
||||
float bob = calm ? 0 : f.Cheering
|
||||
? f.Y + MathF.Abs(MathF.Sin((float)_t * 7.5f + f.Phase)) * 10
|
||||
: MathF.Sin((float)_t * 1.6f + f.Phase) * 3 + _excite * MathF.Abs(MathF.Sin((float)_t * 5 + f.Phase)) * 8;
|
||||
// in der Luft gestreckt, bei der Landung gestaucht
|
||||
float stretch = calm ? 1 : 1 + Math.Clamp(f.Vy / 4000f, -0.06f, 0.08f);
|
||||
float scale = f.H / tex.Height;
|
||||
float bottom = f.H > 260 ? Camera.H + 175 : Camera.H + 70;
|
||||
var pos = new Vector2(f.X, bottom - bob);
|
||||
var c = new Color(f.Shade * 1.1f, f.Shade * 0.9f, f.Shade * 0.75f);
|
||||
sb.Draw(tex, pos, null, c, calm ? 0 : f.Tilt, new Vector2(tex.Width / 2f, tex.Height),
|
||||
new Vector2(scale / MathF.Sqrt(stretch), scale * stretch * breathe),
|
||||
f.Mirror ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
|
||||
}
|
||||
if (calm) return;
|
||||
foreach (var p in _petals)
|
||||
{
|
||||
float a = MathF.Min(1, p.Life * 1.5f);
|
||||
float flip = MathF.Abs(MathF.Cos(p.Angle * 1.7f)); // dreht sich in der Luft
|
||||
sb.Draw(Assets.Disc, p.Pos, null, p.Color * a, p.Angle, new Vector2(64), new Vector2(p.Size / 128f, p.Size * (0.35f + 0.65f * flip) / 128f / 1.6f),
|
||||
SpriteEffects.None, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
570
Mono/Arena/DuelScene.cs
Normal file
570
Mono/Arena/DuelScene.cs
Normal file
@@ -0,0 +1,570 @@
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ein Echtzeit-Duell in der Arena: Logik aus <see cref="Duel"/>, Darstellung mit Kamera,
|
||||
/// Trefferstopp, Zeitlupe, Partikeln, Publikum und knappem HUD.
|
||||
/// </summary>
|
||||
internal sealed class DuelScene
|
||||
{
|
||||
enum Phase { 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;
|
||||
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<Floater> _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");
|
||||
}
|
||||
|
||||
// ── 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.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();
|
||||
}
|
||||
|
||||
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;
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
181
Mono/Arena/FighterView.Model.cs
Normal file
181
Mono/Arena/FighterView.Model.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using GladiatorIdle.Gfx;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace GladiatorIdle.Arena
|
||||
{
|
||||
/// 3D-Darstellung eines Kämpfers (Mixamo-Bewegungen, siehe <see cref="Model3D"/>): gibt es für das
|
||||
/// Bild ein Modell (Assets/Models/<art>.gim), sonst das Standardmodell, zeichnet die Figur in 3D
|
||||
/// statt der Sprites. Zustände der Kampflogik werden auf Clips gelegt, der Treffer fällt auf den
|
||||
/// Moment, in dem der Schwertarm am weitesten vorn ist.
|
||||
internal sealed partial class FighterView
|
||||
{
|
||||
public const string DefaultModel = "hero_murmillo_1";
|
||||
|
||||
Model3D? _model;
|
||||
BasicEffect? _mfx;
|
||||
Matrix _fit;
|
||||
string _mClip = "";
|
||||
float _mTime, _mBlend = 1;
|
||||
bool _mFree;
|
||||
|
||||
public bool Is3D => _model != null;
|
||||
|
||||
void InitModel(int color)
|
||||
{
|
||||
_model = Model3D.Load(_art);
|
||||
foreach (var alt in Fallbacks(_art)) _model ??= Model3D.Load(alt);
|
||||
_model ??= Model3D.Load(DefaultModel);
|
||||
if (_model == null || _model.Clips.Count == 0) { _model = null; return; }
|
||||
_model.AddSword();
|
||||
_model.AddShield();
|
||||
_model.SetColor(color);
|
||||
var idle = Clip3("idle");
|
||||
_model.Pose(idle, 0, true);
|
||||
_fit = _model.FitNow();
|
||||
foreach (var c in new[] { "slash", "slash2", "slash3", "attack", "attack2" }) _model.ImpactTime(Clip3(c));
|
||||
_mfx = new BasicEffect(Assets.Device) { VertexColorEnabled = true, LightingEnabled = true, PreferPerPixelLighting = true };
|
||||
// Kamera-Raum der Arena: x rechts, y nach unten, z zum Betrachter
|
||||
_mfx.AmbientLightColor = new Vector3(0.45f, 0.40f, 0.37f);
|
||||
_mfx.DirectionalLight0.Enabled = true; // warmes Licht von oben links vorn
|
||||
_mfx.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(0.45f, 0.75f, -0.5f));
|
||||
_mfx.DirectionalLight0.DiffuseColor = new Vector3(0.95f, 0.84f, 0.70f);
|
||||
_mfx.DirectionalLight0.SpecularColor = new Vector3(0.22f, 0.2f, 0.18f);
|
||||
_mfx.DirectionalLight1.Enabled = true; // kühles Gegenlicht
|
||||
_mfx.DirectionalLight1.Direction = Vector3.Normalize(new Vector3(-0.7f, 0.1f, 0.7f));
|
||||
_mfx.DirectionalLight1.DiffuseColor = new Vector3(0.22f, 0.27f, 0.36f);
|
||||
_mfx.DirectionalLight2.Enabled = false;
|
||||
_mfx.SpecularPower = 24;
|
||||
}
|
||||
|
||||
/// Figuren ohne eigenes Modell: eine ähnliche vorhandene (in eigener Teamfarbe), bis es eines gibt.
|
||||
static System.Collections.Generic.IEnumerable<string> Fallbacks(string art)
|
||||
{
|
||||
if (art.StartsWith("hero_") && art.LastIndexOf('_') is int u && u > 5) yield return art[..u] + "_1"; // Vorlage 1 der Klasse
|
||||
if (art.StartsWith("champ_")) { yield return "champ_doctore"; yield break; }
|
||||
switch (art)
|
||||
{
|
||||
case "foe_recruit": yield return "foe_slave"; break;
|
||||
case "foe_provocator" or "foe_crupellarius" or "foe_praetorian" or "foe_eques":
|
||||
yield return "foe_hoplomachus"; break;
|
||||
case "foe_dimachaerus" or "foe_essedarius" or "foe_laquearius" or "foe_sagittarius":
|
||||
yield return "foe_brawler"; break;
|
||||
}
|
||||
yield return "foe_hoplomachus";
|
||||
}
|
||||
|
||||
Model3D.Clip Clip3(string name) => _model!.Find(name) ?? _model!.Clips[0];
|
||||
|
||||
/// Clip und Zeit zum Zustand der Kampflogik.
|
||||
void UpdateModel(DuelFighter f, float dt, float realDt)
|
||||
{
|
||||
var m = _model!;
|
||||
double K(double total) => total > 0 ? Math.Clamp(f.StateTime / total, 0, 1) : 1;
|
||||
string name; float t; bool loop = false;
|
||||
var atk = Clip3(f.Heavy ? "slash2" : "slash");
|
||||
float impact = m.ImpactTime(atk), lead = MathF.Min(0.12f, impact);
|
||||
switch (f.State)
|
||||
{
|
||||
case DuelState.Windup:
|
||||
name = atk.Name; t = (float)K(f.Heavy ? Duel.HEAVY_WINDUP : f.Windup) * (impact - lead); _mFree = false; break;
|
||||
case DuelState.Strike:
|
||||
name = atk.Name; t = impact - lead + (float)K(f.StrikeTime) * lead; break;
|
||||
case DuelState.Recover:
|
||||
name = atk.Name; t = impact + (float)K(f.RecoverTime) * (atk.Length - impact) * 0.5f; _mFree = true; break;
|
||||
case DuelState.Block or DuelState.Wall:
|
||||
name = "block"; t = (float)f.StateTime * 1.5f; _mFree = false; break;
|
||||
case DuelState.Hit:
|
||||
name = "impact"; t = (float)f.StateTime * 1.4f; _mFree = true; break;
|
||||
case DuelState.Stunned:
|
||||
name = "impact2"; t = (float)f.StateTime * 0.6f; loop = true; _mFree = false; break;
|
||||
case DuelState.Dodge:
|
||||
name = "crouchblock"; t = (float)K(0.32) * Clip3("crouchblock").Length; _mFree = false; break;
|
||||
case DuelState.Down:
|
||||
name = "death"; t = (float)f.StateTime; _mFree = false; break;
|
||||
case DuelState.Victory:
|
||||
name = "victory"; t = (float)f.StateTime; _mFree = false; break;
|
||||
case DuelState.Leap:
|
||||
{
|
||||
// Sprungangriff: der Hieb des Clips fällt auf den Treffer der Kampflogik
|
||||
var leap = Clip3("attack");
|
||||
float li = m.ImpactTime(leap), st = (float)f.StateTime, hit = (float)Duel.LEAP_HIT;
|
||||
name = leap.Name;
|
||||
t = st < hit ? st / hit * li : li + (st - hit);
|
||||
_mFree = true; break;
|
||||
}
|
||||
case DuelState.Super:
|
||||
{
|
||||
// Aufladen, dann drei Hiebe; jeder Clip trifft genau zu seinem Zeitpunkt
|
||||
float st = (float)f.StateTime;
|
||||
if (st < Duel.SUPER_CHARGE) { name = "powerup"; t = st * 1.6f; _mFree = false; break; }
|
||||
string[] combo = { "slash", "slash3", "attack2" };
|
||||
int k = 0;
|
||||
while (k < combo.Length - 1 && st > Duel.SUPER_HITS[k] + 0.08) k++;
|
||||
var c = Clip3(combo[k]);
|
||||
name = c.Name;
|
||||
t = MathF.Max(0, m.ImpactTime(c) + (st - (float)Duel.SUPER_HITS[k]) * 1.2f);
|
||||
_mFree = true; break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
float vx = dt > 0 ? (X - _lastX) / dt : 0;
|
||||
bool moving = MathF.Abs(vx) > 40;
|
||||
// nach Schlag/Treffer den Clip auslaufen lassen, außer man bewegt sich
|
||||
if (_mFree && !moving && _mTime < Clip3(_mClip).Length)
|
||||
{
|
||||
name = _mClip; t = _mTime + dt * 1.4f; break;
|
||||
}
|
||||
_mFree = false;
|
||||
if (moving)
|
||||
{
|
||||
name = "walk"; loop = true;
|
||||
float dir = MathF.Sign(vx) * Facing; // rückwärts gehen: Clip rückwärts
|
||||
t = (_mClip == "walk" ? _mTime : 0) + dt * 1.25f * dir;
|
||||
}
|
||||
else { name = "idle"; loop = true; t = (_mClip == "idle" ? _mTime : 0) + dt; }
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (name != _mClip) { m.BeginBlend(); _mBlend = 0; _mClip = name; }
|
||||
_mBlend = MathF.Min(1, _mBlend + realDt / 0.12f);
|
||||
_mTime = t;
|
||||
m.Pose(Clip3(name), t, loop, _mBlend, rootY: f.State == DuelState.Leap ? 0.5f : 1);
|
||||
}
|
||||
|
||||
Matrix ModelWorld(float grow)
|
||||
{
|
||||
float s = Stage.FigH / 180f * (1 + grow);
|
||||
float yaw = Facing * MathHelper.ToRadians(72); // zum Gegner, leicht zum Betrachter gedreht
|
||||
return _fit * Matrix.CreateRotationY(yaw)
|
||||
* Matrix.CreateScale(s * (1 - _sq * 0.04f), -s * (1 + _sq * 0.06f), s) // y nach unten
|
||||
* Matrix.CreateRotationZ(_lean * Facing)
|
||||
* Matrix.CreateTranslation(X + _off * Facing * 0.35f * Stage.Scale, Stage.FloorY, 0);
|
||||
}
|
||||
|
||||
void DrawModel(GraphicsDevice gd, BasicEffect scene, Color aura, float grow)
|
||||
{
|
||||
var fx = _mfx!;
|
||||
var vp = gd.Viewport;
|
||||
fx.View = scene.View;
|
||||
fx.Projection = Matrix.CreateOrthographicOffCenter(0, vp.Width, vp.Height, 0, -100000, 100000);
|
||||
fx.World = ModelWorld(grow);
|
||||
if (aura.A > 0)
|
||||
{
|
||||
fx.LightingEnabled = false;
|
||||
fx.DiffuseColor = aura.ToVector3() * (aura.A / 255f);
|
||||
fx.EmissiveColor = Vector3.Zero;
|
||||
_model!.Draw(gd, fx, aura: true);
|
||||
fx.LightingEnabled = true;
|
||||
fx.DiffuseColor = Vector3.One;
|
||||
}
|
||||
else
|
||||
{
|
||||
fx.EmissiveColor = Color.White.ToVector3() * (_flash * 0.55f) + _tintColor.ToVector3() * (_tint * 0.5f);
|
||||
_model!.Draw(gd, fx);
|
||||
}
|
||||
gd.DepthStencilState = DepthStencilState.None;
|
||||
gd.BlendState = BlendState.AlphaBlend;
|
||||
}
|
||||
}
|
||||
}
|
||||
363
Mono/Arena/FighterView.cs
Normal file
363
Mono/Arena/FighterView.cs
Normal file
@@ -0,0 +1,363 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GladiatorIdle.Gfx;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Clip = GladiatorIdle.Gfx.ClipCache.Clip;
|
||||
|
||||
namespace GladiatorIdle.Arena
|
||||
{
|
||||
internal static class Stage
|
||||
{
|
||||
/// Größe der Kämpfer (1 = früher 560 px hoch); Abstände im Kampf: <see cref="Duel.SCALE"/>.
|
||||
public const float Scale = (float)Duel.SCALE;
|
||||
public const float FloorY = 890, FigH = 560 * Scale;
|
||||
/// Sprites: 768er-Leinwand, Füße bei y = 742, Kopf bei ~26 (716 px Figur).
|
||||
public const float Canvas = 768, Feet = 742, Body = 716;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Darstellung eines Duell-Kämpfers: Pose je Zustand (weich überblendet) auf einem Gitter,
|
||||
/// das auf der GPU verformt wird — Atmen, Ausholen (Stauchen), Schlag (Strecken, Vorstoß),
|
||||
/// Treffer (Rückstoß, Wackeln, weißer Blitz), Lehnen beim Laufen. Füße bleiben am Boden.
|
||||
/// </summary>
|
||||
internal sealed partial class FighterView
|
||||
{
|
||||
const int NX = 6, NY = 14;
|
||||
const float BLEND = 0.08f;
|
||||
|
||||
readonly string _art;
|
||||
readonly Dictionary<string, Texture2D?> _poses = new();
|
||||
readonly VertexPositionColorTexture[] _verts = new VertexPositionColorTexture[(NX + 1) * (NY + 1)];
|
||||
static readonly short[] Indices = BuildIndices();
|
||||
|
||||
Texture2D? _cur, _prev;
|
||||
string _poseKey = "";
|
||||
float _blend = 1;
|
||||
DuelState _state = (DuelState)(-1);
|
||||
double _t;
|
||||
float _phase;
|
||||
|
||||
// Federn: Strecken/Stauchen, Lehnen, Versatz entlang der Blickrichtung, Wackeln
|
||||
float _sq, _sqV, _lean, _leanV, _off, _offV, _wob;
|
||||
float _flash, _tint;
|
||||
Color _tintColor = Color.Red;
|
||||
float _lastX, _stepDust;
|
||||
|
||||
public float X { get; private set; }
|
||||
public int Facing { get; private set; } = 1;
|
||||
public Vector2 Chest => new(X + _off * Facing * Stage.Scale, Stage.FloorY - Stage.FigH * 0.58f);
|
||||
public Vector2 Front => new(X + (150 + _off) * Facing * Stage.Scale, Stage.FloorY - Stage.FigH * 0.55f);
|
||||
|
||||
readonly int _color;
|
||||
|
||||
/// <param name="color">Teamfarbe (Index in <see cref="Appearance.Colors"/>), −1 = Bild unverändert.</param>
|
||||
/// <param name="modelColor">Teamfarbe der 3D-Figur (−1: wie <paramref name="color"/>).</param>
|
||||
public FighterView(string art, float phase, int color = -1, int modelColor = -1)
|
||||
{
|
||||
_art = art;
|
||||
_phase = phase;
|
||||
_color = color;
|
||||
InitModel(modelColor >= 0 ? modelColor : color);
|
||||
}
|
||||
|
||||
Texture2D? Pose(string key)
|
||||
{
|
||||
if (!_poses.TryGetValue(key, out var t))
|
||||
{
|
||||
t = Assets.Sprite(key == "" ? _art : _art + "_" + key);
|
||||
if (t != null && _color >= 0) t = Assets.Paint(t, _color);
|
||||
_poses[key] = t;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/// Erste vorhandene Pose aus der Liste (sonst das Grundbild).
|
||||
string Pick(params string[] keys)
|
||||
{
|
||||
foreach (var k in keys) if (Pose(k) != null) return k;
|
||||
return "";
|
||||
}
|
||||
|
||||
// ── Video-Clips (Wan): Bildfolgen je Aktion, auf die Zustände der Kampflogik gelegt ──
|
||||
|
||||
Clip? _clip;
|
||||
string? _clipName, _lastClipName;
|
||||
float _clipPos;
|
||||
bool _freePlay; // Clip läuft nach Ende des Zustands weiter (Erholung nach Schlag/Treffer)
|
||||
const float FPS = 16;
|
||||
|
||||
/// Clip aus dem gemeinsamen Zwischenspeicher (null, solange er im Hintergrund lädt).
|
||||
Clip? GetClip(string action) => ClipCache.Get(_art, action, _color);
|
||||
|
||||
/// Vorab laden (Duell-Beginn), damit es mitten im Kampf nicht ruckelt.
|
||||
public void Preload()
|
||||
{
|
||||
if (_model != null) return;
|
||||
foreach (var a in new[] { "idle", "walk", "attack", "heavy", "block", "hit", "dodge", "victory", "ko" }) GetClip(a);
|
||||
}
|
||||
|
||||
/// Bild des passenden Clips zum Zustand (null = Posen verwenden).
|
||||
Texture2D? ClipFrame(DuelFighter f, float dt)
|
||||
{
|
||||
string name; float pos;
|
||||
double K(double total) => total > 0 ? Math.Clamp(f.StateTime / total, 0, 1) : 1;
|
||||
bool heavy = f.Heavy && GetClip("heavy") != null;
|
||||
Clip? atk = GetClip(heavy ? "heavy" : "attack");
|
||||
switch (f.State)
|
||||
{
|
||||
case DuelState.Windup when atk != null:
|
||||
name = heavy ? "heavy" : "attack";
|
||||
pos = (float)(K(heavy ? Duel.HEAVY_WINDUP : f.Windup) * (atk.Impact - 3));
|
||||
_freePlay = false; break;
|
||||
case DuelState.Strike when atk != null:
|
||||
name = heavy ? "heavy" : "attack";
|
||||
pos = atk.Impact - 3 + (float)K(f.StrikeTime) * 3; break;
|
||||
case DuelState.Recover when atk != null:
|
||||
name = heavy ? "heavy" : "attack";
|
||||
pos = atk.Impact + (float)K(f.RecoverTime) * (atk.Last - atk.Impact) * 0.55f;
|
||||
_freePlay = true; break;
|
||||
case DuelState.Block or DuelState.Wall when GetClip("block") is Clip b:
|
||||
name = "block"; pos = MathF.Min(b.Last, (float)f.StateTime * FPS * 3); _freePlay = false; break;
|
||||
case DuelState.Hit when GetClip("hit") is Clip h:
|
||||
name = "hit"; pos = (float)K(0.25) * h.Impact; _freePlay = true; break;
|
||||
case DuelState.Dodge when GetClip("dodge") is Clip d:
|
||||
name = "dodge"; pos = (float)K(0.32) * d.Last; _freePlay = false; break;
|
||||
case DuelState.Down when GetClip("ko") is Clip ko:
|
||||
name = "ko"; pos = MathF.Min(ko.Last, (float)f.StateTime * FPS); break;
|
||||
case DuelState.Victory when GetClip("victory") is Clip v:
|
||||
name = "victory"; pos = MathF.Min(v.Last, (float)f.StateTime * FPS); break;
|
||||
case DuelState.Ready:
|
||||
{
|
||||
float vx = dt > 0 ? (X - _lastX) / dt : 0;
|
||||
bool moving = MathF.Abs(vx) > 40;
|
||||
// nach Schlag/Treffer: Clip zu Ende spielen, außer man bewegt sich
|
||||
if (_freePlay && _clip != null && !moving && _clipPos < _clip.Last)
|
||||
{
|
||||
_clipPos += dt * FPS * 1.6f;
|
||||
return _clip.Frames[(int)MathF.Min(_clip.Last, _clipPos)];
|
||||
}
|
||||
_freePlay = false;
|
||||
if (moving && GetClip("walk") is Clip w)
|
||||
{
|
||||
name = "walk";
|
||||
float dir = MathF.Sign(vx) * Facing; // rückwärts gehen: Clip rückwärts
|
||||
pos = _clipName == "walk" ? _clipPos + dt * FPS * 1.3f * dir : 0;
|
||||
pos = ((pos % w.Last) + w.Last) % w.Last;
|
||||
break;
|
||||
}
|
||||
if (GetClip("idle") is Clip idle)
|
||||
{
|
||||
name = "idle";
|
||||
pos = _clipName == "idle" ? (_clipPos + dt * FPS) % idle.Last : 0;
|
||||
break;
|
||||
}
|
||||
_clip = null; _clipName = null; return null;
|
||||
}
|
||||
default:
|
||||
_clip = null; _clipName = null; _freePlay = false; return null;
|
||||
}
|
||||
_clip = GetClip(name); _clipName = name; _clipPos = pos;
|
||||
return _clip!.Frames[Math.Clamp((int)pos, 0, _clip.Last)];
|
||||
}
|
||||
|
||||
static short[] BuildIndices()
|
||||
{
|
||||
var idx = new List<short>();
|
||||
for (int j = 0; j < NY; j++)
|
||||
for (int i = 0; i < NX; i++)
|
||||
{
|
||||
short a = (short)(j * (NX + 1) + i), b = (short)(a + 1), c = (short)(a + NX + 1), d = (short)(c + 1);
|
||||
idx.AddRange(new[] { a, b, c, b, d, c });
|
||||
}
|
||||
return idx.ToArray();
|
||||
}
|
||||
|
||||
// ── Anstöße von außen (Ereignisse) ──────────────────────────
|
||||
|
||||
public void Hurt(bool crit)
|
||||
{
|
||||
_flash = crit ? 1f : 0.85f;
|
||||
_tint = 0.55f; _tintColor = new Color(255, 80, 60);
|
||||
_offV -= crit ? 900 : 600;
|
||||
_sqV -= crit ? 2.6f : 1.8f;
|
||||
_wob = crit ? 1f : 0.7f;
|
||||
}
|
||||
|
||||
public void Blocked() { _offV -= 320; _sqV -= 1.0f; _flash = 0.35f; }
|
||||
|
||||
public void Parried() { _flash = 1f; _tint = 0.5f; _tintColor = new Color(160, 210, 255); _sqV += 1.5f; }
|
||||
|
||||
public void Heal() { _tint = 0.7f; _tintColor = new Color(120, 255, 140); _sqV += 1.2f; }
|
||||
|
||||
// ── Takt ────────────────────────────────────────────────────
|
||||
|
||||
/// Zustand übernehmen; liefert true bei einem Fußtritt (Staub).
|
||||
public bool Update(float dt, float realDt, DuelFighter f, float displayX, bool calm)
|
||||
{
|
||||
_t += dt;
|
||||
X = displayX;
|
||||
Facing = f.Facing;
|
||||
if (f.State != _state) Enter(f);
|
||||
_state = f.State;
|
||||
|
||||
string key = f.State switch
|
||||
{
|
||||
DuelState.Windup => Pick("windup"),
|
||||
DuelState.Strike => Pick("attack"),
|
||||
DuelState.Recover => f.StateTime < f.RecoverTime * 0.35 ? Pick("attack") : Pick("recover", ""),
|
||||
DuelState.Block or DuelState.Wall => Pick("block"),
|
||||
DuelState.Dodge => Pick("dodge", ""),
|
||||
DuelState.Hit => Pick("hit"),
|
||||
DuelState.Stunned => Pick("stagger", "hit"),
|
||||
DuelState.Down => Pick("ko", "hit"),
|
||||
DuelState.Victory => Pick("victory"),
|
||||
DuelState.Leap => Pick("attack"),
|
||||
DuelState.Super => f.StateTime < Duel.SUPER_CHARGE ? Pick("windup") : Pick("attack"),
|
||||
_ => Math.Sin(_t * 0.9 + _phase) > 0.55 ? Pick("idle2", "") : ""
|
||||
};
|
||||
var clipFrame = _model != null ? null : ClipFrame(f, dt);
|
||||
if (_model != null) UpdateModel(f, dt, realDt);
|
||||
else if (clipFrame != null)
|
||||
{
|
||||
// Video-Clip: neues Bild ohne Überblendung, nur beim Wechsel des Clips weich
|
||||
if (_clipName != _lastClipName) { _prev = _cur; _blend = _prev == null ? 1 : 0; _lastClipName = _clipName; }
|
||||
_cur = clipFrame; _poseKey = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_lastClipName != null) { _prev = _cur; _blend = 0; _lastClipName = null; _poseKey = "-"; }
|
||||
if (key != _poseKey) { _prev = _cur; _cur = Pose(key); _poseKey = key; _blend = _prev == null ? 1 : 0; }
|
||||
}
|
||||
_cur ??= Pose("");
|
||||
_blend = MathF.Min(1, _blend + realDt / BLEND); // in Echtzeit, auch im Trefferstopp
|
||||
|
||||
// Federn
|
||||
Spring(ref _sq, ref _sqV, 0, 260, 14, dt);
|
||||
Spring(ref _off, ref _offV, 0, 140, 16, dt);
|
||||
float vx = dt > 0 ? (X - _lastX) / dt : 0;
|
||||
float leanTarget = f.State == DuelState.Ready ? MathHelper.Clamp(vx * Facing / 440f, -1, 1) * 0.07f : 0;
|
||||
if (f.State == DuelState.Windup) leanTarget = -0.06f;
|
||||
if (f.State == DuelState.Strike) leanTarget = 0.09f;
|
||||
if (f.State == DuelState.Stunned) leanTarget = 0.05f * MathF.Sin((float)_t * 6);
|
||||
Spring(ref _lean, ref _leanV, leanTarget, 180, 18, dt);
|
||||
// Blitz und Färbung in Echtzeit (auch während Trefferstopp und Zeitlupe)
|
||||
_wob = MathF.Max(0, _wob - dt * 3.5f);
|
||||
_flash = MathF.Max(0, _flash - realDt * 7);
|
||||
_tint = MathF.Max(0, _tint - realDt * 2.5f);
|
||||
if (calm) { _sq *= 0.3f; _wob = 0; }
|
||||
|
||||
bool step = false;
|
||||
if (MathF.Abs(vx) > 60 && f.State == DuelState.Ready)
|
||||
{
|
||||
_stepDust -= dt;
|
||||
if (_stepDust <= 0) { _stepDust = 0.22f; step = true; }
|
||||
}
|
||||
_lastX = X;
|
||||
return step;
|
||||
}
|
||||
|
||||
void Enter(DuelFighter f)
|
||||
{
|
||||
switch (f.State)
|
||||
{
|
||||
case DuelState.Windup: _sqV -= f.Heavy ? 2.2f : 1.2f; _offV -= 200; break; // Ausholen: zusammenziehen
|
||||
case DuelState.Strike: _sqV += f.Heavy ? 3.5f : 2.4f; _offV += f.Heavy ? 1300 : 900; break; // Vorstoß
|
||||
case DuelState.Leap: _sqV -= 1.8f; break;
|
||||
case DuelState.Super: _sqV -= 2.0f; break;
|
||||
case DuelState.Dodge: _sqV -= 1.5f; break;
|
||||
case DuelState.Victory: _sqV += 2f; break;
|
||||
case DuelState.Down: _sqV -= 2.5f; break;
|
||||
}
|
||||
}
|
||||
|
||||
static void Spring(ref float x, ref float v, float target, float k, float c, float dt)
|
||||
{
|
||||
v += (-(x - target) * k - v * c) * dt;
|
||||
x += v * dt;
|
||||
}
|
||||
|
||||
// ── Zeichnen ────────────────────────────────────────────────
|
||||
|
||||
/// Bodenschatten (SpriteBatch, Kamera-Matrix).
|
||||
public void DrawShadow(SpriteBatch sb)
|
||||
{
|
||||
float w = 270 * Stage.Scale * (1 + _sq * 0.4f);
|
||||
Draw.Glow(sb, new Vector2(X + _off * Facing * 0.5f * Stage.Scale, Stage.FloorY + 4), new Vector2(w, 58 * Stage.Scale), Color.Black * 0.55f);
|
||||
}
|
||||
|
||||
/// Leuchten hinter der Figur (Silhouette, leicht vergrößert): angekündigter Schlag, Schildwall.
|
||||
public void DrawAura(GraphicsDevice gd, BasicEffect fx, Color c, float grow)
|
||||
{
|
||||
if (_model != null) { if (c.A > 0) DrawModel(gd, fx, c, grow); return; }
|
||||
if (_cur == null || c.A == 0) return;
|
||||
Quad(gd, fx, Assets.White(_cur), 1 + grow, c, 0);
|
||||
}
|
||||
|
||||
public void DrawBody(GraphicsDevice gd, BasicEffect fx, DuelFighter f, bool calm)
|
||||
{
|
||||
if (_model != null) { DrawModel(gd, fx, Color.Transparent, 0); return; }
|
||||
if (_cur == null) return;
|
||||
float alpha = f.State == DuelState.Down ? MathF.Max(0.55f, 1 - (float)f.StateTime * 0.3f) : 1f;
|
||||
// Ausweichen: Nachbilder
|
||||
if (f.State == DuelState.Dodge && !calm)
|
||||
for (int k = 1; k <= 2; k++)
|
||||
{
|
||||
Quad(gd, fx, _cur, 1, Color.White * (0.22f / k), -Facing * 70 * k);
|
||||
}
|
||||
if (_prev != null && _blend < 1)
|
||||
{
|
||||
Quad(gd, fx, _prev, 1, Color.White * (alpha * (1 - _blend)), 0);
|
||||
}
|
||||
// neue Pose sofort voll deckend; nur die alte blendet darunter aus (sonst scheint
|
||||
// die Figur beim Wechsel durch)
|
||||
Quad(gd, fx, _cur, 1, Color.White * alpha, 0);
|
||||
if (_tint > 0) { Quad(gd, fx, Assets.White(_cur), 1, _tintColor * (_tint * 0.5f), 0); }
|
||||
if (_flash > 0) { Quad(gd, fx, Assets.White(_cur), 1, Color.White * (_flash * 0.55f), 0); }
|
||||
}
|
||||
|
||||
/// Gitter aufbauen: Füße fest am Boden, Verformung wächst mit der Höhe.
|
||||
void Quad(GraphicsDevice gd, BasicEffect fx, Texture2D tex, float scale, Color color, float shiftX)
|
||||
{
|
||||
// Clip-Bilder sind auf den Bewegungsbereich zugeschnitten: Lage in der vollen Leinwand
|
||||
if (ClipCache.CropOf(tex) is (Vector4 crop, float aspect))
|
||||
Build(scale, color, shiftX, Stage.Canvas * aspect, crop);
|
||||
else
|
||||
Build(scale, color, shiftX, Stage.Canvas * tex.Width / tex.Height, new Vector4(0, 0, 1, 1));
|
||||
Mesh(gd, fx, tex);
|
||||
}
|
||||
|
||||
void Build(float scale, Color color, float shiftX, float canvasW, Vector4 crop)
|
||||
{
|
||||
float s = Stage.FigH / Stage.Body * scale;
|
||||
float breathe = _clip != null ? 0 : 0.012f * MathF.Sin((float)_t * 2.3f + _phase);
|
||||
float sy = 1 + _sq * 0.10f + breathe, sx = 1 - _sq * 0.06f - breathe * 0.5f;
|
||||
float baseX = X + (_off * Facing * Stage.Scale) * (_clip != null ? 0.35f : 1) + shiftX * Stage.Scale;
|
||||
for (int j = 0; j <= NY; j++)
|
||||
{
|
||||
float v = (float)j / NY, cv = crop.Y + v * crop.W;
|
||||
float py = (cv * Stage.Canvas - Stage.Feet) * s; // < 0 über den Füßen
|
||||
float h = MathHelper.Clamp(-py / (Stage.Body * s), 0, 1.1f); // 0 Füße … 1 Kopf
|
||||
float lean = _lean * h * Stage.FigH * Facing;
|
||||
float wob = _wob * 22 * MathF.Sin(h * 5.5f - (float)_t * 38) * h;
|
||||
for (int i = 0; i <= NX; i++)
|
||||
{
|
||||
float u = (float)i / NX, cu = crop.X + u * crop.Z;
|
||||
float px = (cu - 0.5f) * canvasW * s * sx * Facing;
|
||||
var pos = new Vector3(baseX + px + lean + wob, Stage.FloorY + py * sy, 0);
|
||||
_verts[j * (NX + 1) + i] = new VertexPositionColorTexture(pos, color, new Vector2(u, v));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Mesh(GraphicsDevice gd, BasicEffect fx, Texture2D tex)
|
||||
{
|
||||
fx.Texture = tex;
|
||||
foreach (var pass in fx.CurrentTechnique.Passes)
|
||||
{
|
||||
pass.Apply();
|
||||
gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, _verts, 0, _verts.Length, Indices, 0, Indices.Length / 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
169
Mono/Arena/HubScene.Gear.cs
Normal file
169
Mono/Arena/HubScene.Gear.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GladiatorIdle.Gfx;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using D = GladiatorIdle.Gfx.Draw;
|
||||
|
||||
namespace GladiatorIdle.Arena
|
||||
{
|
||||
/// Ausrüstung: Inventar mit Detailkarte (anlegen, verkaufen), Händler und Schmied.
|
||||
internal sealed partial class HubScene
|
||||
{
|
||||
long? _sel; // gewähltes Stück (Inventar oder angelegt)
|
||||
double _sellAllArmed; // "Alle verkaufen": zweiter Klick innerhalb von 4 s
|
||||
|
||||
Item? Selected => _sel is long id ? _game.Inventory.FirstOrDefault(i => i.Id == id) ?? _game.Equipped.FirstOrDefault(i => i?.Id == id) : null;
|
||||
bool SelectedEquipped => _sel is long id && _game.Equipped.Any(i => i?.Id == id);
|
||||
|
||||
// ── Kachel und Texte ────────────────────────────────────────
|
||||
|
||||
void ItemTile(SpriteBatch sb, RectangleF r, Item? it, bool selected)
|
||||
{
|
||||
D.Rect(sb, r, new Color(24, 18, 12) * (it == null ? 0.6f : 0.95f));
|
||||
var col = it == null ? D.Border : RarityColor(it.Rarity);
|
||||
if (it != null && Assets.Sprite(it.Def.Icon) is Texture2D icon)
|
||||
sb.Draw(icon, r.Center, null, Color.White, 0, new Vector2(icon.Width / 2f, icon.Height / 2f), r.Width * 0.82f / icon.Width, SpriteEffects.None, 0);
|
||||
if (it != null && it.Level > 0)
|
||||
D.Text(sb, Assets.SansBold, 14, it.Level.ToString(NumberFormat.Culture), new Vector2(r.Right - 6, r.Bottom - 12), Color.White, Align.Right);
|
||||
D.Frame(sb, r, selected ? Color.White : col, selected ? 3 : 2);
|
||||
}
|
||||
|
||||
/// Hauptwirkung in einer Zeile (Schaden ×…, Leben ×…, Block …), so wie im Slot.
|
||||
string ItemMain(Item it)
|
||||
{
|
||||
var d = it.Def;
|
||||
double lv = it.EffLevel(_game.SlotLevels[(int)it.Slot]);
|
||||
var parts = new List<string>();
|
||||
if (d.Slot == ItemSlot.Shield) parts.Add(string.Format(L.t("item.stat.block"), NumberFormat.Percent(0.5 * lv / (lv + 8))));
|
||||
if (d.DmgK > 0) parts.Add(string.Format(L.t("item.stat.damage"), NumberFormat.Mult(Math.Pow(Items.LEVEL_GROWTH, lv * d.DmgK))));
|
||||
if (d.HpK > 0) parts.Add(string.Format(L.t("item.stat.health"), NumberFormat.Mult(Math.Pow(Items.LEVEL_GROWTH, lv * d.HpK))));
|
||||
return string.Join(" · ", parts); // i18n-ok
|
||||
}
|
||||
|
||||
static IEnumerable<string> ItemAffixes(Item it) => it.Affixes.Select(a => a.Kind == Affix.Agility
|
||||
? string.Format(L.t("affix.agility"), a.Value.ToString("0.#", NumberFormat.Culture))
|
||||
: string.Format(L.t("affix." + a.Kind.ToString().ToLowerInvariant()), NumberFormat.Percent(a.Value)));
|
||||
|
||||
/// Unterschied in der Kampfkraft, wenn das Stück angelegt würde.
|
||||
(string, Color) PowerDelta(Item it)
|
||||
{
|
||||
double now = _game.Power(), with = _game.PowerWith(it), d = with / now - 1;
|
||||
if (Math.Abs(d) < 0.005) return (L.t("item.same"), D.Dim);
|
||||
string pct = (d > 0 ? "+" : "−") + NumberFormat.Percent(Math.Abs(d)); // i18n-ok
|
||||
return (string.Format(L.t("item.power"), pct), d > 0 ? D.Green : D.Red);
|
||||
}
|
||||
|
||||
// ── Inventar und Detailkarte (Gladiator-Schublade, rechts) ──
|
||||
|
||||
void DrawInventory(SpriteBatch sb, RectangleF area)
|
||||
{
|
||||
const int COLS = 5;
|
||||
const float CELL = 76, GAP = 8;
|
||||
D.Text(sb, Assets.SansBold, 20, string.Format(L.t("char.inventory"), _game.Inventory.Count, Items.INVENTORY),
|
||||
new Vector2(area.X, area.Y), D.Sand);
|
||||
// Alle verkaufen (mit Sicherheits-Klick)
|
||||
_sellAllArmed = Math.Max(0, _sellAllArmed - 1 / 60.0);
|
||||
bool armed = _sellAllArmed > 0;
|
||||
string sellText = armed ? string.Format(L.t("char.sellall.confirm"), _game.Inventory.Count)
|
||||
: string.Format(L.t("char.sellall"), NumberFormat.Format(_game.InventoryValue));
|
||||
if (_ui.Button(sb, new RectangleF(area.X + 170, area.Y - 18, 250, 36), sellText, _game.Inventory.Count > 0,
|
||||
selected: armed, size: armed ? 13 : 15, accent: armed ? D.Red : null))
|
||||
{
|
||||
if (!armed) _sellAllArmed = 4;
|
||||
else
|
||||
{
|
||||
double got = _game.SellAll();
|
||||
_sellAllArmed = 0;
|
||||
if (_sel is long id && !_game.Equipped.Any(i => i?.Id == id)) _sel = null;
|
||||
if (got > 0) SoundManager.PlayCoins();
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < Items.INVENTORY; i++)
|
||||
{
|
||||
var r = new RectangleF(area.X + i % COLS * (CELL + GAP), area.Y + 26 + i / COLS * (CELL + GAP), CELL, CELL);
|
||||
var it = i < _game.Inventory.Count ? _game.Inventory[i] : null;
|
||||
ItemTile(sb, r, it, it != null && _sel == it.Id);
|
||||
if (it != null && (_ui.Hover(r) || false) && _ui.Hit(r)) _sel = it.Id;
|
||||
}
|
||||
|
||||
// Detailkarte
|
||||
var card = new RectangleF(area.X, area.Y + 26 + 6 * (CELL + GAP) + 10, COLS * (CELL + GAP) - GAP, area.Bottom - (area.Y + 26 + 6 * (CELL + GAP) + 10));
|
||||
Ui.Panel(sb, card, D.Border, 0.9f);
|
||||
var sel = Selected;
|
||||
if (sel == null)
|
||||
{
|
||||
D.Text(sb, Assets.Sans, 18, L.t("char.pick"), card.Center, D.Dim, Align.Center);
|
||||
return;
|
||||
}
|
||||
float x = card.X + 16, y = card.Y + 22;
|
||||
D.Text(sb, Assets.SansBold, 22, ItemName(sel), new Vector2(x, y), RarityColor(sel.Rarity));
|
||||
D.Text(sb, Assets.Sans, 16, L.t("rarity." + sel.Rarity.ToString().ToLowerInvariant()) + " · " + L.t("slot." + sel.Slot.ToString().ToLowerInvariant()),
|
||||
new Vector2(x, y + 26), D.Dim); // i18n-ok
|
||||
D.Text(sb, Assets.Sans, 17, ItemMain(sel), new Vector2(x, y + 54), D.Sand);
|
||||
float ay = y + 80;
|
||||
foreach (var a in ItemAffixes(sel)) { D.Text(sb, Assets.Sans, 16, a, new Vector2(x, ay), D.Blue); ay += 22; }
|
||||
if (SelectedEquipped)
|
||||
{
|
||||
D.Text(sb, Assets.SansBold, 17, L.t("char.equipped"), new Vector2(card.Right - 16, y), D.Green, Align.Right);
|
||||
return;
|
||||
}
|
||||
var (delta, dc) = PowerDelta(sel);
|
||||
D.Text(sb, Assets.SansBold, 17, delta, new Vector2(card.Right - 16, y), dc, Align.Right);
|
||||
float by = card.Bottom - 54, bw = (card.Width - 44) / 2;
|
||||
if (_ui.Button(sb, new RectangleF(card.X + 16, by, bw, 42), L.t("char.equip"), size: 18, accent: D.Green))
|
||||
if (_game.Equip(sel.Id)) SoundManager.PlayBlock();
|
||||
if (_ui.Button(sb, new RectangleF(card.X + 28 + bw, by, bw, 42), string.Format(L.t("char.sell"), NumberFormat.Format(Items.SellValue(sel))), size: 16))
|
||||
if (_game.Sell(sel.Id)) { SoundManager.PlayCoins(); _sel = null; }
|
||||
}
|
||||
|
||||
// ── Forum: Händler (links) und Schmied (rechts) ─────────────
|
||||
|
||||
void DrawForum(SpriteBatch sb, RectangleF r)
|
||||
{
|
||||
float x = r.X + 30, y = r.Y + 40, w = 700;
|
||||
D.Text(sb, Assets.Serif, 30, L.t("forum.tab.merchant"), new Vector2(x, y), D.Gold);
|
||||
D.Text(sb, Assets.Sans, 16, string.Format(L.t("merchant.refresh"), NumberFormat.Duration(_game.MerchantRefreshIn)),
|
||||
new Vector2(x + w, y), D.Dim, Align.Right);
|
||||
D.Text(sb, Assets.Sans, 16, string.Format(L.t("merchant.bag"), _game.Inventory.Count, Items.INVENTORY), new Vector2(x + w, y + 24), D.Dim, Align.Right);
|
||||
float ry = y + 50;
|
||||
foreach (var it in _game.Merchant.ToList())
|
||||
{
|
||||
var row = new RectangleF(x, ry, w, 96);
|
||||
D.Rect(sb, row, new Color(30, 22, 15) * 0.9f);
|
||||
D.Frame(sb, row, RarityColor(it.Rarity), 2);
|
||||
ItemTile(sb, new RectangleF(row.X + 10, row.Y + 10, 76, 76), it, false);
|
||||
D.Text(sb, Assets.SansBold, 20, ItemName(it), new Vector2(row.X + 100, row.Y + 22), RarityColor(it.Rarity));
|
||||
D.Text(sb, Assets.Sans, 15, ItemMain(it), new Vector2(row.X + 100, row.Y + 48), D.Sand);
|
||||
string aff = string.Join(" · ", ItemAffixes(it)); // i18n-ok
|
||||
if (aff.Length > 0) D.Text(sb, Assets.Sans, 14, aff, new Vector2(row.X + 100, row.Y + 72), D.Blue);
|
||||
var (delta, dc) = PowerDelta(it);
|
||||
D.Text(sb, Assets.SansBold, 15, delta, new Vector2(row.Right - 200, row.Y + 22), dc, Align.Right);
|
||||
double price = Items.Value(it);
|
||||
long id = it.Id;
|
||||
if (_ui.Button(sb, new RectangleF(row.Right - 180, row.Y + 24, 166, 48), NumberFormat.Format(price),
|
||||
_game.Gold >= price && _game.Inventory.Count < Items.INVENTORY, size: 19))
|
||||
if (_game.BuyFromMerchant(id)) { SoundManager.PlayPurchase(); _sel = id; }
|
||||
ry += 104;
|
||||
}
|
||||
|
||||
// Schmied: Ausrüstungsplätze verstärken (wirkt auf jedes Stück im Platz)
|
||||
float fx = x + w + 50, fw = r.Right - 30 - fx;
|
||||
D.Text(sb, Assets.Serif, 30, L.t("forum.tab.forge"), new Vector2(fx, y), D.Gold);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var slot = (ItemSlot)i;
|
||||
var row = new RectangleF(fx, y + 50 + i * 104, fw, 96);
|
||||
D.Rect(sb, row, new Color(30, 22, 15) * 0.9f);
|
||||
D.Frame(sb, row, D.Border, 2);
|
||||
ItemTile(sb, new RectangleF(row.X + 10, row.Y + 10, 76, 76), _game.Equipped[i], false);
|
||||
D.Text(sb, Assets.SansBold, 20, L.t("slot." + slot.ToString().ToLowerInvariant()), new Vector2(row.X + 100, row.Y + 30), Color.White);
|
||||
D.Text(sb, Assets.Sans, 16, string.Format(L.t("forge.level"), _game.SlotLevels[i]), new Vector2(row.X + 100, row.Y + 60), D.Sand);
|
||||
double cost = _game.UpgradeSlotCost(slot);
|
||||
if (_ui.Button(sb, new RectangleF(row.Right - 180, row.Y + 24, 166, 48), NumberFormat.Format(cost), _game.Gold >= cost, size: 19))
|
||||
if (_game.UpgradeSlot(slot)) SoundManager.PlayLevelUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
97
Mono/Arena/HubScene.Skills.cs
Normal file
97
Mono/Arena/HubScene.Skills.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
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
|
||||
{
|
||||
/// Fähigkeitenbaum: drei Zweige (Angriff, Verteidigung, Kampfstil der Klasse), je vier Stufen.
|
||||
/// Eine Stufe braucht 2 × Stufe Punkte im Zweig. Zeigen = Beschreibung, Klick = lernen.
|
||||
internal sealed partial class HubScene
|
||||
{
|
||||
string? _skillHover;
|
||||
float _learnFlash;
|
||||
string? _learnedId;
|
||||
|
||||
void DrawSkills(SpriteBatch sb, RectangleF r)
|
||||
{
|
||||
float x = r.X + 30, y = r.Y + 40;
|
||||
D.Text(sb, Assets.Serif, 30, L.t("char.skills"), new Vector2(x, y), D.Gold);
|
||||
D.Text(sb, Assets.SansBold, 22, string.Format(L.t("char.skillpoints"), _game.SkillPoints),
|
||||
new Vector2(x + 300, y + 2), _game.SkillPoints > 0 ? D.Gold : D.Dim);
|
||||
if (_ui.Button(sb, new RectangleF(r.Right - 330, y - 22, 300, 44),
|
||||
string.Format(L.t("char.skillreset"), NumberFormat.Format(_game.SkillResetCost)),
|
||||
_game.SkillRanks.Count > 0 && _game.Gold >= _game.SkillResetCost, size: 16))
|
||||
if (_game.ResetSkills()) SoundManager.PlayCoins();
|
||||
|
||||
_skillHover = null;
|
||||
_learnFlash = MathF.Max(0, _learnFlash - 1 / 60f * 2.5f);
|
||||
var branches = new[] { SkillBranch.Offense, SkillBranch.Defense, SkillBranch.Class };
|
||||
float colW = (r.Width - 60) / 3, top = y + 60, rowH = 142;
|
||||
for (int b = 0; b < 3; b++)
|
||||
{
|
||||
var branch = branches[b];
|
||||
float cx = r.X + 30 + colW * b + colW / 2;
|
||||
int pts = _game.BranchPoints(branch);
|
||||
D.Text(sb, Assets.Serif, 24, $"{L.t("branch." + branch.ToString().ToLowerInvariant()).ToUpperInvariant()} · {pts}", // i18n-ok
|
||||
new Vector2(cx, top), D.Gold, Align.Center);
|
||||
var skills = SkillDef.For(_game.Class).Where(s => s.Branch == branch).OrderBy(s => s.Tier).ToList();
|
||||
// Verbindungslinien zwischen den Stufen
|
||||
for (int i = 0; i + 1 < skills.Count; i++)
|
||||
{
|
||||
float y0 = top + 82 + i * rowH, y1 = y0 + rowH;
|
||||
bool open = pts >= skills[i + 1].Requires;
|
||||
D.Rect(sb, new RectangleF(cx - 2, y0 + 80, 4, y1 - y0 - 124), open ? D.Gold * 0.7f : D.Border * 0.6f);
|
||||
}
|
||||
foreach (var s in skills) DrawSkillNode(sb, s, new Vector2(cx, top + 82 + s.Tier * rowH), pts);
|
||||
}
|
||||
|
||||
// Beschreibung (Zeigen) oder Hinweis
|
||||
var info = new RectangleF(r.X + 30, r.Bottom - 96, r.Width - 60, 76);
|
||||
Ui.Panel(sb, info, D.Border, 0.9f);
|
||||
if (_skillHover is string id)
|
||||
{
|
||||
var s = SkillDef.Get(id);
|
||||
string head = L.t(s.Key) + (s.Active ? " · " + L.t("char.skill.active") : ""); // i18n-ok
|
||||
D.Text(sb, Assets.SansBold, 21, head, new Vector2(info.X + 20, info.Y + 22), s.Active ? new Color(255, 170, 70) : D.Gold);
|
||||
D.Text(sb, Assets.Sans, 18, L.t(s.Desc), new Vector2(info.X + 20, info.Y + 52), D.Sand);
|
||||
}
|
||||
else D.Text(sb, Assets.Sans, 18, L.t("char.skill.hint"), info.Center, D.Dim, Align.Center);
|
||||
}
|
||||
|
||||
void DrawSkillNode(SpriteBatch sb, SkillDef s, Vector2 c, int branchPts)
|
||||
{
|
||||
int rank = _game.SkillRank(s.Id);
|
||||
bool unlocked = branchPts >= s.Requires, can = _game.CanLearn(s), max = rank >= s.MaxRank;
|
||||
var r = new RectangleF(c.X - 44, c.Y - 44, 88, 88);
|
||||
bool hover = _ui.Hover(r);
|
||||
if (hover) _skillHover = s.Id;
|
||||
|
||||
if (can) D.Glow(sb, c, new Vector2(150 + 12 * MathF.Sin((float)_t * 4)), D.Gold * 0.45f);
|
||||
if (_learnedId == s.Id && _learnFlash > 0) D.Glow(sb, c, new Vector2(200 + 120 * (1 - _learnFlash)), Color.White * _learnFlash);
|
||||
if (Assets.Sprite(s.Icon) is Texture2D icon)
|
||||
{
|
||||
var tint = !unlocked ? new Color(55, 48, 40) : rank == 0 ? new Color(150, 140, 125) : Color.White;
|
||||
sb.Draw(icon, c, null, tint, 0, new Vector2(icon.Width / 2f, icon.Height / 2f), (hover ? 88f : 80f) / icon.Width, SpriteEffects.None, 0);
|
||||
}
|
||||
if (s.Active) D.Text(sb, Assets.SansBold, 14, L.t("char.skill.active").ToUpperInvariant(), c + new Vector2(56, 0), new Color(255, 170, 70));
|
||||
|
||||
// Rang als Punkte unter dem Medaillon
|
||||
for (int i = 0; i < s.MaxRank; i++)
|
||||
{
|
||||
var p = c + new Vector2((i - (s.MaxRank - 1) / 2f) * 18, 50);
|
||||
sb.Draw(Assets.Disc, p, null, i < rank ? D.Gold : new Color(40, 32, 24), 0, new Vector2(64), 14f / 128, SpriteEffects.None, 0);
|
||||
}
|
||||
string label = unlocked ? L.t(s.Key) : string.Format(L.t("char.skill.requires"), s.Requires);
|
||||
D.Text(sb, Assets.SansBold, 16, label, c + new Vector2(0, 70), !unlocked ? D.Dim : max ? D.Gold : Color.White, Align.Center);
|
||||
|
||||
if (can && _ui.Hit(r) && _game.Learn(s.Id))
|
||||
{
|
||||
SoundManager.PlayLevelUp();
|
||||
_learnedId = s.Id; _learnFlash = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
401
Mono/Arena/HubScene.cs
Normal file
401
Mono/Arena/HubScene.cs
Normal file
@@ -0,0 +1,401 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GladiatorIdle.Gfx;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using D = GladiatorIdle.Gfx.Draw;
|
||||
|
||||
namespace GladiatorIdle.Arena
|
||||
{
|
||||
/// <summary>
|
||||
/// Arena zwischen den Kämpfen: der eigene Gladiator in der Arena, oben Stufe, Denare und Ruhm,
|
||||
/// rechts die Gegner zur Wahl (leichter / ebenbürtig / stärker / Champion), unten Schubladen
|
||||
/// für Gladiator und Ludus. Training und Einnahmen laufen weiter.
|
||||
/// </summary>
|
||||
internal sealed partial class HubScene
|
||||
{
|
||||
enum Drawer { None, Gladiator, Ludus, Forum, Skills }
|
||||
|
||||
readonly GameState _game;
|
||||
readonly Ui _ui = new();
|
||||
readonly Particles _fx = new();
|
||||
readonly Crowd _crowd = new(11);
|
||||
readonly FighterView _hero;
|
||||
readonly DuelFighter _dummy = new() { IsPlayer = true, X = 0, Facing = 1, MaxHp = 1, Hp = 1 };
|
||||
Texture2D? _backdrop;
|
||||
string? _loopName;
|
||||
int _arenaShown = -1;
|
||||
double _t;
|
||||
Drawer _drawer;
|
||||
float _drawerK; // 0 zu, 1 offen (gleitet)
|
||||
|
||||
// Meldung nach dem Kampf
|
||||
string[] _toast = Array.Empty<string>();
|
||||
Color _toastColor;
|
||||
double _toastAge = 99;
|
||||
|
||||
/// Gewählter Gegner (Kampf beginnt) — von außen abgeholt.
|
||||
public Offer? Chosen { get; set; }
|
||||
|
||||
public HubScene(GameState game)
|
||||
{
|
||||
_game = game;
|
||||
string hero = Art.Hero(game.Class, game.Look.Preset);
|
||||
_hero = Assets.Has(hero) ? new FighterView(hero, 0.5f, game.Look.Color) : new FighterView(Art.Fighter(game.Class), 0.5f);
|
||||
_hero.Preload();
|
||||
_fx.Calm = AppSettings.ReduceMotion;
|
||||
SoundManager.StartAmbient("music_ludus");
|
||||
}
|
||||
|
||||
public void ShowResult(string[] lines, Color color)
|
||||
{
|
||||
_toast = lines; _toastColor = color; _toastAge = 0;
|
||||
_crowd.Excite(color == D.Gold ? 0.8f : 0.1f);
|
||||
}
|
||||
|
||||
void EnsureArena()
|
||||
{
|
||||
if (_arenaShown == _game.Arena) return;
|
||||
_arenaShown = _game.Arena;
|
||||
string art = Art.Arena(ArenaDef.All[_game.Arena]);
|
||||
_backdrop = Assets.Sprite(art, "jpg");
|
||||
_loopName = AppSettings.ReduceMotion ? null : art;
|
||||
}
|
||||
|
||||
// ── Takt ────────────────────────────────────────────────────
|
||||
|
||||
public void Update(float dt, Input input, Matrix ui)
|
||||
{
|
||||
_t += dt;
|
||||
_toastAge += dt;
|
||||
_ui.Begin(input, ui);
|
||||
_game.Tick(dt); // Training, Einnahmen, Erholung
|
||||
_hero.Update(dt, dt, _dummy, 0, AppSettings.ReduceMotion);
|
||||
_crowd.Update(dt);
|
||||
_fx.Motes(AppSettings.ReduceMotion ? 0 : 50, Camera.W, Camera.H);
|
||||
_fx.Update(dt);
|
||||
float target = _drawer == Drawer.None ? 0 : 1;
|
||||
_drawerK += (target - _drawerK) * (1 - MathF.Exp(-dt * 14));
|
||||
if (input.Pressed(Microsoft.Xna.Framework.Input.Keys.Escape) && _drawer != Drawer.None) { _drawer = Drawer.None; input.PrevKeys = input.Keys; }
|
||||
}
|
||||
|
||||
public bool DrawerOpen => _drawer != Drawer.None;
|
||||
|
||||
/// Testlauf: Schublade öffnen (0 zu, 1 Gladiator, 2 Ludus), sofort ganz offen.
|
||||
public void DevOpen(int d)
|
||||
{
|
||||
_drawer = (Drawer)d; _drawerK = d == 0 ? 0 : 1;
|
||||
if (d == 1 && _game.Inventory.Count > 0) _sel = _game.Inventory[0].Id;
|
||||
}
|
||||
|
||||
// ── Zeichnen ────────────────────────────────────────────────
|
||||
|
||||
public void Draw(GraphicsDevice gd, SpriteBatch sb, BasicEffect fx, float scale, Vector2 offset)
|
||||
{
|
||||
EnsureArena();
|
||||
D.UiScale = scale;
|
||||
var ui = Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0);
|
||||
|
||||
// Arena im Hintergrund
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
|
||||
var loop = _loopName != null ? ClipCache.Video(_loopName) : null; // Standbild, bis der Film geladen ist
|
||||
var bg = loop != null ? loop[PingPong(_t * 8, loop.Length)] : _backdrop;
|
||||
if (bg != null)
|
||||
{
|
||||
float k = 1.12f * 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.55f, 0.51f, 0.47f), 0,
|
||||
new Vector2(bg.Width / 2f, bg.Height / 2f), k, SpriteEffects.None, 0);
|
||||
}
|
||||
D.Glow(sb, new Vector2(-200, Camera.H / 2), new Vector2(900, 2000), Color.Black * 0.7f);
|
||||
D.Glow(sb, new Vector2(Camera.W + 200, Camera.H / 2), new Vector2(900, 2000), Color.Black * 0.6f);
|
||||
D.Rect(sb, new RectangleF(0, 0, Camera.W, 120), Color.Black * 0.45f);
|
||||
sb.End();
|
||||
|
||||
// Gladiator (links, in der Arena), Licht, Schatten
|
||||
var view = Matrix.CreateTranslation(0, -Stage.FloorY, 0) * Matrix.CreateScale(1.1f) * Matrix.CreateTranslation(520, 930, 0) * ui;
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, view);
|
||||
D.Glow(sb, new Vector2(0, Stage.FloorY - 300), new Vector2(1000, 1100), new Color(255, 190, 120) * 0.14f);
|
||||
D.Glow(sb, new Vector2(0, Stage.FloorY + 6), new Vector2(760, 130), new Color(255, 180, 110) * 0.22f);
|
||||
sb.End();
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, view);
|
||||
_hero.DrawShadow(sb);
|
||||
sb.End();
|
||||
fx.View = view;
|
||||
fx.Projection = Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 0, 1);
|
||||
gd.BlendState = BlendState.AlphaBlend; gd.SamplerStates[0] = SamplerState.LinearClamp;
|
||||
gd.RasterizerState = RasterizerState.CullNone; gd.DepthStencilState = DepthStencilState.None;
|
||||
_hero.DrawBody(gd, fx, _dummy, AppSettings.ReduceMotion);
|
||||
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui * Matrix.Identity);
|
||||
_crowd.Draw(sb, AppSettings.ReduceMotion);
|
||||
sb.End();
|
||||
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);
|
||||
DrawTopBar(sb);
|
||||
if (_drawerK < 0.98f) DrawOffers(sb);
|
||||
DrawDrawerButtons(sb);
|
||||
DrawToast(sb);
|
||||
if (_drawerK > 0.01f) DrawDrawer(sb);
|
||||
sb.End();
|
||||
}
|
||||
|
||||
static int PingPong(double t, int n)
|
||||
{
|
||||
int period = 2 * (n - 1), i = (int)t % period;
|
||||
return i < n ? i : period - i;
|
||||
}
|
||||
|
||||
// ── Kopfleiste ──────────────────────────────────────────────
|
||||
|
||||
void DrawTopBar(SpriteBatch sb)
|
||||
{
|
||||
float x = 40;
|
||||
if (Assets.Sprite(_game.Look.EmblemArt) is Texture2D em)
|
||||
{
|
||||
sb.Draw(em, new Vector2(x + 34, 60), null, Color.White, 0, new Vector2(em.Width / 2f, em.Height / 2f), 70f / em.Width, SpriteEffects.None, 0);
|
||||
x += 80;
|
||||
}
|
||||
D.Text(sb, Assets.Serif, 32, $"{_game.Name} · {L.t(_game.ClassDef.Key)}", new Vector2(x, 42), D.Gold);
|
||||
D.Text(sb, Assets.SansBold, 20, string.Format(L.t("char.level"), _game.CharLevel), new Vector2(x, 84), D.Sand);
|
||||
D.Bar(sb, new RectangleF(x + 110, 74, 300, 20), (float)(_game.CharXp / _game.CharXpToNext), (float)(_game.CharXp / _game.CharXpToNext), D.Blue);
|
||||
|
||||
// Denare
|
||||
float gx = 860;
|
||||
if (Assets.Sprite("icon_denarius") is Texture2D coin)
|
||||
sb.Draw(coin, new Vector2(gx, 60), null, Color.White, 0, new Vector2(coin.Width / 2f, coin.Height / 2f), 52f / coin.Width, SpriteEffects.None, 0);
|
||||
D.Text(sb, Assets.SansBold, 30, NumberFormat.Format(_game.Gold), new Vector2(gx + 36, 52), Color.White);
|
||||
if (_game.GoldPerSec > 0)
|
||||
D.Text(sb, Assets.Sans, 17, string.Format(L.t("res.persec"), NumberFormat.Small(_game.GoldPerSec)), new Vector2(gx + 36, 86), D.Sand);
|
||||
|
||||
// Arena, Rang, Ruhm bis zum Champion
|
||||
float rx = Camera.W - 40;
|
||||
D.Text(sb, Assets.Serif, 28, L.t(ArenaDef.All[_game.Arena].Key), new Vector2(rx, 36), D.Gold, Align.Right);
|
||||
D.Text(sb, Assets.Sans, 18, string.Format(L.t("arena.rank"), _game.Rank + 1, Balance.RANKS_PER_ARENA), new Vector2(rx - 440, 76), D.Sand);
|
||||
D.Bar(sb, new RectangleF(rx - 300, 68, 300, 18), (float)(_game.FameRun / _game.FameRequired), (float)(_game.FameRun / _game.FameRequired), D.Gold);
|
||||
D.Text(sb, Assets.Sans, 15, string.Format(L.t("arena.fame"), NumberFormat.Format(_game.FameRun), NumberFormat.Format(_game.FameRequired)),
|
||||
new Vector2(rx - 150, 100), D.Dim, Align.Center);
|
||||
}
|
||||
|
||||
// ── Gegner zur Wahl ─────────────────────────────────────────
|
||||
|
||||
void DrawOffers(SpriteBatch sb)
|
||||
{
|
||||
var offers = _game.Offers();
|
||||
float w = offers.Count > 3 ? 220 : 270, gap = 20;
|
||||
float total = offers.Count * w + (offers.Count - 1) * gap, x0 = Camera.W - 60 - total, y = 170, h = 650;
|
||||
bool canFight = _game.CanFight;
|
||||
for (int i = 0; i < offers.Count; i++)
|
||||
{
|
||||
var o = offers[i];
|
||||
var r = new RectangleF(x0 + i * (w + gap), y, w, h);
|
||||
bool champ = o.Kind == OfferKind.Champion, hover = canFight && _ui.Hover(r);
|
||||
var accent = champ ? D.Gold : o.Kind == OfferKind.Hard ? D.Red : o.Kind == OfferKind.Easy ? D.Green : D.Sand;
|
||||
Ui.Panel(sb, r, hover ? accent : champ ? D.Gold : D.Border, 0.84f);
|
||||
if (champ) D.Glow(sb, r.Center, new Vector2(w * 1.6f, h * 1.2f), D.Gold * (0.08f + 0.04f * MathF.Sin((float)_t * 3)));
|
||||
|
||||
D.Text(sb, Assets.SansBold, 18, L.t(o.Key).ToUpperInvariant(), new Vector2(r.Center.X, r.Y + 24), accent, Align.Center);
|
||||
// Gegner
|
||||
string art = o.Enemy.Art ?? Art.Enemy(o.Enemy.NameKey);
|
||||
if (Assets.Sprite(art) is Texture2D t)
|
||||
{
|
||||
float k = 300f / t.Height;
|
||||
sb.Draw(t, new Vector2(r.Center.X, r.Y + 350), null, Color.White, 0, new Vector2(t.Width / 2f, Stage.Feet), k * 1.0f, SpriteEffects.FlipHorizontally, 0);
|
||||
}
|
||||
D.Text(sb, Assets.Serif, 24, o.Enemy.Name, new Vector2(r.Center.X, r.Y + 372), Color.White, Align.Center);
|
||||
|
||||
// Aussichten nach Kampfkraft
|
||||
double ratio = _game.DuelRatio(o.Enemy);
|
||||
var (odds, oc) = ratio >= 1.3 ? ("hub.odds.easy", D.Green) : ratio >= 0.85 ? ("hub.odds.even", D.Gold) : ("hub.odds.hard", D.Red);
|
||||
D.Text(sb, Assets.SansBold, 17, L.t(odds), new Vector2(r.Center.X, r.Y + 404), oc, Align.Center);
|
||||
|
||||
// Lohn
|
||||
var (gold, fame, xp) = _game.RewardPreview(o);
|
||||
float ly = r.Y + 440;
|
||||
Line(sb, r, ly, L.t("res.gold"), "+" + NumberFormat.Format(gold));
|
||||
Line(sb, r, ly + 26, L.t("res.fame"), "+" + NumberFormat.Format(fame));
|
||||
Line(sb, r, ly + 52, "XP", "+" + NumberFormat.Format(xp)); // i18n-ok
|
||||
|
||||
// Knöpfe
|
||||
bool auto = _game.CanAutoWin(o);
|
||||
var fb = new RectangleF(r.X + 16, r.Bottom - (auto ? 112 : 62), r.Width - 32, 48);
|
||||
if (_ui.Button(sb, fb, L.t(champ ? "arena.challenge" : "hub.fight"), canFight, selected: champ, size: champ ? 18 : 22, accent: accent))
|
||||
Chosen = o;
|
||||
if (auto && _ui.Button(sb, new RectangleF(r.X + 16, r.Bottom - 58, r.Width - 32, 42), L.t("hub.auto"), canFight, size: 17))
|
||||
{
|
||||
var before = Snapshot();
|
||||
_game.AutoWin(o);
|
||||
ShowResult(ResultLines(before, true), D.Gold);
|
||||
SoundManager.PlayCoins();
|
||||
}
|
||||
}
|
||||
if (!canFight && _game.Recovery > 0)
|
||||
{
|
||||
var r = new RectangleF(x0, y + h / 2 - 50, total, 100);
|
||||
D.Rect(sb, r, Color.Black * 0.7f);
|
||||
D.Text(sb, Assets.Serif, 34, string.Format(L.t("arena.recover"), NumberFormat.Duration(_game.Recovery)), r.Center, D.Red, Align.Center);
|
||||
}
|
||||
}
|
||||
|
||||
static void Line(SpriteBatch sb, RectangleF r, float y, string label, string value)
|
||||
{
|
||||
D.Text(sb, Assets.Sans, 17, label, new Vector2(r.X + 20, y), D.Dim);
|
||||
D.Text(sb, Assets.SansBold, 18, value, new Vector2(r.Right - 20, y), D.Sand, Align.Right);
|
||||
}
|
||||
|
||||
// ── Ergebnis-Meldung ────────────────────────────────────────
|
||||
|
||||
/// Stand vor einem Kampf (für die Meldung danach).
|
||||
public (double Gold, double Fame, double Xp, int Level, int Items) Snapshot() =>
|
||||
(_game.Gold, _game.FameRun, _game.CharXp, _game.CharLevel, _game.Inventory.Count);
|
||||
|
||||
public string[] ResultLines((double Gold, double Fame, double Xp, int Level, int Items) before, bool won)
|
||||
{
|
||||
if (!won) return new[] { L.t("duel.lose"), L.t("hub.lost") };
|
||||
var lines = new List<string>
|
||||
{
|
||||
L.t("duel.win"),
|
||||
string.Format(L.t("hub.won"), NumberFormat.Format(_game.Gold - before.Gold), NumberFormat.Format(_game.FameRun - before.Fame))
|
||||
};
|
||||
if (_game.CharLevel > before.Level) lines.Add(string.Format(L.t("ludus.levelup"), _game.CharLevel));
|
||||
if (_game.Inventory.Count > before.Items && _game.Inventory.Count > 0)
|
||||
lines.Add(string.Format(L.t("hub.loot"), ItemName(_game.Inventory[^1])));
|
||||
return lines.ToArray();
|
||||
}
|
||||
|
||||
void DrawToast(SpriteBatch sb)
|
||||
{
|
||||
if (_toastAge > 4.5 || _toast.Length == 0 || _drawerK > 0.05f) return;
|
||||
float a = (float)Math.Clamp(Math.Min(_toastAge * 4, (4.5 - _toastAge) * 2), 0, 1);
|
||||
float pop = 1 + 0.25f * MathF.Max(0, 1 - (float)_toastAge * 5);
|
||||
var c = new Vector2(520, 220);
|
||||
D.Glow(sb, c + new Vector2(0, 40), new Vector2(900, 320), Color.Black * (0.6f * a));
|
||||
D.Text(sb, Assets.Serif, 64, _toast[0], c, _toastColor * a, Align.Center, pop);
|
||||
for (int i = 1; i < _toast.Length; i++)
|
||||
D.Text(sb, Assets.SansBold, 24, _toast[i], c + new Vector2(0, 40 + i * 34), Color.White * a, Align.Center);
|
||||
}
|
||||
|
||||
// ── Schubladen ──────────────────────────────────────────────
|
||||
|
||||
void DrawDrawerButtons(SpriteBatch sb)
|
||||
{
|
||||
float y = Camera.H - 92;
|
||||
string gl = _game.AttrPoints > 0 ? $"{L.t("ludus.gladiator")} ({_game.AttrPoints})" : L.t("ludus.gladiator");
|
||||
if (_ui.Button(sb, new RectangleF(40, y, 230, 60), gl, selected: _drawer == Drawer.Gladiator, size: 22,
|
||||
accent: _game.AttrPoints > 0 ? D.Gold : null))
|
||||
_drawer = _drawer == Drawer.Gladiator ? Drawer.None : Drawer.Gladiator;
|
||||
if (_ui.Button(sb, new RectangleF(286, y, 230, 60), L.t("main.ludus"), selected: _drawer == Drawer.Ludus, size: 22))
|
||||
_drawer = _drawer == Drawer.Ludus ? Drawer.None : Drawer.Ludus;
|
||||
if (_ui.Button(sb, new RectangleF(532, y, 230, 60), L.t("main.shop"), selected: _drawer == Drawer.Forum, size: 22))
|
||||
_drawer = _drawer == Drawer.Forum ? Drawer.None : Drawer.Forum;
|
||||
int sp = _game.LearnablePoints;
|
||||
string sk = sp > 0 ? $"{L.t("char.skills")} ({sp})" : L.t("char.skills");
|
||||
if (_ui.Button(sb, new RectangleF(778, y, 230, 60), sk, selected: _drawer == Drawer.Skills, size: 22, accent: sp > 0 ? D.Gold : null))
|
||||
_drawer = _drawer == Drawer.Skills ? Drawer.None : Drawer.Skills;
|
||||
}
|
||||
|
||||
void DrawDrawer(SpriteBatch sb)
|
||||
{
|
||||
float w = _drawer == Drawer.Ludus ? 820 : 1300, x = -w + (w + 40) * Ease(_drawerK);
|
||||
var r = new RectangleF(x, 140, w, Camera.H - 260);
|
||||
Ui.Panel(sb, r, D.Gold, 0.94f);
|
||||
if (_drawer == Drawer.Gladiator) DrawGladiator(sb, r);
|
||||
else if (_drawer == Drawer.Ludus) DrawLudus(sb, r);
|
||||
else if (_drawer == Drawer.Forum) DrawForum(sb, r);
|
||||
else if (_drawer == Drawer.Skills) DrawSkills(sb, r);
|
||||
}
|
||||
|
||||
static float Ease(float k) => 1 - (1 - k) * (1 - k);
|
||||
|
||||
void DrawGladiator(SpriteBatch sb, RectangleF r)
|
||||
{
|
||||
float x = r.X + 30, y = r.Y + 40;
|
||||
D.Text(sb, Assets.Serif, 30, $"{_game.Name} · {L.t(_game.ClassDef.Key)}", new Vector2(x, y), D.Gold);
|
||||
D.Text(sb, Assets.SansBold, 20, string.Format(L.t("char.power"), NumberFormat.Format(_game.Power())), new Vector2(x + 700, y), D.Sand, Align.Right);
|
||||
|
||||
// Werte mit Attributpunkten
|
||||
y += 50;
|
||||
D.Text(sb, Assets.SansBold, 20, string.Format(L.t("char.points"), _game.AttrPoints), new Vector2(x, y), _game.AttrPoints > 0 ? D.Gold : D.Dim);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
var s = (Stat)i;
|
||||
float ry = y + 44 + i * 44;
|
||||
D.Text(sb, Assets.Sans, 21, L.t(TextKeys.Of(s)), new Vector2(x, ry), D.Sand);
|
||||
D.Text(sb, Assets.SansBold, 22, _game.Level(s).ToString(NumberFormat.Culture), new Vector2(x + 300, ry), Color.White, Align.Right);
|
||||
if (_ui.Button(sb, new RectangleF(x + 320, ry - 17, 44, 34), "+", _game.AttrPoints > 0, size: 22)) // i18n-ok
|
||||
_game.SpendPoint(s);
|
||||
}
|
||||
// Kampfwerte
|
||||
var c = _game.PlayerCombat();
|
||||
float cx = x + 420;
|
||||
Stat2(sb, cx, y + 44, L.t("ludus.hp"), NumberFormat.Format(c.MaxHp));
|
||||
Stat2(sb, cx, y + 88, L.t("ludus.damage"), NumberFormat.Format(c.Damage));
|
||||
Stat2(sb, cx, y + 132, L.t("ludus.crit"), NumberFormat.Percent(c.Crit));
|
||||
|
||||
// Ausrüstung
|
||||
y += 240;
|
||||
if (_ui.Button(sb, new RectangleF(x + 480, y - 22, 220, 44), L.t("char.equipbest"), size: 18))
|
||||
{
|
||||
if (_game.EquipBest() > 0) SoundManager.PlayPurchase();
|
||||
}
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var slot = (ItemSlot)i;
|
||||
var it = _game.Equipped[i];
|
||||
float ry = y + 40 + i * 74;
|
||||
var row = new RectangleF(x, ry, 700, 66);
|
||||
D.Rect(sb, row, new Color(30, 22, 15) * 0.9f);
|
||||
D.Frame(sb, row, it == null ? D.Border : RarityColor(it.Rarity), 2);
|
||||
if (it != null && Assets.Sprite(it.Def.Icon) is Texture2D icon)
|
||||
sb.Draw(icon, new Vector2(row.X + 36, row.Center.Y), null, Color.White, 0, new Vector2(icon.Width / 2f, icon.Height / 2f), 56f / icon.Width, SpriteEffects.None, 0);
|
||||
D.Text(sb, Assets.Sans, 16, L.t("slot." + slot.ToString().ToLowerInvariant()), new Vector2(row.X + 76, row.Y + 18), D.Dim);
|
||||
D.Text(sb, Assets.SansBold, 20, it == null ? "–" : ItemName(it), new Vector2(row.X + 76, row.Y + 44), it == null ? D.Dim : RarityColor(it.Rarity)); // i18n-ok
|
||||
if (it != null && _sel == it.Id) D.Frame(sb, row, Color.White, 3);
|
||||
if (it != null && _ui.Hit(row)) _sel = it.Id;
|
||||
}
|
||||
DrawInventory(sb, new RectangleF(r.X + 790, r.Y + 30, 430, r.Height - 60));
|
||||
}
|
||||
|
||||
static void Stat2(SpriteBatch sb, float x, float y, string label, string value)
|
||||
{
|
||||
D.Text(sb, Assets.Sans, 19, label, new Vector2(x, y), D.Dim);
|
||||
D.Text(sb, Assets.SansBold, 21, value, new Vector2(x + 320, y), Color.White, Align.Right);
|
||||
}
|
||||
|
||||
void DrawLudus(SpriteBatch sb, RectangleF r)
|
||||
{
|
||||
float x = r.X + 30, y = r.Y + 40;
|
||||
D.Text(sb, Assets.Serif, 30, L.t("main.ludus"), new Vector2(x, y), D.Gold);
|
||||
y += 40;
|
||||
foreach (var u in UpgradeDef.All)
|
||||
{
|
||||
var row = new RectangleF(x, y, r.Width - 60, 84);
|
||||
D.Rect(sb, row, new Color(30, 22, 15) * 0.9f);
|
||||
D.Frame(sb, row, D.Border, 2);
|
||||
if (Assets.Sprite(Art.Upgrade(u)) is Texture2D icon)
|
||||
sb.Draw(icon, new Vector2(row.X + 42, row.Center.Y), null, Color.White, 0, new Vector2(icon.Width / 2f, icon.Height / 2f), 64f / icon.Width, SpriteEffects.None, 0);
|
||||
int level = _game.UpgradeLevel(u.Id);
|
||||
D.Text(sb, Assets.SansBold, 21, L.t(u.Key), new Vector2(row.X + 86, row.Y + 24), Color.White);
|
||||
D.Text(sb, Assets.Sans, 17, string.Format(L.t("ludus.level"), level), new Vector2(row.X + 86, row.Y + 56), D.Sand);
|
||||
string desc = u.Stat is Stat s ? string.Format(L.t("upgrade.trainer.desc"), L.t(TextKeys.Of(s))) : L.t(u.Key + ".desc");
|
||||
D.Text(sb, Assets.Sans, 15, desc.Length > 52 ? desc[..50] + "…" : desc, new Vector2(row.X + 200, row.Y + 56), D.Dim); // i18n-ok
|
||||
double cost = _game.UpgradeCost(u.Id);
|
||||
if (_ui.Button(sb, new RectangleF(row.Right - 200, row.Y + 16, 184, 52), NumberFormat.Format(cost), _game.Gold >= cost, size: 20))
|
||||
if (_game.Buy(u.Id)) SoundManager.PlayPurchase();
|
||||
y += 92;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ItemName(Item it) => L.t(it.Def.Key) + (it.Level > 0 ? $" +{it.Level}" : ""); // i18n-ok
|
||||
|
||||
static Color RarityColor(Rarity r) => r switch
|
||||
{
|
||||
Rarity.Good => new Color(110, 200, 90), Rarity.Rare => new Color(90, 160, 240),
|
||||
Rarity.Epic => new Color(185, 110, 235), Rarity.Legendary => new Color(250, 160, 40),
|
||||
_ => new Color(190, 175, 150)
|
||||
};
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
92
Mono/Arena/MenuScene.cs
Normal file
92
Mono/Arena/MenuScene.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using GladiatorIdle.Gfx;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using D = GladiatorIdle.Gfx.Draw;
|
||||
|
||||
namespace GladiatorIdle.Arena
|
||||
{
|
||||
/// <summary>
|
||||
/// Startmenü: Kolosseum im Morgenlicht, Titel, Weiterspielen / Neuer Gladiator (mit zweitem
|
||||
/// Klick zur Sicherheit, wenn ein Spielstand da ist) / Intro / Einstellungen / Beenden.
|
||||
/// </summary>
|
||||
internal sealed class MenuScene
|
||||
{
|
||||
public enum Choice { None, Continue, New, Intro, Settings, Quit }
|
||||
|
||||
readonly Ui _ui = new();
|
||||
readonly Particles _fx = new();
|
||||
readonly Texture2D? _backdrop = Assets.Sprite("intro_colosseum", "jpg");
|
||||
readonly bool _hasSave;
|
||||
readonly int _freedoms;
|
||||
double _t, _armNew;
|
||||
|
||||
public Choice Picked { get; set; }
|
||||
|
||||
public MenuScene(bool hasSave, int freedoms)
|
||||
{
|
||||
_hasSave = hasSave;
|
||||
_freedoms = freedoms;
|
||||
SoundManager.StartAmbient("music_menu");
|
||||
// Intro-Clips schon jetzt im Hintergrund laden
|
||||
foreach (var s in IntroScene.Scenes) ClipCache.Video(s);
|
||||
}
|
||||
|
||||
public void Update(float dt, Input input, Matrix ui, bool overlay)
|
||||
{
|
||||
_t += dt;
|
||||
_armNew = Math.Max(0, _armNew - dt);
|
||||
if (!overlay) _ui.Begin(input, ui); else _ui.Click = false;
|
||||
_fx.Motes(AppSettings.ReduceMotion ? 0 : 70, Camera.W, Camera.H);
|
||||
_fx.Update(dt);
|
||||
}
|
||||
|
||||
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 (_backdrop != null)
|
||||
{
|
||||
// langsames Heranfahren
|
||||
float k = (1.08f + 0.03f * (float)Math.Sin(_t * 0.05)) * MathF.Max(Camera.W / _backdrop.Width, Camera.H / _backdrop.Height);
|
||||
sb.Draw(_backdrop, new Vector2(Camera.W / 2, Camera.H / 2), null, new Color(0.62f, 0.58f, 0.54f), 0,
|
||||
new Vector2(_backdrop.Width / 2f, _backdrop.Height / 2f), k, SpriteEffects.None, 0);
|
||||
}
|
||||
D.Glow(sb, new Vector2(Camera.W / 2, Camera.H / 2), new Vector2(Camera.W * 0.9f, Camera.H * 1.2f), Color.Black * 0.35f);
|
||||
D.Glow(sb, new Vector2(-200, Camera.H / 2), new Vector2(900, 2000), Color.Black * 0.8f);
|
||||
D.Glow(sb, new Vector2(Camera.W + 200, Camera.H / 2), new Vector2(900, 2000), Color.Black * 0.8f);
|
||||
sb.End();
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, ui);
|
||||
_fx.DrawAdd(sb);
|
||||
D.Glow(sb, new Vector2(Camera.W / 2, 230), new Vector2(1500, 420), D.Gold * 0.10f);
|
||||
sb.End();
|
||||
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
|
||||
float appear = MathHelper.Clamp((float)_t / 0.8f, 0, 1);
|
||||
D.Text(sb, Assets.Serif, 120, L.t("app.title").ToUpperInvariant(), new Vector2(Camera.W / 2, 220), D.Gold * appear, Align.Center, 1.06f - 0.06f * appear);
|
||||
D.Text(sb, Assets.Serif, 32, L.t("start.subtitle"), new Vector2(Camera.W / 2, 320), D.Sand * appear, Align.Center);
|
||||
|
||||
float w = 520, h = 74, x = (Camera.W - w) / 2, y = 430;
|
||||
if (_hasSave && _ui.Button(sb, new RectangleF(x, y, w, h), L.t("menu.continue"), selected: true, size: 30)) Picked = Choice.Continue;
|
||||
if (_hasSave) y += h + 18;
|
||||
string newText = _armNew > 0 ? L.t("menu.new.confirm") : L.t("menu.new");
|
||||
if (_ui.Button(sb, new RectangleF(x, y, w, h), newText, selected: !_hasSave, size: _armNew > 0 ? 18 : 28, accent: _armNew > 0 ? D.Red : null))
|
||||
{
|
||||
if (!_hasSave || _armNew > 0) Picked = Choice.New;
|
||||
else _armNew = 4; // zweiter Klick innerhalb von 4 s
|
||||
}
|
||||
y += h + 18;
|
||||
if (_ui.Button(sb, new RectangleF(x, y, w, h), L.t("menu.intro"), size: 26)) Picked = Choice.Intro;
|
||||
y += h + 18;
|
||||
if (_ui.Button(sb, new RectangleF(x, y, w, h), L.t("main.settings"), size: 26)) Picked = Choice.Settings;
|
||||
y += h + 18;
|
||||
if (_ui.Button(sb, new RectangleF(x, y, w, h), L.t("main.quit"), size: 26)) Picked = Choice.Quit;
|
||||
|
||||
if (_freedoms > 0)
|
||||
D.Text(sb, Assets.Serif, 22, string.Format(L.t("menu.freedoms"), _freedoms), new Vector2(Camera.W / 2, y + h + 50), D.Gold, Align.Center);
|
||||
D.Text(sb, Assets.Sans, 16, $"{Credits.COPYRIGHT} · {Credits.DISCORD}", new Vector2(Camera.W / 2, Camera.H - 30), D.Dim, Align.Center); // i18n-ok
|
||||
sb.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
150
Mono/Arena/ModelTestScene.cs
Normal file
150
Mono/Arena/ModelTestScene.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
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>
|
||||
/// Test: ein Gladiator als 3D-Modell (Mixamo-Bewegungen) vor der Arena. Start mit --model3d.
|
||||
/// Pfeile/1–9: Bewegung, Leertaste: anhalten, Maus ziehen: drehen, Rad: Abstand,
|
||||
/// V: Ansicht (vorn / schräg / Duell-Seite), T: Teamfarbe, Esc: beenden.
|
||||
/// </summary>
|
||||
internal sealed class ModelTestScene
|
||||
{
|
||||
public readonly Model3D? Model;
|
||||
readonly BasicEffect _fx;
|
||||
readonly Texture2D? _backdrop;
|
||||
public int ClipIndex;
|
||||
public float Time, Yaw, Distance = 520;
|
||||
public bool Paused;
|
||||
public int Color = -1;
|
||||
float _blend = 1;
|
||||
int _lastX = -1;
|
||||
int _prevWheel;
|
||||
static readonly float[] Views = { 0, MathHelper.ToRadians(35), MathHelper.ToRadians(90) };
|
||||
int _view;
|
||||
Matrix? _fit; // Modell in Zentimeter, Füße auf dem Boden (aus der ersten Haltung)
|
||||
|
||||
public ModelTestScene(GraphicsDevice gd)
|
||||
{
|
||||
// --model=<name>: andere Figur ansehen (Standard: hero_murmillo_1)
|
||||
string name = Array.Find(Environment.GetCommandLineArgs(), x => x.StartsWith("--model="))?[8..] ?? "hero_murmillo_1";
|
||||
Model = Model3D.Load(gd, name);
|
||||
Model?.AddSword();
|
||||
Model?.AddShield();
|
||||
_backdrop = Assets.Sprite("arena_colosseum", "jpg");
|
||||
_fx = new BasicEffect(gd) { VertexColorEnabled = true, LightingEnabled = true, PreferPerPixelLighting = true };
|
||||
_fx.AmbientLightColor = new Vector3(0.42f, 0.38f, 0.36f);
|
||||
_fx.DirectionalLight0.Enabled = true;
|
||||
_fx.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(-0.4f, -0.7f, -0.6f));
|
||||
_fx.DirectionalLight0.DiffuseColor = new Vector3(0.95f, 0.85f, 0.72f);
|
||||
_fx.DirectionalLight0.SpecularColor = new Vector3(0.25f, 0.22f, 0.2f);
|
||||
_fx.DirectionalLight1.Enabled = true; // kühles Gegenlicht von hinten links
|
||||
_fx.DirectionalLight1.Direction = Vector3.Normalize(new Vector3(0.7f, -0.2f, 0.7f));
|
||||
_fx.DirectionalLight1.DiffuseColor = new Vector3(0.25f, 0.3f, 0.4f);
|
||||
_fx.DirectionalLight2.Enabled = false;
|
||||
_fx.SpecularPower = 24;
|
||||
Yaw = Views[1];
|
||||
_view = 1;
|
||||
}
|
||||
|
||||
public Model3D.Clip? Clip => Model != null && Model.Clips.Count > 0 ? Model.Clips[ClipIndex % Model.Clips.Count] : null;
|
||||
|
||||
public void Play(int index)
|
||||
{
|
||||
if (Model == null || Model.Clips.Count == 0) return;
|
||||
ClipIndex = (index % Model.Clips.Count + Model.Clips.Count) % Model.Clips.Count;
|
||||
Time = 0;
|
||||
Model.BeginBlend();
|
||||
_blend = 0;
|
||||
}
|
||||
|
||||
public void SetView(int v) { _view = v % Views.Length; Yaw = Views[_view]; }
|
||||
|
||||
public void Update(float dt, Input input)
|
||||
{
|
||||
if (Model == null) return;
|
||||
if (input.Pressed(Keys.Right)) Play(ClipIndex + 1);
|
||||
if (input.Pressed(Keys.Left)) Play(ClipIndex - 1);
|
||||
for (int k = 0; k < 9; k++) if (input.Pressed(Keys.D1 + k)) Play(k);
|
||||
if (input.Pressed(Keys.Space)) Paused = !Paused;
|
||||
if (input.Pressed(Keys.V)) SetView(_view + 1);
|
||||
if (input.Pressed(Keys.T)) Color = Color + 1 >= Appearance.Colors.Length ? -1 : Color + 1;
|
||||
// drehen mit gedrückter linker Maustaste, Abstand mit dem Rad
|
||||
if (input.Mouse.LeftButton == ButtonState.Pressed)
|
||||
{
|
||||
if (_lastX >= 0) Yaw += (input.Mouse.X - _lastX) * 0.01f;
|
||||
_lastX = input.Mouse.X;
|
||||
}
|
||||
else _lastX = -1;
|
||||
int wheel = input.Mouse.ScrollWheelValue;
|
||||
Distance = MathHelper.Clamp(Distance - (wheel - _prevWheel) * 0.3f, 200, 1200);
|
||||
_prevWheel = wheel;
|
||||
|
||||
if (!Paused) Time += dt;
|
||||
_blend = Math.Min(1, _blend + dt / 0.15f);
|
||||
Model.SetColor(Color);
|
||||
}
|
||||
|
||||
public void Draw(GraphicsDevice gd, SpriteBatch sb, float scale, Vector2 offset)
|
||||
{
|
||||
var vp = gd.Viewport;
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp);
|
||||
if (_backdrop != null)
|
||||
{
|
||||
float k = MathF.Max(vp.Width / (float)_backdrop.Width, vp.Height / (float)_backdrop.Height);
|
||||
sb.Draw(_backdrop, new Vector2(vp.Width / 2f, vp.Height / 2f), null, new Color(0.55f, 0.52f, 0.5f), 0,
|
||||
new Vector2(_backdrop.Width / 2f, _backdrop.Height / 2f), k, SpriteEffects.None, 0);
|
||||
}
|
||||
sb.End();
|
||||
if (Model == null || Clip is not Model3D.Clip clip)
|
||||
{
|
||||
sb.Begin(transformMatrix: Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0));
|
||||
D.Text(sb, Assets.SansBold, 30, L.t("model3d.missing"), new Vector2(Camera.W / 2, Camera.H / 2), Microsoft.Xna.Framework.Color.White, Align.Center);
|
||||
sb.End();
|
||||
return;
|
||||
}
|
||||
bool loop = clip.Name is "idle" or "walk" or "run" or "blockidle" or "strafe"; // i18n-ok
|
||||
Model.Pose(clip, Time, loop, _blend);
|
||||
|
||||
var target = new Vector3(0, 95, 0);
|
||||
var view = Matrix.CreateLookAt(target + new Vector3(0, 25, Distance), target, Vector3.Up);
|
||||
var proj = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(32), vp.AspectRatio, 10, 5000);
|
||||
if (_fit == null && _blend >= 1)
|
||||
{
|
||||
// robuste Grenzen (einzelne Ausreißer-Punkte verschieben sonst Boden und Größe)
|
||||
float Q(Func<Vector3, float> axis, float q)
|
||||
{
|
||||
var a = Array.ConvertAll(Model.Vertices, v => axis(v.Position));
|
||||
Array.Sort(a);
|
||||
return a[(int)(q * (a.Length - 1))];
|
||||
}
|
||||
float y0 = Q(p => p.Y, 0.002f), y1 = Q(p => p.Y, 0.998f);
|
||||
float cx = (Q(p => p.X, 0.01f) + Q(p => p.X, 0.99f)) / 2, cz = (Q(p => p.Z, 0.01f) + Q(p => p.Z, 0.99f)) / 2;
|
||||
_fit = Matrix.CreateTranslation(-cx, -y0, -cz) * Matrix.CreateScale(180 / MathF.Max(1e-3f, y1 - y0));
|
||||
DevShot.Log($"model3d fit: unit {Model.Unit} feet {y0:0.0} top {y1:0.0}");
|
||||
}
|
||||
var world = (_fit ?? Matrix.Identity) * Matrix.CreateRotationY(Yaw);
|
||||
|
||||
// Schatten unter den Füßen
|
||||
var feet = vp.Project(Vector3.Zero, proj, view, world);
|
||||
var side = vp.Project(new Vector3(60, 0, 0), proj, view, Matrix.Identity);
|
||||
float w = MathF.Abs(side.X - vp.Project(Vector3.Zero, proj, view, Matrix.Identity).X) * 2.4f;
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
|
||||
D.Glow(sb, new Vector2(feet.X, feet.Y), new Vector2(w, w * 0.22f), Microsoft.Xna.Framework.Color.Black * 0.7f);
|
||||
sb.End();
|
||||
|
||||
_fx.World = world; _fx.View = view; _fx.Projection = proj;
|
||||
Model.Draw(gd, _fx);
|
||||
|
||||
sb.Begin(transformMatrix: Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0));
|
||||
string info = $"{ClipIndex + 1}/{Model.Clips.Count} {clip.Name} {Time % MathF.Max(clip.Length, 0.01f):0.00}/{clip.Length:0.00} s"; // i18n-ok
|
||||
D.Text(sb, Assets.SansBold, 26, info, new Vector2(40, 40), D.Gold);
|
||||
D.Text(sb, Assets.Sans, 18, L.t("model3d.help"), new Vector2(40, 80), D.Sand);
|
||||
sb.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
136
Mono/Arena/Particles.cs
Normal file
136
Mono/Arena/Particles.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GladiatorIdle.Gfx;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace GladiatorIdle.Arena
|
||||
{
|
||||
internal enum PKind { Spark, Dust, Mote, Ring, Chip }
|
||||
|
||||
/// <summary>Funken (gestreckt, additiv), Sand/Staub (weich), Schwebstaub im Licht, Ringe, Splitter.</summary>
|
||||
internal sealed class Particles
|
||||
{
|
||||
struct P
|
||||
{
|
||||
public PKind Kind;
|
||||
public Vector2 Pos, Vel;
|
||||
public float Age, Life, Size, Grow, Gravity, Drag, Rot, Spin;
|
||||
public Color Color;
|
||||
}
|
||||
|
||||
readonly List<P> _list = new(2048);
|
||||
readonly Random _rng = new();
|
||||
public bool Calm;
|
||||
|
||||
float R(float a, float b) => a + (float)_rng.NextDouble() * (b - a);
|
||||
|
||||
public void Sparks(Vector2 at, int n, Color c, float dir = 0, float spread = MathF.PI, float speed = 900)
|
||||
{
|
||||
if (Calm) n /= 3;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
float a = dir + R(-spread, spread), v = R(0.3f, 1f) * speed;
|
||||
_list.Add(new P { Kind = PKind.Spark, Pos = at, Vel = new Vector2(MathF.Cos(a), MathF.Sin(a)) * v - new Vector2(0, R(100, 300)),
|
||||
Life = R(0.18f, 0.45f), Size = R(2.5f, 5f), Gravity = 1600, Drag = 2.5f, Color = c });
|
||||
}
|
||||
}
|
||||
|
||||
public void Dust(Vector2 at, int n, float spread = 60, float rise = 60, float size = 60)
|
||||
{
|
||||
if (Calm) n /= 2;
|
||||
for (int i = 0; i < n; i++)
|
||||
_list.Add(new P { Kind = PKind.Dust, Pos = at + new Vector2(R(-spread, spread), R(-8, 4)),
|
||||
Vel = new Vector2(R(-120, 120), -R(10, rise)), Life = R(0.5f, 1.1f), Size = R(0.6f, 1f) * size,
|
||||
Grow = size * 1.2f, Drag = 2.2f, Color = new Color(150, 120, 85) * 0.55f });
|
||||
}
|
||||
|
||||
public void Chips(Vector2 at, int n, Color c, int facing)
|
||||
{
|
||||
if (Calm) n /= 2;
|
||||
for (int i = 0; i < n; i++)
|
||||
_list.Add(new P { Kind = PKind.Chip, Pos = at, Vel = new Vector2(facing * R(150, 650), -R(250, 750)), Life = R(0.5f, 0.9f),
|
||||
Size = R(4, 9), Gravity = 2000, Drag = 0.6f, Rot = R(0, 6), Spin = R(-20, 20), Color = c });
|
||||
}
|
||||
|
||||
public void Ring(Vector2 at, Color c, float size = 420, float life = 0.35f) =>
|
||||
_list.Add(new P { Kind = PKind.Ring, Pos = at, Life = life, Size = 40, Grow = size / life, Color = c });
|
||||
|
||||
/// Schwebstaub im Licht: langsam, flackernd; hält die Anzahl um <paramref name="count"/>.
|
||||
public void Motes(int count, float w, float h)
|
||||
{
|
||||
int have = 0;
|
||||
foreach (var p in _list) if (p.Kind == PKind.Mote) have++;
|
||||
for (int i = have; i < count; i++)
|
||||
_list.Add(new P { Kind = PKind.Mote, Pos = new Vector2(R(-200, w + 200), R(80, h - 120)), Vel = new Vector2(R(-12, 12), R(-14, -4)),
|
||||
Life = R(5, 11), Size = R(3, 7), Rot = R(0, 6), Color = new Color(255, 215, 150) * 0.5f });
|
||||
}
|
||||
|
||||
public void Update(float dt)
|
||||
{
|
||||
for (int i = _list.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var p = _list[i];
|
||||
p.Age += dt;
|
||||
if (p.Age >= p.Life) { _list[i] = _list[^1]; _list.RemoveAt(_list.Count - 1); continue; }
|
||||
p.Vel.Y += p.Gravity * dt;
|
||||
p.Vel *= MathF.Exp(-p.Drag * dt);
|
||||
p.Pos += p.Vel * dt;
|
||||
p.Size += p.Grow * dt;
|
||||
p.Rot += p.Spin * dt;
|
||||
if (p.Kind == PKind.Chip && p.Pos.Y > Stage.FloorY) { p.Pos.Y = Stage.FloorY; p.Vel.Y *= -0.3f; p.Vel.X *= 0.5f; p.Spin *= 0.5f; }
|
||||
_list[i] = p;
|
||||
}
|
||||
}
|
||||
|
||||
/// Weiche Teile (Staub, Schwebstaub, Splitter) mit Alpha-Mischung.
|
||||
public void DrawSoft(SpriteBatch sb)
|
||||
{
|
||||
foreach (var p in _list)
|
||||
{
|
||||
float k = p.Age / p.Life;
|
||||
switch (p.Kind)
|
||||
{
|
||||
case PKind.Dust:
|
||||
Draw.Glow(sb, p.Pos, new Vector2(p.Size * 1.4f, p.Size), p.Color * (1 - k));
|
||||
break;
|
||||
case PKind.Chip:
|
||||
sb.Draw(Assets.Pixel, p.Pos, null, p.Color * MathF.Min(1, (1 - k) * 3), p.Rot, new Vector2(0.5f), new Vector2(p.Size, p.Size * 0.6f), SpriteEffects.None, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Leuchtende Teile (Funken, Ringe, Schwebstaub) additiv.
|
||||
public void DrawAdd(SpriteBatch sb)
|
||||
{
|
||||
foreach (var p in _list)
|
||||
{
|
||||
float k = p.Age / p.Life;
|
||||
switch (p.Kind)
|
||||
{
|
||||
case PKind.Spark:
|
||||
float len = MathF.Max(6, p.Vel.Length() * 0.035f);
|
||||
float rot = MathF.Atan2(p.Vel.Y, p.Vel.X);
|
||||
sb.Draw(Assets.Pixel, p.Pos, null, p.Color * (1 - k), rot, new Vector2(1, 0.5f), new Vector2(len, p.Size), SpriteEffects.None, 0);
|
||||
Draw.Glow(sb, p.Pos, new Vector2(p.Size * 6), p.Color * (0.35f * (1 - k)));
|
||||
break;
|
||||
case PKind.Ring:
|
||||
// Ring aus vielen Punkten
|
||||
int n = 48;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
float a = i * MathF.Tau / n;
|
||||
Draw.Glow(sb, p.Pos + new Vector2(MathF.Cos(a), MathF.Sin(a) * 0.55f) * p.Size, new Vector2(26), p.Color * ((1 - k) * 0.9f));
|
||||
}
|
||||
break;
|
||||
case PKind.Mote:
|
||||
float tw = 0.5f + 0.5f * MathF.Sin(p.Age * 2.5f + p.Rot);
|
||||
float fade = MathF.Min(1, MathF.Min(p.Age, p.Life - p.Age));
|
||||
Draw.Glow(sb, p.Pos, new Vector2(p.Size * 2), p.Color * (tw * fade));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
104
Mono/Arena/SettingsOverlay.cs
Normal file
104
Mono/Arena/SettingsOverlay.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
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>
|
||||
/// Einstellungen über jedem Bildschirm: Lautstärken (Musik, Effekte, Erzählstimme), Ton an/aus,
|
||||
/// Vollbild, Sprache, Erzählstimme, Effekte reduzieren. Jede Änderung wird sofort gespeichert.
|
||||
/// </summary>
|
||||
internal sealed class SettingsOverlay
|
||||
{
|
||||
readonly Ui _ui = new();
|
||||
readonly Action _toggleFullscreen;
|
||||
public bool Open { get; set; }
|
||||
|
||||
public SettingsOverlay(Action toggleFullscreen) => _toggleFullscreen = toggleFullscreen;
|
||||
|
||||
public void Update(Input input, Matrix ui)
|
||||
{
|
||||
_ui.Begin(input, ui);
|
||||
if (input.Pressed(Microsoft.Xna.Framework.Input.Keys.Escape)) { Open = false; input.PrevKeys = input.Keys; }
|
||||
}
|
||||
|
||||
/// Text ohne vorangestelltes Symbol (die Schrift hat keine Emoji).
|
||||
static string Plain(string s) => new string(s.SkipWhile(c => !char.IsLetter(c)).ToArray());
|
||||
|
||||
static void Save()
|
||||
{
|
||||
AppSettings.Save();
|
||||
AppSettings.ApplyVolumes();
|
||||
}
|
||||
|
||||
public void Draw(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);
|
||||
D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), Color.Black * 0.6f);
|
||||
var r = new RectangleF(Camera.W / 2 - 420, 100, 840, 880);
|
||||
Ui.Panel(sb, r, D.Gold, 0.97f);
|
||||
float x = r.X + 50, y = r.Y + 60, w = r.Width - 100;
|
||||
D.Text(sb, Assets.Serif, 40, L.t("main.settings").ToUpperInvariant(), new Vector2(r.Center.X, y), D.Gold, Align.Center);
|
||||
|
||||
// Audio
|
||||
y += 70;
|
||||
D.Text(sb, Assets.SansBold, 18, L.t("settings.sec.audio"), new Vector2(x, y), D.Dim);
|
||||
y += 40;
|
||||
Volume(sb, x, y, w, L.t("settings.row.music"), () => AppSettings.MusicVolume, v => AppSettings.MusicVolume = v); y += 56;
|
||||
Volume(sb, x, y, w, L.t("settings.row.sfx"), () => AppSettings.SfxVolume, v => AppSettings.SfxVolume = v); y += 56;
|
||||
Volume(sb, x, y, w, L.t("settings.vol.voice"), () => AppSettings.VoiceVolume, v => AppSettings.VoiceVolume = v); y += 56;
|
||||
Toggle(sb, x, y, w, Plain(L.t(AppSettings.Muted ? "settings.muted" : "settings.sound.on")), !AppSettings.Muted,
|
||||
() => { AppSettings.Muted = !AppSettings.Muted; if (!AppSettings.Muted) SoundManager.StartAmbient(); });
|
||||
y += 56;
|
||||
Toggle(sb, x, y, w, L.t("settings.narration"), AppSettings.Narration, () => AppSettings.Narration = !AppSettings.Narration);
|
||||
|
||||
// Anzeige
|
||||
y += 80;
|
||||
D.Text(sb, Assets.SansBold, 18, L.t("settings.sec.display"), new Vector2(x, y), D.Dim);
|
||||
y += 40;
|
||||
Toggle(sb, x, y, w, L.t("settings.fullscreen"), AppSettings.Fullscreen, _toggleFullscreen);
|
||||
y += 56;
|
||||
Toggle(sb, x, y, w, L.t("settings.reducemotion"), AppSettings.ReduceMotion, () => AppSettings.ReduceMotion = !AppSettings.ReduceMotion);
|
||||
y += 56;
|
||||
D.Text(sb, Assets.Sans, 22, L.t("settings.row.language"), new Vector2(x, y), D.Sand);
|
||||
var langs = new[] { (L.Lang.De, "Deutsch"), (L.Lang.En, "English"), (L.Lang.Es, "Español") }; // i18n-ok
|
||||
for (int i = 0; i < langs.Length; i++)
|
||||
{
|
||||
var (lang, name) = langs[i];
|
||||
if (_ui.Button(sb, new RectangleF(x + w - 3 * 150 - 20 + i * 160, y - 22, 150, 44), name, selected: L.Current == lang, size: 18))
|
||||
if (L.Current != lang && DevShot.Lang == null) L.Set(lang);
|
||||
}
|
||||
|
||||
if (_ui.Button(sb, new RectangleF(r.Center.X - 160, r.Bottom - 100, 320, 64), L.t("select.back"), selected: true, size: 26))
|
||||
Open = false;
|
||||
D.Text(sb, Assets.Sans, 15, $"{Credits.COPYRIGHT} · {Credits.MAIL}", new Vector2(r.Center.X, r.Bottom - 20), D.Dim, Align.Center); // i18n-ok
|
||||
sb.End();
|
||||
}
|
||||
|
||||
void Volume(SpriteBatch sb, float x, float y, float w, string label, Func<int> get, Action<int> set)
|
||||
{
|
||||
D.Text(sb, Assets.Sans, 22, label, new Vector2(x, y), D.Sand);
|
||||
var steps = AppSettings.VolumeSteps;
|
||||
for (int i = 0; i < steps.Length; i++)
|
||||
{
|
||||
int v = steps[i];
|
||||
var r = new RectangleF(x + w - steps.Length * 86 + i * 86, y - 20, 78, 40);
|
||||
if (_ui.Button(sb, r, v.ToString(NumberFormat.Culture), selected: get() == v, size: 17)) { set(v); Save(); SoundManager.PlayClick(); }
|
||||
}
|
||||
}
|
||||
|
||||
void Toggle(SpriteBatch sb, float x, float y, float w, string label, bool on, Action flip)
|
||||
{
|
||||
D.Text(sb, Assets.Sans, 22, label, new Vector2(x, y), D.Sand);
|
||||
if (_ui.Button(sb, new RectangleF(x + w - 170, y - 20, 170, 40), L.t(on ? "settings.on" : "settings.off"), selected: on, size: 18))
|
||||
{
|
||||
flip();
|
||||
Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
476
Mono/ArenaGame.cs
Normal file
476
Mono/ArenaGame.cs
Normal file
@@ -0,0 +1,476 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GladiatorIdle.Arena;
|
||||
using GladiatorIdle.Gfx;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace GladiatorIdle
|
||||
{
|
||||
/// <summary>
|
||||
/// Das Spiel: Startmenü → (Intro) → Erstellung des eigenen Gladiators → Arena ↔ Kampf.
|
||||
/// Einstellungen und Pause liegen als Ebenen darüber. Eigener Spielstand (arena.json),
|
||||
/// gespeichert nach jedem Kampf, alle 30 s und beim Beenden. Testläufe speichern nie.
|
||||
/// </summary>
|
||||
internal sealed class ArenaGame : Game
|
||||
{
|
||||
readonly GraphicsDeviceManager _gdm;
|
||||
SpriteBatch _sb = null!;
|
||||
BasicEffect _fx = null!;
|
||||
RenderTarget2D? _rt;
|
||||
GameState? _game;
|
||||
MenuScene? _menu;
|
||||
IntroScene? _intro;
|
||||
CreatorScene? _creator;
|
||||
HubScene? _hub;
|
||||
DuelScene? _scene;
|
||||
ModelTestScene? _model; // --model3d: 3D-Test
|
||||
static readonly bool Model3DTest = Array.IndexOf(Environment.GetCommandLineArgs(), "--model3d") >= 0;
|
||||
SettingsOverlay _settings = null!;
|
||||
bool _paused;
|
||||
readonly Ui _pauseUi = new();
|
||||
bool _introThenCreate; // erster Start: nach dem Intro gleich die Erstellung
|
||||
Offer? _offer;
|
||||
(double Gold, double Fame, double Xp, int Level, int Items) _before;
|
||||
double _saveIn = 30;
|
||||
Enemy _enemy = null!;
|
||||
readonly Input _input = new(), _noInput = new();
|
||||
int _seed = 1;
|
||||
|
||||
// Testlauf
|
||||
double _devTime;
|
||||
int _rec = -1;
|
||||
string? _capture;
|
||||
readonly System.Collections.Generic.HashSet<string> _shots = new();
|
||||
readonly Stopwatch _drawWatch = new();
|
||||
double _drawMs, _frameSum; int _frames;
|
||||
double _hubDraw, _duelDraw; int _hubFrames, _duelFrames;
|
||||
|
||||
public ArenaGame()
|
||||
{
|
||||
_gdm = new GraphicsDeviceManager(this) { SynchronizeWithVerticalRetrace = true, GraphicsProfile = GraphicsProfile.HiDef };
|
||||
SetMode(AppSettings.Fullscreen);
|
||||
IsFixedTimeStep = false;
|
||||
IsMouseVisible = true;
|
||||
Window.Title = L.t("app.title");
|
||||
Window.AllowUserResizing = true;
|
||||
}
|
||||
|
||||
void SetMode(bool fullscreen)
|
||||
{
|
||||
if (fullscreen)
|
||||
{
|
||||
_gdm.HardwareModeSwitch = false;
|
||||
_gdm.IsFullScreen = true;
|
||||
var mode = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode;
|
||||
_gdm.PreferredBackBufferWidth = mode.Width;
|
||||
_gdm.PreferredBackBufferHeight = mode.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
_gdm.IsFullScreen = false;
|
||||
var size = DevShot.WindowSize ?? new System.Drawing.Size(1600, 900);
|
||||
_gdm.PreferredBackBufferWidth = size.Width;
|
||||
_gdm.PreferredBackBufferHeight = size.Height;
|
||||
}
|
||||
}
|
||||
|
||||
void ToggleFullscreen()
|
||||
{
|
||||
AppSettings.Fullscreen = !AppSettings.Fullscreen;
|
||||
AppSettings.Save();
|
||||
SetMode(AppSettings.Fullscreen);
|
||||
_gdm.ApplyChanges();
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Window.ClientSizeChanged += (_, _) =>
|
||||
{
|
||||
if (_gdm.IsFullScreen || Window.ClientBounds.Width < 64) return;
|
||||
_gdm.PreferredBackBufferWidth = Window.ClientBounds.Width;
|
||||
_gdm.PreferredBackBufferHeight = Window.ClientBounds.Height;
|
||||
_gdm.ApplyChanges();
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadContent()
|
||||
{
|
||||
_sb = new SpriteBatch(GraphicsDevice);
|
||||
_fx = new BasicEffect(GraphicsDevice) { TextureEnabled = true, VertexColorEnabled = true, LightingEnabled = false, World = Matrix.Identity };
|
||||
Assets.Init(GraphicsDevice);
|
||||
_settings = new SettingsOverlay(ToggleFullscreen);
|
||||
Window.TextInput += (_, e) => { if (!_settings.Open) _creator?.OnText(e.Character, e.Key); };
|
||||
// eigener Spielstand fürs neue Spiel; vorhandenen laden und Abwesenheit nachrechnen
|
||||
GameState.SaveFile = "arena.json";
|
||||
if (Model3DTest) { _model = new ModelTestScene(GraphicsDevice); return; }
|
||||
if (!DevShot.Active && GameState.Load(out var savedUtc) is GameState loaded)
|
||||
{
|
||||
_game = loaded;
|
||||
_game.ManualFights = true;
|
||||
_game.ApplyOffline((DateTime.UtcNow - savedUtc).TotalSeconds);
|
||||
ToMenu();
|
||||
}
|
||||
else if (!DevShot.Active) { _introThenCreate = true; _intro = new IntroScene(); } // erster Start: Intro
|
||||
else ToMenu();
|
||||
}
|
||||
|
||||
void ToMenu()
|
||||
{
|
||||
_hub = null; _scene = null; _creator = null; _intro = null; _paused = false;
|
||||
_menu = new MenuScene(_game != null, _game?.Freedoms ?? 0);
|
||||
}
|
||||
|
||||
protected override void OnExiting(object sender, ExitingEventArgs args)
|
||||
{
|
||||
if (_game != null && _creator == null) _game.Save(); // Testläufe speichern nie (GameState.Save)
|
||||
base.OnExiting(sender, args);
|
||||
}
|
||||
|
||||
/// Erstellung fertig: neues Leben mit dem eigenen Gladiator, dann in die Arena.
|
||||
void StartGame(CreatorScene c)
|
||||
{
|
||||
int freedoms = _game?.Freedoms ?? 0;
|
||||
_game = new GameState(seed: DevShot.Active ? 7 : Environment.TickCount);
|
||||
_game.Create(c.Name.Trim(), c.Class, c.Look, c.Bonus, c.StartSkill);
|
||||
// --sim H: weiter vorn einsteigen (Testläufe, Ausprobieren späterer Arenen)
|
||||
if (Array.IndexOf(Environment.GetCommandLineArgs(), "--sim") >= 0) Playtest.Advance(_game, DevShot.SimHours);
|
||||
_game.ManualFights = true;
|
||||
_game.Save();
|
||||
_creator = null;
|
||||
var sw = Stopwatch.StartNew();
|
||||
_hub = new HubScene(_game);
|
||||
DevShot.Log($"timing: hub created in {sw.ElapsedMilliseconds} ms");
|
||||
}
|
||||
|
||||
/// Gegner gewählt: Duell beginnt.
|
||||
void StartDuel(Offer o)
|
||||
{
|
||||
_offer = o;
|
||||
_enemy = o.Enemy;
|
||||
_before = _hub!.Snapshot();
|
||||
_game!.BeginDuel();
|
||||
var sw = Stopwatch.StartNew();
|
||||
_scene = new DuelScene(_game, _enemy, _seed++);
|
||||
DevShot.Log($"timing: duel created in {sw.ElapsedMilliseconds} ms");
|
||||
if (DevShot.Active) _scene.Bot = new DuelBot(0.8, new Random(3));
|
||||
DevShot.Log($"duel vs {_enemy.NameKey} ({o.Kind}) arena={_game.Arena} rank={_game.Rank} ratio={_game.DuelRatio(_enemy):0.00}");
|
||||
}
|
||||
|
||||
/// Duell vorbei: Ergebnis übernehmen, zurück in den Hub mit Meldung, speichern.
|
||||
void EndDuel()
|
||||
{
|
||||
bool won = _scene!.Won;
|
||||
_game!.ResolveFight(_offer!, won);
|
||||
_hub!.ShowResult(_hub.ResultLines(_before, won), won ? Gfx.Draw.Gold : Gfx.Draw.Red);
|
||||
SoundManager.StartAmbient("music_ludus");
|
||||
_scene = null;
|
||||
_game.Save();
|
||||
}
|
||||
|
||||
readonly Stopwatch _updWatch = new();
|
||||
double _updMs;
|
||||
|
||||
Matrix UiMatrix(out float s, out Vector2 off)
|
||||
{
|
||||
s = Math.Min(GraphicsDevice.Viewport.Width / Camera.W, GraphicsDevice.Viewport.Height / Camera.H);
|
||||
off = new Vector2((GraphicsDevice.Viewport.Width - Camera.W * s) / 2, (GraphicsDevice.Viewport.Height - Camera.H * s) / 2);
|
||||
return Matrix.CreateScale(s) * Matrix.CreateTranslation(off.X, off.Y, 0);
|
||||
}
|
||||
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
_updWatch.Restart();
|
||||
float dt = (float)Math.Min(0.05, gameTime.ElapsedGameTime.TotalSeconds);
|
||||
ClipCache.Pump(GraphicsDevice, 4); // Video-Sprites nachladen (höchstens 4 ms pro Bild)
|
||||
_input.PrevKeys = _input.Keys; _input.PrevMouse = _input.Mouse;
|
||||
_input.Keys = Keyboard.GetState();
|
||||
_input.Mouse = IsActive ? Mouse.GetState() : default;
|
||||
var ui = UiMatrix(out _, out _);
|
||||
Window.Title = L.t("app.title");
|
||||
|
||||
// Einstellungen liegen über allem und nehmen die Eingaben
|
||||
var input = _input;
|
||||
if (_settings.Open) { _settings.Update(_input, ui); input = _noInput; }
|
||||
if (DevShot.Active) DevMenu(dt);
|
||||
|
||||
if (_model != null)
|
||||
{
|
||||
_model.Update(dt, input);
|
||||
if (input.Pressed(Keys.Escape)) Exit();
|
||||
if (DevShot.Active) DevModel(dt);
|
||||
}
|
||||
else if (_intro != null)
|
||||
{
|
||||
_intro.Update(dt, input, ui);
|
||||
if (_intro.Done)
|
||||
{
|
||||
_intro = null;
|
||||
if (_introThenCreate) { _introThenCreate = false; _creator = new CreatorScene(L.t("gladiator.defaultname")); }
|
||||
else ToMenu();
|
||||
}
|
||||
}
|
||||
else if (_menu != null)
|
||||
{
|
||||
_menu.Update(dt, input, ui, _settings.Open);
|
||||
switch (_menu.Picked)
|
||||
{
|
||||
case MenuScene.Choice.Continue when _game != null: _menu = null; _hub = new HubScene(_game); break;
|
||||
case MenuScene.Choice.New: _menu = null; _creator = new CreatorScene(DevShot.Active ? DevShot.Name : L.t("gladiator.defaultname")); break;
|
||||
case MenuScene.Choice.Intro: _menu = null; _intro = new IntroScene(); break;
|
||||
case MenuScene.Choice.Settings: _menu.Picked = MenuScene.Choice.None; _settings.Open = true; break;
|
||||
case MenuScene.Choice.Quit: Exit(); break;
|
||||
}
|
||||
if (_menu != null && input.Pressed(Keys.Escape)) Exit();
|
||||
}
|
||||
else if (_creator != null)
|
||||
{
|
||||
_creator.Update(dt, input, ui);
|
||||
if (input.Pressed(Keys.Escape)) ToMenu();
|
||||
if (DevShot.Active) DevCreator(dt);
|
||||
if (_creator != null && _creator.Done) StartGame(_creator);
|
||||
}
|
||||
else if (_scene == null && _hub != null)
|
||||
{
|
||||
// Arena zwischen den Kämpfen; Esc: Schublade zu, sonst Pause-Menü
|
||||
if ((_saveIn -= dt) <= 0) { _saveIn = 30; _game!.Save(); }
|
||||
bool drawer = _hub.DrawerOpen;
|
||||
_hub.Update(dt, _paused ? _noInput : input, ui);
|
||||
if (!drawer && !_settings.Open && input.Pressed(Keys.Escape)) _paused = !_paused;
|
||||
if (_paused) _pauseUi.Begin(input, ui);
|
||||
if (DevShot.Active) DevHub(dt);
|
||||
if (_hub?.Chosen is Offer o) { _hub.Chosen = null; StartDuel(o); }
|
||||
}
|
||||
else if (_scene != null)
|
||||
{
|
||||
if ((_saveIn -= dt) <= 0) { _saveIn = 30; _game!.Save(); }
|
||||
if (!IsActive && !DevShot.Active && !_scene.Over) _scene.Paused = true; // Fenster verlassen: Pause
|
||||
if (input.Pressed(Keys.Escape) && !_scene.Over) _scene.Paused = !_scene.Paused;
|
||||
if (_scene.Paused && input.Pressed(Keys.X)) _scene.GiveUp();
|
||||
_game!.Tick(dt); // Training läuft auch im Kampf weiter
|
||||
_scene.Update(dt, input);
|
||||
if (DevShot.Active) DevSteps(dt);
|
||||
if (_scene != null && _scene.Finished && (input.Pressed(Keys.Enter) || input.LeftClick || DevShot.Active && _shots.Contains("m_end") && _capture == null))
|
||||
EndDuel();
|
||||
}
|
||||
base.Update(gameTime);
|
||||
_updMs += _updWatch.Elapsed.TotalMilliseconds;
|
||||
}
|
||||
|
||||
/// Pause-Menü in der Arena: Weiter / Einstellungen / Hauptmenü / Beenden.
|
||||
void DrawPause(SpriteBatch sb, Matrix ui)
|
||||
{
|
||||
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
|
||||
Gfx.Draw.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), Color.Black * 0.6f);
|
||||
Gfx.Draw.Text(sb, Assets.Serif, 100, L.t("duel.pause").ToUpperInvariant(), new Vector2(Camera.W / 2, 300), Gfx.Draw.Gold, Align.Center);
|
||||
float w = 460, h = 70, x = (Camera.W - w) / 2, y = 420;
|
||||
if (_pauseUi.Button(sb, new RectangleF(x, y, w, h), L.t("duel.resume"), selected: true, size: 28)) _paused = false;
|
||||
if (_pauseUi.Button(sb, new RectangleF(x, y + 90, w, h), L.t("main.settings"), size: 26)) _settings.Open = true;
|
||||
if (_pauseUi.Button(sb, new RectangleF(x, y + 180, w, h), L.t("pause.menu"), size: 26)) { _game!.Save(); ToMenu(); }
|
||||
if (_pauseUi.Button(sb, new RectangleF(x, y + 270, w, h), L.t("main.quit"), size: 26)) Exit();
|
||||
sb.End();
|
||||
}
|
||||
|
||||
// ── Testläufe ───────────────────────────────────────────────
|
||||
|
||||
/// Testlauf: Menü und Einstellungen aufnehmen (mit --full auch das Intro), dann Neuer Gladiator.
|
||||
void DevMenu(float dt)
|
||||
{
|
||||
if (_menu == null && _intro == null) return;
|
||||
_devTime += dt;
|
||||
void Shot(string name) { if (_shots.Add(name)) _capture = name; }
|
||||
if (_intro != null)
|
||||
{
|
||||
var times = _intro.CaptureTimes();
|
||||
int k = _shots.Count(s => s.StartsWith("i_"));
|
||||
if (k < times.Length && _capture == null) { _intro.Time = times[k]; Shot($"i_{k}"); }
|
||||
else if (k >= times.Length && _capture == null) { _intro = null; _devTime = 0; ToMenu(); }
|
||||
return;
|
||||
}
|
||||
if (_devTime > 1.0) Shot("c_menu");
|
||||
if (_devTime > 1.4 && !_shots.Contains("c_settings_open")) { _shots.Add("c_settings_open"); _settings.Open = true; }
|
||||
if (_devTime > 1.9) Shot("c_settings");
|
||||
if (_devTime > 2.3 && _capture == null && _settings.Open) _settings.Open = false;
|
||||
if (_devTime > 2.5 && _capture == null && DevShot.Full && !_shots.Contains("i_intro")) { _shots.Add("i_intro"); _menu = null; _intro = new IntroScene(); return; }
|
||||
if (_devTime > 2.6 && _capture == null && _menu != null) { _menu.Picked = MenuScene.Choice.New; _devTime = 0; }
|
||||
}
|
||||
|
||||
/// --model3d im Testlauf: Ansichten (vorn, schräg, Seite) und je ein Bild pro Bewegung.
|
||||
int _mStep; double _mWait; bool _mArmed;
|
||||
void DevModel(float dt)
|
||||
{
|
||||
var m = _model!;
|
||||
if (m.Model == null) { DevShot.Log("model3d: no model"); Exit(); return; }
|
||||
if (_capture != null) return;
|
||||
var clips = m.Model.Clips;
|
||||
if (_mStep >= 3 + clips.Count)
|
||||
{
|
||||
DevShot.Log($"model3d: {clips.Count} clips, {m.Model.BoneCount} bones, {m.Model.Vertices.Length} vertices, {m.Model.Indices.Length / 3} triangles, draw {_drawMs / Math.Max(1, _frames):0.00} ms/frame");
|
||||
Exit(); return;
|
||||
}
|
||||
if (!_mArmed)
|
||||
{
|
||||
m.Paused = true;
|
||||
if (_mStep < 3) { m.SetView(_mStep); m.Color = _mStep == 2 ? 1 : -1; m.Play(clips.FindIndex(c => c.Name == "idle")); m.Time = 1f; }
|
||||
else { int i = _mStep - 3; m.SetView(1); m.Color = -1; m.Play(i); m.Time = clips[i].Length * 0.45f; }
|
||||
_mArmed = true; _mWait = 0.35; return;
|
||||
}
|
||||
if ((_mWait -= dt) > 0) return;
|
||||
_capture = _mStep < 3 ? $"m3_view{_mStep}" : $"m3_{_mStep - 2:00}_{clips[_mStep - 3].Name}";
|
||||
_mStep++; _mArmed = false;
|
||||
}
|
||||
|
||||
/// Testlauf: Erstellung aufnehmen (Grundeinstellung, dann eine eigene Zusammenstellung).
|
||||
void DevCreator(float dt)
|
||||
{
|
||||
_devTime += dt;
|
||||
void Shot(string name) { if (_shots.Add(name)) _capture = name; }
|
||||
if (_devTime > 1.0) Shot("c_creator");
|
||||
if (_devTime > 1.6 && !_shots.Contains("c_pick")) { _shots.Add("c_pick"); _creator!.DevPick(DevShot.Class, int.TryParse(Environment.GetEnvironmentVariable("GI_PRESET"), out int pr) ? pr : 1, 1, 2); }
|
||||
if (_devTime > 2.6) Shot("c_custom");
|
||||
if (_devTime > 3.2 && _capture == null) { _creator!.Finish(); _devTime = 0; }
|
||||
}
|
||||
|
||||
/// Testlauf: Arena aufnehmen, Schubladen öffnen, Gegner wählen; nach dem Kampf Ergebnis, Pause, dann Ende.
|
||||
void DevHub(float dt)
|
||||
{
|
||||
_devTime += dt;
|
||||
void Shot(string name) { if (_shots.Add(name)) _capture = name; }
|
||||
if (!_shots.Contains("m_end"))
|
||||
{
|
||||
if (_devTime > 1.0) Shot("h_hub");
|
||||
if (_devTime > 1.5 && !_shots.Contains("h_pick")) { _shots.Add("h_pick"); _hub!.DevOpen(1); }
|
||||
if (_devTime > 2.2) Shot("h_gladiator");
|
||||
if (_devTime > 2.6 && !_shots.Contains("h_ludus_open")) { _shots.Add("h_ludus_open"); _hub!.DevOpen(2); }
|
||||
if (_devTime > 3.3) Shot("h_ludus");
|
||||
if (_devTime > 3.5 && !_shots.Contains("h_forum_open")) { _shots.Add("h_forum_open"); _hub!.DevOpen(3); }
|
||||
if (_devTime > 4.2) Shot("h_forum");
|
||||
if (_devTime > 4.4 && !_shots.Contains("h_skills_open")) { _shots.Add("h_skills_open"); _hub!.DevOpen(4); }
|
||||
if (_devTime > 5.1) Shot("h_skills");
|
||||
if (_devTime > 5.5 && _capture == null) { _hub!.DevOpen(0); var offers = _game!.Offers(); _hub.Chosen = offers[Math.Min(1, offers.Count - 1)]; _devTime = 0; }
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_devTime > 0.6) Shot("h_result");
|
||||
if (_devTime > 0.8 && !_shots.Contains("h_inv_open")) { _shots.Add("h_inv_open"); _hub!.DevOpen(1); }
|
||||
if (_devTime > 1.4) Shot("h_inventory");
|
||||
if (_devTime > 1.6 && !_shots.Contains("h_pause_open")) { _shots.Add("h_pause_open"); _hub!.DevOpen(0); _paused = true; }
|
||||
if (_devTime > 2.0) Shot("h_pause");
|
||||
if (_shots.Contains("h_pause") && _capture == null && _devTime > 2.2)
|
||||
{
|
||||
DevShot.Log($"after duel: arena={_game!.Arena} rank={_game.Rank} gold={_game.Gold:0} fame={_game.FameRun:0} wins={_game.Wins} " +
|
||||
$"draw hub {_hubDraw / Math.Max(1, _hubFrames):0.00} ms, duel {_duelDraw / Math.Max(1, _duelFrames):0.00} ms at {GraphicsDevice.PresentationParameters.BackBufferWidth}x{GraphicsDevice.PresentationParameters.BackBufferHeight}");
|
||||
Exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Testlauf: Bot kämpft; Aufnahmen an markanten Stellen.
|
||||
void DevSteps(float dt)
|
||||
{
|
||||
_devTime += dt;
|
||||
var d = _scene!.Duel;
|
||||
if (Perf) { PerfStep(); return; }
|
||||
void Shot(string name) { if (_shots.Add(name)) _capture = name; }
|
||||
if (_devTime > 0.5) Shot("m_countdown");
|
||||
if (d.Time > 0.6) Shot("m_fight");
|
||||
if (d.Enemy.State == DuelState.Windup && d.Enemy.StateTime > d.Enemy.Windup * 0.6) Shot("m_telegraph");
|
||||
if (d.Player.State == DuelState.Strike) Shot("m_strike");
|
||||
// --record: Bildserie eines ganzen Schlags (Ausholen bis Erholung), für die Prüfung der Animation
|
||||
if (Record && _rec < 0 && d.Player.State == DuelState.Windup && d.Time > 2) _rec = 0;
|
||||
if (_rec >= 0 && _rec < 48 && _capture == null) { _capture = $"rec_{_rec:D2}"; _rec++; }
|
||||
if (d.Player.State == DuelState.Leap && d.Player.StateTime > 0.3) Shot("m_leap");
|
||||
if (d.Player.State == DuelState.Leap && d.Player.StateTime > 0.52) Shot("m_leap_hit");
|
||||
if (d.Player.State == DuelState.Super && d.Player.StateTime > 0.35) Shot("m_super_charge");
|
||||
if (d.Player.State == DuelState.Super && d.Player.StateTime > 1.22) Shot("m_super_hit");
|
||||
if (d.Player.Rage >= 100) Shot("m_rage_full");
|
||||
if (d.Enemy.State == DuelState.Hit && d.Enemy.StateTime < 0.03) Shot("m_hit");
|
||||
if (d.Player.State == DuelState.Block && d.Player.StateTime > 0.1) Shot("m_block");
|
||||
if (d.Player.State == DuelState.Hit && d.Player.StateTime < 0.03) Shot("m_hurt");
|
||||
if (_scene.Over && !_shots.Contains("m_ko")) Shot("m_ko");
|
||||
if (_scene.Finished) Shot("m_end");
|
||||
if (_shots.Contains("m_end") && _capture == null && !_shots.Contains("m_logged"))
|
||||
{
|
||||
_shots.Add("m_logged");
|
||||
DevShot.Log($"duel done: won={_scene.Won} time={d.Time:0.0}s");
|
||||
_devTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// --perf: 15 s Kampf ohne Aufnahmen, Bildzeiten messen (Mittel, 95. Perzentil).
|
||||
static readonly bool Perf = Array.IndexOf(Environment.GetCommandLineArgs(), "--perf") >= 0;
|
||||
static readonly bool Record = Array.IndexOf(Environment.GetCommandLineArgs(), "--record") >= 0;
|
||||
readonly System.Collections.Generic.List<double> _times = new();
|
||||
|
||||
void PerfStep()
|
||||
{
|
||||
if (_devTime > 3) _times.Add(_lastFrameMs);
|
||||
if (_scene!.Over) { var o = _offer!; EndDuel(); StartDuel(o); }
|
||||
if (_devTime < 18) return;
|
||||
_times.Sort();
|
||||
double avg = 0; foreach (var t in _times) avg += t; avg /= Math.Max(1, _times.Count);
|
||||
DevShot.Log($"perf {GraphicsDevice.PresentationParameters.BackBufferWidth}x{GraphicsDevice.PresentationParameters.BackBufferHeight}: " +
|
||||
$"avg {avg:0.0} ms ({1000 / avg:0} fps), p95 {_times[(int)(_times.Count * 0.95)]:0.0} ms, frames {_times.Count}");
|
||||
Exit();
|
||||
}
|
||||
|
||||
double _lastFrameMs;
|
||||
|
||||
// ── Zeichnen ────────────────────────────────────────────────
|
||||
|
||||
protected override void Draw(GameTime gameTime)
|
||||
{
|
||||
_drawWatch.Restart();
|
||||
bool capturing = _capture != null;
|
||||
var gd = GraphicsDevice;
|
||||
int w = gd.PresentationParameters.BackBufferWidth, h = gd.PresentationParameters.BackBufferHeight;
|
||||
bool toTarget = _capture != null && DevShot.Dir != null; // nur für Aufnahmen über ein Zwischenbild
|
||||
if (toTarget && (_rt == null || _rt.Width != w || _rt.Height != h))
|
||||
{
|
||||
_rt?.Dispose();
|
||||
_rt = new RenderTarget2D(gd, w, h, false, SurfaceFormat.Color, DepthFormat.Depth24);
|
||||
}
|
||||
if (toTarget) gd.SetRenderTarget(_rt);
|
||||
gd.Clear(Color.Black);
|
||||
float scale = Math.Min(w / Camera.W, h / Camera.H);
|
||||
var offset = new Vector2((w - Camera.W * scale) / 2, (h - Camera.H * scale) / 2);
|
||||
var ui = Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0);
|
||||
Gfx.Draw.UiScale = scale;
|
||||
if (_model != null) _model.Draw(gd, _sb, scale, offset);
|
||||
else if (_intro != null) _intro.Draw(_sb, scale, offset);
|
||||
else if (_menu != null) _menu.Draw(_sb, scale, offset);
|
||||
else if (_creator != null) _creator.Draw(gd, _sb, _fx, scale, offset);
|
||||
else if (_scene != null) _scene.Draw(gd, _sb, _fx, scale, offset);
|
||||
else if (_hub != null)
|
||||
{
|
||||
_hub.Draw(gd, _sb, _fx, scale, offset);
|
||||
if (_paused && !_settings.Open) DrawPause(_sb, ui);
|
||||
}
|
||||
if (_settings.Open) _settings.Draw(_sb, scale, offset);
|
||||
|
||||
if (toTarget)
|
||||
{
|
||||
gd.SetRenderTarget(null);
|
||||
if (_capture != null && DevShot.Dir != null)
|
||||
{
|
||||
using (var fs = File.Create(Path.Combine(DevShot.Dir, _capture + ".png"))) _rt!.SaveAsPng(fs, w, h);
|
||||
_capture = null;
|
||||
}
|
||||
_sb.Begin();
|
||||
_sb.Draw(_rt, Vector2.Zero, Color.White);
|
||||
_sb.End();
|
||||
}
|
||||
_drawMs += _drawWatch.Elapsed.TotalMilliseconds; _frames++;
|
||||
if (capturing) { } // Bilder mit Aufnahme (PNG speichern) nicht mitzählen
|
||||
else if (_scene != null) { _duelDraw += _drawWatch.Elapsed.TotalMilliseconds; _duelFrames++; }
|
||||
else if (_hub != null) { _hubDraw += _drawWatch.Elapsed.TotalMilliseconds; _hubFrames++; }
|
||||
_frameSum += gameTime.ElapsedGameTime.TotalMilliseconds;
|
||||
_lastFrameMs = gameTime.ElapsedGameTime.TotalMilliseconds;
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
210
Mono/Gfx/Assets.cs
Normal file
210
Mono/Gfx/Assets.cs
Normal file
@@ -0,0 +1,210 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FontStashSharp;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace GladiatorIdle.Gfx
|
||||
{
|
||||
/// <summary>
|
||||
/// Bilder, Clips und Schriften zur Laufzeit: Texturen aus Assets/Sprites bzw. Assets/Video
|
||||
/// (von der Platte, vormultipliziertes Alpha), Schriften als TTF aus dem System.
|
||||
/// </summary>
|
||||
internal static class Assets
|
||||
{
|
||||
static GraphicsDevice _gd = null!;
|
||||
public static GraphicsDevice Device => _gd;
|
||||
static readonly Dictionary<string, Texture2D?> _tex = new();
|
||||
static readonly Dictionary<Texture2D, Texture2D> _white = new();
|
||||
static string? _root;
|
||||
|
||||
public static Texture2D Pixel { get; private set; } = null!;
|
||||
/// Weicher Kreis (Licht, Staub, Schatten), 128 px.
|
||||
public static Texture2D Soft { get; private set; } = null!;
|
||||
/// Scharfer Kreis mit geglättetem Rand (Farbfelder, Knöpfe), 128 px.
|
||||
public static Texture2D Disc { get; private set; } = null!;
|
||||
|
||||
public static FontSystem Serif { get; private set; } = null!;
|
||||
public static FontSystem Sans { get; private set; } = null!;
|
||||
public static FontSystem SansBold { get; private set; } = null!;
|
||||
|
||||
public static void Init(GraphicsDevice gd)
|
||||
{
|
||||
_gd = gd;
|
||||
Pixel = new Texture2D(gd, 1, 1);
|
||||
Pixel.SetData(new[] { Color.White });
|
||||
const int S = 128;
|
||||
var soft = new Color[S * S];
|
||||
for (int y = 0; y < S; y++)
|
||||
for (int x = 0; x < S; x++)
|
||||
{
|
||||
float dx = (x + 0.5f) / S * 2 - 1, dy = (y + 0.5f) / S * 2 - 1;
|
||||
float a = MathHelper.Clamp(1 - MathF.Sqrt(dx * dx + dy * dy), 0, 1);
|
||||
a = a * a * (3 - 2 * a);
|
||||
soft[y * S + x] = new Color(a, a, a, a);
|
||||
}
|
||||
Soft = new Texture2D(gd, S, S);
|
||||
Soft.SetData(soft);
|
||||
var disc = new Color[S * S];
|
||||
for (int y = 0; y < S; y++)
|
||||
for (int x = 0; x < S; x++)
|
||||
{
|
||||
float dx = x + 0.5f - S / 2f, dy = y + 0.5f - S / 2f;
|
||||
float a = MathHelper.Clamp(S / 2f - 1 - MathF.Sqrt(dx * dx + dy * dy), 0, 1);
|
||||
disc[y * S + x] = new Color(a, a, a, a);
|
||||
}
|
||||
Disc = new Texture2D(gd, S, S);
|
||||
Disc.SetData(disc);
|
||||
|
||||
string fonts = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Fonts");
|
||||
Serif = Font(fonts, "georgiab.ttf");
|
||||
Sans = Font(fonts, "segoeui.ttf");
|
||||
SansBold = Font(fonts, "segoeuib.ttf");
|
||||
}
|
||||
|
||||
static FontSystem Font(string dir, string file)
|
||||
{
|
||||
var fs = new FontSystem(new FontSystemSettings { FontResolutionFactor = 1, KernelWidth = 1, KernelHeight = 1 });
|
||||
fs.AddFont(File.ReadAllBytes(Path.Combine(dir, file)));
|
||||
return fs;
|
||||
}
|
||||
|
||||
static string? Root => _root ??= FindRoot();
|
||||
|
||||
/// Assets-Ordner (null, wenn nicht gefunden).
|
||||
public static string? RootDir => Root;
|
||||
|
||||
static string? FindRoot()
|
||||
{
|
||||
var dir = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
while (dir != null)
|
||||
{
|
||||
if (Directory.Exists(Path.Combine(dir.FullName, "Assets", "Sprites"))) return Path.Combine(dir.FullName, "Assets");
|
||||
dir = dir.Parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Bild aus Assets/Sprites (null, wenn es fehlt).
|
||||
public static Texture2D? Sprite(string name, string ext = "png") => Load($"Sprites/{name}.{ext}");
|
||||
|
||||
public static Texture2D? Load(string rel)
|
||||
{
|
||||
if (_tex.TryGetValue(rel, out var t)) return t;
|
||||
Texture2D? result = null;
|
||||
if (Root is string root && File.Exists(Path.Combine(root, rel)))
|
||||
using (var fs = File.OpenRead(Path.Combine(root, rel)))
|
||||
result = Texture2D.FromStream(_gd, fs, DefaultColorProcessors.PremultiplyAlpha);
|
||||
_tex[rel] = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Bild eines Video-Sprites: Farbe vor Schwarz (JPEG, also schon vormultipliziert)
|
||||
/// plus Deckkraft (Graustufen-PNG) — zusammengesetzt zu einer Textur.
|
||||
public static Texture2D? LoadFrame(string relBase)
|
||||
{
|
||||
if (Root is not string root) return null;
|
||||
string jpg = Path.Combine(root, relBase + ".jpg"), mask = Path.Combine(root, relBase + "_a.png");
|
||||
if (!File.Exists(jpg) || !File.Exists(mask)) return null;
|
||||
Texture2D color, alpha;
|
||||
using (var fs = File.OpenRead(jpg)) color = Texture2D.FromStream(_gd, fs);
|
||||
using (var fs = File.OpenRead(mask)) alpha = Texture2D.FromStream(_gd, fs);
|
||||
var c = new Color[color.Width * color.Height];
|
||||
var a = new Color[alpha.Width * alpha.Height];
|
||||
color.GetData(c); alpha.GetData(a);
|
||||
for (int i = 0; i < c.Length && i < a.Length; i++) c[i].A = a[i].R;
|
||||
color.SetData(c);
|
||||
alpha.Dispose();
|
||||
return color;
|
||||
}
|
||||
|
||||
/// Textdatei aus Assets (z. B. Clip-Angaben), null wenn sie fehlt.
|
||||
public static string? ReadText(string rel) =>
|
||||
Root is string root && File.Exists(Path.Combine(root, rel)) ? File.ReadAllText(Path.Combine(root, rel)) : null;
|
||||
|
||||
/// Frames eines Wan-Clips (Assets/Video/<name>_NN.jpg).
|
||||
public static List<Texture2D> Clip(string name)
|
||||
{
|
||||
var list = new List<Texture2D>();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
var t = Load($"Video/{name}_{i:D2}.jpg");
|
||||
if (t == null) break;
|
||||
list.Add(t);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// Weiße Silhouette einer Textur (Treffer-Blitz, Leuchten), einmal erzeugt.
|
||||
public static Texture2D White(Texture2D src)
|
||||
{
|
||||
if (_white.TryGetValue(src, out var w)) return w;
|
||||
var data = new Color[src.Width * src.Height];
|
||||
src.GetData(data);
|
||||
for (int i = 0; i < data.Length; i++) { byte a = data[i].A; data[i] = new Color(a, a, a, a); }
|
||||
w = new Texture2D(_gd, src.Width, src.Height);
|
||||
w.SetData(data);
|
||||
_white[src] = w;
|
||||
return w;
|
||||
}
|
||||
|
||||
static readonly Dictionary<(Texture2D, int), Texture2D> _painted = new();
|
||||
|
||||
/// Teamfarbe: Magenta-Flächen (Stoff, Federbusch, Schildbemalung) in die gewählte Farbe,
|
||||
/// Schattierung bleibt; weiche Übergänge am Rand der Flächen. Einmal je Bild und Farbe.
|
||||
public static Texture2D Paint(Texture2D src, int colorIndex)
|
||||
{
|
||||
if (_painted.TryGetValue((src, colorIndex), out var t)) return t;
|
||||
var data = new Color[src.Width * src.Height];
|
||||
src.GetData(data);
|
||||
PaintPixels(data, colorIndex);
|
||||
t = new Texture2D(_gd, src.Width, src.Height);
|
||||
t.SetData(data);
|
||||
_painted[(src, colorIndex)] = t;
|
||||
return t;
|
||||
}
|
||||
|
||||
/// Umfärben auf Pixeldaten (vormultipliziert) — auch im Hintergrund nutzbar.
|
||||
public static void PaintPixels(Color[] data, int colorIndex)
|
||||
{
|
||||
var c = Appearance.Colors[colorIndex];
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
var px = data[i];
|
||||
if (px.A == 0) continue;
|
||||
float a = px.A / 255f, r = px.R / 255f / a, g = px.G / 255f / a, b = px.B / 255f / a;
|
||||
float max = MathF.Max(r, MathF.Max(g, b)), min = MathF.Min(r, MathF.Min(g, b)), d = max - min;
|
||||
if (max <= 0.08f || d <= 0.001f) continue;
|
||||
float s = d / max;
|
||||
float h = max == r ? 60 * (((g - b) / d) % 6) : max == g ? 60 * ((b - r) / d + 2) : 60 * ((r - g) / d + 4);
|
||||
if (h < 0) h += 360;
|
||||
float dist = MathF.Abs(h - 312);
|
||||
float w = Smooth(48, 30, dist) * Smooth(0.18f, 0.32f, s);
|
||||
if (w <= 0) continue;
|
||||
var (nr, ng, nb) = Hsv(c.Hue, MathHelper.Clamp(s * c.Sat, 0, 1), MathHelper.Clamp(max * c.Val, 0, 1));
|
||||
r += (nr - r) * w; g += (ng - g) * w; b += (nb - b) * w;
|
||||
data[i] = new Color(r * a, g * a, b * a, a);
|
||||
}
|
||||
}
|
||||
|
||||
/// 0 bei <paramref name="from"/>, 1 bei <paramref name="to"/> (auch absteigend), weich dazwischen.
|
||||
static float Smooth(float from, float to, float x)
|
||||
{
|
||||
float k = MathHelper.Clamp((x - from) / (to - from), 0, 1);
|
||||
return k * k * (3 - 2 * k);
|
||||
}
|
||||
|
||||
static (float, float, float) Hsv(float h, float s, float v)
|
||||
{
|
||||
float c = v * s, x = c * (1 - MathF.Abs(h / 60 % 2 - 1)), m = v - c;
|
||||
var (r, g, b) = h < 60 ? (c, x, 0f) : h < 120 ? (x, c, 0f) : h < 180 ? (0f, c, x) : h < 240 ? (0f, x, c) : h < 300 ? (x, 0f, c) : (c, 0f, x);
|
||||
return (r + m, g + m, b + m);
|
||||
}
|
||||
|
||||
public static bool Has(string name) => Sprite(name) != null;
|
||||
|
||||
public static IEnumerable<string> Existing(IEnumerable<string> names) => names.Where(Has);
|
||||
}
|
||||
}
|
||||
196
Mono/Gfx/ClipCache.cs
Normal file
196
Mono/Gfx/ClipCache.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using StbImageSharp;
|
||||
|
||||
namespace GladiatorIdle.Gfx
|
||||
{
|
||||
/// <summary>
|
||||
/// Video-Sprites, einmal je Sitzung geladen und von allen Szenen geteilt. Entpacken und
|
||||
/// Umfärben laufen im Hintergrund (höchstens zwei Clips gleichzeitig); <see cref="Pump"/>
|
||||
/// schiebt die fertigen Bilder mit festem Zeitbudget pro Bild auf die Grafikkarte — das Spiel
|
||||
/// steht dabei nie. Bis ein Clip bereit ist, liefert <see cref="Get"/> null (dann Posen).
|
||||
/// </summary>
|
||||
internal static class ClipCache
|
||||
{
|
||||
public sealed class Clip
|
||||
{
|
||||
public Texture2D[] Frames = Array.Empty<Texture2D>();
|
||||
public int Impact;
|
||||
public int Last => Frames.Length - 1;
|
||||
}
|
||||
|
||||
sealed class Job
|
||||
{
|
||||
public Color[][]? Pixels;
|
||||
public int W, H, Impact, Uploaded;
|
||||
public int FullW, FullH, X0, Y0; // Zuschnitt in der vollen Leinwand
|
||||
public Texture2D[]? Textures;
|
||||
public volatile bool Decoded;
|
||||
public bool Missing, Ready;
|
||||
public Clip? Clip;
|
||||
}
|
||||
|
||||
static readonly Dictionary<string, Job> _jobs = new();
|
||||
static readonly Dictionary<Texture2D, (Vector4 Crop, float Aspect)> _crops = new();
|
||||
|
||||
/// Zugeschnittenes Clip-Bild: Lage (x, y, Breite, Höhe; 0..1) in der vollen Leinwand und deren Seitenverhältnis.
|
||||
public static (Vector4, float)? CropOf(Texture2D t) => _crops.TryGetValue(t, out var c) ? c : null;
|
||||
static readonly SemaphoreSlim _workers = new(2);
|
||||
static readonly Regex ImpactRx = new("\"impact\":\\s*(\\d+)");
|
||||
|
||||
/// Clip der Figur <paramref name="art"/> für die Aktion (null = fehlt oder lädt noch).
|
||||
public static Clip? Get(string art, string action, int color)
|
||||
{
|
||||
string key = $"{art}|{action}|{color}";
|
||||
if (!_jobs.TryGetValue(key, out var job))
|
||||
{
|
||||
job = new Job();
|
||||
_jobs[key] = job;
|
||||
string? dir = Assets.RootDir is string root ? Path.Combine(root, "Sprites", "anim") : null;
|
||||
if (dir == null || !File.Exists(Path.Combine(dir, $"{art}_{action}_00.jpg"))) job.Missing = true;
|
||||
else Task.Run(() => Decode(job, dir, art, action, color));
|
||||
}
|
||||
return job.Ready ? job.Clip : null;
|
||||
}
|
||||
|
||||
/// Wan-Clip aus Assets/Video (<name>_NN.jpg, ohne Transparenz), im Hintergrund geladen.
|
||||
public static Texture2D[]? Video(string name)
|
||||
{
|
||||
string key = "video|" + name;
|
||||
if (!_jobs.TryGetValue(key, out var job))
|
||||
{
|
||||
job = new Job();
|
||||
_jobs[key] = job;
|
||||
string? dir = Assets.RootDir is string root ? Path.Combine(root, "Video") : null;
|
||||
if (dir == null || !File.Exists(Path.Combine(dir, $"{name}_00.jpg"))) job.Missing = true;
|
||||
else Task.Run(() => DecodeVideo(job, dir, name));
|
||||
}
|
||||
return job.Ready ? job.Clip!.Frames : null;
|
||||
}
|
||||
|
||||
static void DecodeVideo(Job job, string dir, string name)
|
||||
{
|
||||
_workers.Wait();
|
||||
try
|
||||
{
|
||||
var frames = new List<Color[]>();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
string p = Path.Combine(dir, $"{name}_{i:D2}.jpg");
|
||||
if (!File.Exists(p)) break;
|
||||
var rgb = ImageResult.FromMemory(File.ReadAllBytes(p), ColorComponents.RedGreenBlue);
|
||||
var px = new Color[rgb.Width * rgb.Height];
|
||||
for (int k = 0; k < px.Length; k++) px[k] = new Color(rgb.Data[k * 3], rgb.Data[k * 3 + 1], rgb.Data[k * 3 + 2], (byte)255);
|
||||
frames.Add(px);
|
||||
job.W = rgb.Width; job.H = rgb.Height;
|
||||
}
|
||||
job.Pixels = frames.ToArray();
|
||||
job.Missing = frames.Count < 2;
|
||||
}
|
||||
catch (Exception ex) { job.Missing = true; DevShot.Log("video load failed " + name + ": " + ex.Message); }
|
||||
finally { job.Decoded = true; _workers.Release(); }
|
||||
}
|
||||
|
||||
/// Nur nachsehen, ob es den Clip gibt (ohne Laden).
|
||||
public static bool Exists(string art, string action) =>
|
||||
Assets.RootDir is string root && File.Exists(Path.Combine(root, "Sprites", "anim", $"{art}_{action}_00.jpg"));
|
||||
|
||||
static void Decode(Job job, string dir, string art, string action, int color)
|
||||
{
|
||||
_workers.Wait();
|
||||
try
|
||||
{
|
||||
var frames = new List<Color[]>();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
string b = Path.Combine(dir, $"{art}_{action}_{i:D2}");
|
||||
if (!File.Exists(b + ".jpg") || !File.Exists(b + "_a.png")) break;
|
||||
var rgb = ImageResult.FromMemory(File.ReadAllBytes(b + ".jpg"), ColorComponents.RedGreenBlue);
|
||||
var mask = ImageResult.FromMemory(File.ReadAllBytes(b + "_a.png"), ColorComponents.Grey);
|
||||
var px = new Color[rgb.Width * rgb.Height];
|
||||
int n = Math.Min(px.Length, mask.Data.Length);
|
||||
// Farbe liegt vor Schwarz (schon vormultipliziert), Deckkraft aus der Maske
|
||||
for (int k = 0; k < n; k++)
|
||||
px[k] = new Color(rgb.Data[k * 3], rgb.Data[k * 3 + 1], rgb.Data[k * 3 + 2], mask.Data[k]);
|
||||
if (color >= 0) Assets.PaintPixels(px, color);
|
||||
frames.Add(px);
|
||||
job.W = rgb.Width; job.H = rgb.Height;
|
||||
}
|
||||
Crop(job, frames);
|
||||
job.Impact = Math.Max(3, frames.Count / 3);
|
||||
string meta = Path.Combine(dir, $"{art}_{action}.json");
|
||||
if (File.Exists(meta) && ImpactRx.Match(File.ReadAllText(meta)) is { Success: true } m)
|
||||
job.Impact = Math.Clamp(int.Parse(m.Groups[1].Value), 3, Math.Max(3, frames.Count - 1));
|
||||
job.Pixels = frames.ToArray();
|
||||
job.Missing = frames.Count < 2;
|
||||
}
|
||||
catch (Exception ex) { job.Missing = true; DevShot.Log("clip load failed " + art + " " + action + ": " + ex.Message); }
|
||||
finally
|
||||
{
|
||||
job.Decoded = true;
|
||||
_workers.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// Auf den Bereich zuschneiden, den die Figur in irgendeinem Bild des Clips berührt (+ Rand).
|
||||
static void Crop(Job job, List<Color[]> frames)
|
||||
{
|
||||
int w = job.W, h = job.H, x0 = w, y0 = h, x1 = -1, y1 = -1;
|
||||
foreach (var px in frames)
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
int row = y * w;
|
||||
for (int x = 0; x < w; x++)
|
||||
if (px[row + x].A > 8)
|
||||
{
|
||||
if (x < x0) x0 = x; if (x > x1) x1 = x;
|
||||
if (y < y0) y0 = y; if (y > y1) y1 = y;
|
||||
}
|
||||
}
|
||||
if (x1 < 0) return;
|
||||
const int PAD = 4;
|
||||
x0 = Math.Max(0, x0 - PAD); y0 = Math.Max(0, y0 - PAD);
|
||||
x1 = Math.Min(w - 1, x1 + PAD); y1 = Math.Min(h - 1, y1 + PAD);
|
||||
int cw = x1 - x0 + 1, ch = y1 - y0 + 1;
|
||||
for (int f = 0; f < frames.Count; f++)
|
||||
{
|
||||
var src = frames[f];
|
||||
var dst = new Color[cw * ch];
|
||||
for (int y = 0; y < ch; y++) Array.Copy(src, (y + y0) * w + x0, dst, y * cw, cw);
|
||||
frames[f] = dst;
|
||||
}
|
||||
job.FullW = w; job.FullH = h; job.X0 = x0; job.Y0 = y0; job.W = cw; job.H = ch;
|
||||
}
|
||||
|
||||
/// Fertig entpackte Bilder hochladen, bis das Zeitbudget verbraucht ist (Hauptthread).
|
||||
public static void Pump(GraphicsDevice gd, double budgetMs)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
foreach (var job in _jobs.Values)
|
||||
{
|
||||
if (job.Ready || job.Missing || !job.Decoded || job.Pixels == null) continue;
|
||||
job.Textures ??= new Texture2D[job.Pixels.Length];
|
||||
while (job.Uploaded < job.Pixels.Length)
|
||||
{
|
||||
var t = new Texture2D(gd, job.W, job.H);
|
||||
t.SetData(job.Pixels[job.Uploaded]);
|
||||
if (job.FullW > 0)
|
||||
_crops[t] = (new Vector4((float)job.X0 / job.FullW, (float)job.Y0 / job.FullH,
|
||||
(float)job.W / job.FullW, (float)job.H / job.FullH), (float)job.FullW / job.FullH);
|
||||
job.Textures[job.Uploaded++] = t;
|
||||
if (sw.Elapsed.TotalMilliseconds > budgetMs) return;
|
||||
}
|
||||
job.Clip = new Clip { Frames = job.Textures, Impact = job.Impact };
|
||||
job.Pixels = null; // Speicher frei
|
||||
job.Ready = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
78
Mono/Gfx/Draw.cs
Normal file
78
Mono/Gfx/Draw.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using FontStashSharp;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace GladiatorIdle.Gfx
|
||||
{
|
||||
internal enum Align { Left, Center, Right }
|
||||
|
||||
/// <summary>
|
||||
/// Zeichenhilfen in Design-Pixeln (1920×1080). Schrift wird in Bildschirmgröße gerastert
|
||||
/// (<see cref="UiScale"/>) und verkleinert gezeichnet — scharf auch in 4K.
|
||||
/// </summary>
|
||||
internal static class Draw
|
||||
{
|
||||
public static float UiScale = 1f;
|
||||
|
||||
public static readonly Color Gold = new(236, 190, 84), Sand = new(222, 196, 150), Dim = new(150, 128, 98),
|
||||
Red = new(200, 64, 52), Green = new(110, 190, 90), Blue = new(110, 160, 220), Purple = new(170, 130, 220),
|
||||
Panel = new(24, 18, 12), Border = new(110, 82, 46);
|
||||
|
||||
public static Color A(Color c, float alpha) => c * MathHelper.Clamp(alpha, 0, 1);
|
||||
|
||||
public static void Rect(SpriteBatch sb, RectangleF r, Color c) =>
|
||||
sb.Draw(Assets.Pixel, new Vector2(r.X, r.Y), null, c, 0, Vector2.Zero, new Vector2(r.Width, r.Height), SpriteEffects.None, 0);
|
||||
|
||||
public static void Frame(SpriteBatch sb, RectangleF r, Color c, float t = 2)
|
||||
{
|
||||
Rect(sb, new RectangleF(r.X, r.Y, r.Width, t), c);
|
||||
Rect(sb, new RectangleF(r.X, r.Bottom - t, r.Width, t), c);
|
||||
Rect(sb, new RectangleF(r.X, r.Y, t, r.Height), c);
|
||||
Rect(sb, new RectangleF(r.Right - t, r.Y, t, r.Height), c);
|
||||
}
|
||||
|
||||
public static void Glow(SpriteBatch sb, Vector2 center, Vector2 size, Color c) =>
|
||||
sb.Draw(Assets.Soft, center, null, c, 0, new Vector2(64, 64), size / 128f, SpriteEffects.None, 0);
|
||||
|
||||
public static Vector2 Measure(FontSystem fs, float px, string text) =>
|
||||
fs.GetFont(px * UiScale).MeasureString(text) / UiScale;
|
||||
|
||||
/// Text an <paramref name="pos"/> (y = Mitte der Zeile), mit weichem Schatten.
|
||||
public static void Text(SpriteBatch sb, FontSystem fs, float px, string text, Vector2 pos, Color c,
|
||||
Align align = Align.Left, float scale = 1f, bool shadow = true)
|
||||
{
|
||||
// feste Rastergröße (ganze Pixel), Animation nur über die Zeichen-Skalierung —
|
||||
// sonst entstehen jedes Bild neue Glyphen
|
||||
var font = fs.GetFont(MathF.Max(4, MathF.Round(px * UiScale)));
|
||||
var size = font.MeasureString(text) / UiScale * scale;
|
||||
float x = align switch { Align.Center => pos.X - size.X / 2, Align.Right => pos.X - size.X, _ => pos.X };
|
||||
var p = new Vector2(x, pos.Y - size.Y / 2);
|
||||
var s = new Vector2(scale / UiScale);
|
||||
if (shadow) font.DrawText(sb, text, p + new Vector2(2, 3) * scale, Color.Black * (c.A / 255f * 0.6f), scale: s);
|
||||
font.DrawText(sb, text, p, c, scale: s);
|
||||
}
|
||||
|
||||
/// Balken mit verzögertem Rest (weißer Abschnitt zeigt den gerade verlorenen Teil).
|
||||
public static void Bar(SpriteBatch sb, RectangleF r, float value, float lag, Color c, bool fromRight = false)
|
||||
{
|
||||
Rect(sb, r, new Color(12, 8, 5) * 0.85f);
|
||||
value = MathHelper.Clamp(value, 0, 1); lag = MathHelper.Clamp(lag, value, 1);
|
||||
RectangleF Part(float a, float b) => fromRight
|
||||
? new RectangleF(r.Right - 3 - (r.Width - 6) * b, r.Y + 3, (r.Width - 6) * (b - a), r.Height - 6)
|
||||
: new RectangleF(r.X + 3 + (r.Width - 6) * a, r.Y + 3, (r.Width - 6) * (b - a), r.Height - 6);
|
||||
Rect(sb, Part(value, lag), new Color(255, 240, 220));
|
||||
Rect(sb, Part(0, value), c);
|
||||
Rect(sb, new RectangleF(r.X + 3, r.Y + 3, r.Width - 6, (r.Height - 6) * 0.35f), Color.White * 0.12f);
|
||||
Frame(sb, r, Border);
|
||||
}
|
||||
}
|
||||
|
||||
internal readonly record struct RectangleF(float X, float Y, float Width, float Height)
|
||||
{
|
||||
public float Right => X + Width;
|
||||
public float Bottom => Y + Height;
|
||||
public Vector2 Center => new(X + Width / 2, Y + Height / 2);
|
||||
public bool Contains(Vector2 p) => p.X >= X && p.X < Right && p.Y >= Y && p.Y < Bottom;
|
||||
}
|
||||
}
|
||||
604
Mono/Gfx/Model3D.cs
Normal file
604
Mono/Gfx/Model3D.cs
Normal file
@@ -0,0 +1,604 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace GladiatorIdle.Gfx
|
||||
{
|
||||
/// Punkt mit Lage, Normale und Farbe (BasicEffect mit Licht und Punktfarben).
|
||||
internal struct VertexPNC : IVertexType
|
||||
{
|
||||
public Vector3 Position, Normal;
|
||||
public Color Color;
|
||||
public static readonly VertexDeclaration Decl = new(
|
||||
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
|
||||
new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
|
||||
new VertexElement(24, VertexElementFormat.Color, VertexElementUsage.Color, 0));
|
||||
VertexDeclaration IVertexType.VertexDeclaration => Decl;
|
||||
}
|
||||
|
||||
/// Wie <see cref="VertexPNC"/>, dazu Texturkoordinaten (Figuren mit Textur, z. B. aus Meshy).
|
||||
internal struct VertexPNCT : IVertexType
|
||||
{
|
||||
public Vector3 Position, Normal;
|
||||
public Color Color;
|
||||
public Vector2 Uv;
|
||||
public static readonly VertexDeclaration Decl = new(
|
||||
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
|
||||
new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
|
||||
new VertexElement(24, VertexElementFormat.Color, VertexElementUsage.Color, 0),
|
||||
new VertexElement(28, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0));
|
||||
VertexDeclaration IVertexType.VertexDeclaration => Decl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 3D-Figur mit Skelett aus einer .gim-Datei (fbx2gim aus _Tools/ModelTools: Mixamo-Figur +
|
||||
/// Bewegungen). Die Verformung rechnet der Prozessor (wenige zehntausend Punkte), Clips werden
|
||||
/// beim Wechsel kurz überblendet. Teamfarbe: Magenta-Punkte wie bei den Sprites umgefärbt.
|
||||
/// </summary>
|
||||
internal sealed class Model3D
|
||||
{
|
||||
public sealed class Clip { public string Name = ""; public float Fps; public int Frames; public float[] Data = null!; public float Length => (Frames - 1) / Fps; }
|
||||
|
||||
readonly string[] _names;
|
||||
readonly int[] _parent;
|
||||
readonly float[] _rest; // 10 je Knochen
|
||||
readonly Matrix[] _offset;
|
||||
readonly Vector3[] _pos, _nrm;
|
||||
readonly Color[] _baseCol;
|
||||
readonly byte[] _bi;
|
||||
readonly float[] _bw;
|
||||
public readonly int[] Indices;
|
||||
public readonly List<Clip> Clips = new();
|
||||
public readonly VertexPNCT[] Vertices;
|
||||
public BoundingBox Bounds { get; }
|
||||
readonly Texture2D? _texture;
|
||||
Texture2D? _painted;
|
||||
/// Maßstab: Modell-Einheiten je Zentimeter (Mixamo-Figuren gibt es in cm und in m).
|
||||
public readonly float Unit;
|
||||
|
||||
readonly float[] _pose, _from; // aktuelle und überblendete Haltung (10 je Knochen)
|
||||
readonly Matrix[] _global, _skin;
|
||||
int _color = -1;
|
||||
|
||||
public int BoneCount => _names.Length;
|
||||
|
||||
public static Model3D? Load(string name) => Load(Assets.Device, name);
|
||||
|
||||
public static Model3D? Load(GraphicsDevice gd, string name)
|
||||
{
|
||||
string? path = Assets.RootDir is string root ? Path.Combine(root, "Models", name + ".gim") : null;
|
||||
return path != null && File.Exists(path) ? new Model3D(gd, path) : null;
|
||||
}
|
||||
|
||||
Model3D(GraphicsDevice gd, string path)
|
||||
{
|
||||
using var r = new BinaryReader(File.OpenRead(path), Encoding.UTF8);
|
||||
string magic = Encoding.ASCII.GetString(r.ReadBytes(4));
|
||||
if (magic != "GIM1" && magic != "GIM2") throw new InvalidDataException(path);
|
||||
bool v2 = magic == "GIM2";
|
||||
var uv = new List<Vector2>();
|
||||
int nb = r.ReadInt32();
|
||||
_names = new string[nb]; _parent = new int[nb]; _rest = new float[nb * 10]; _offset = new Matrix[nb];
|
||||
for (int b = 0; b < nb; b++)
|
||||
{
|
||||
_names[b] = r.ReadString(); _parent[b] = r.ReadInt32();
|
||||
for (int k = 0; k < 10; k++) _rest[b * 10 + k] = r.ReadSingle();
|
||||
r.ReadByte();
|
||||
var m = new float[16];
|
||||
for (int k = 0; k < 16; k++) m[k] = r.ReadSingle();
|
||||
_offset[b] = new Matrix(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9], m[10], m[11], m[12], m[13], m[14], m[15]);
|
||||
}
|
||||
int nv = r.ReadInt32();
|
||||
_pos = new Vector3[nv]; _nrm = new Vector3[nv]; _baseCol = new Color[nv]; _bi = new byte[nv * 4]; _bw = new float[nv * 4];
|
||||
for (int i = 0; i < nv; i++)
|
||||
{
|
||||
_pos[i] = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
|
||||
_nrm[i] = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
|
||||
uv.Add(v2 ? new Vector2(r.ReadSingle(), r.ReadSingle()) : Vector2.Zero);
|
||||
var c = r.ReadBytes(4); _baseCol[i] = new Color(c[0], c[1], c[2], c[3]);
|
||||
r.Read(_bi, i * 4, 4);
|
||||
for (int k = 0; k < 4; k++) _bw[i * 4 + k] = r.ReadSingle();
|
||||
}
|
||||
Indices = new int[r.ReadInt32()];
|
||||
for (int i = 0; i < Indices.Length; i++) Indices[i] = r.ReadInt32();
|
||||
int nc = r.ReadInt32();
|
||||
for (int c = 0; c < nc; c++)
|
||||
{
|
||||
var clip = new Clip { Name = r.ReadString(), Fps = r.ReadSingle(), Frames = r.ReadInt32() };
|
||||
clip.Data = new float[clip.Frames * nb * 10];
|
||||
for (int k = 0; k < clip.Data.Length; k++) clip.Data[k] = r.ReadSingle();
|
||||
Clips.Add(clip);
|
||||
}
|
||||
if (v2 && r.ReadInt32() is int texLen && texLen > 0)
|
||||
using (var ms = new MemoryStream(r.ReadBytes(texLen))) _texture = Texture2D.FromStream(gd, ms);
|
||||
Vertices = new VertexPNCT[nv];
|
||||
for (int i = 0; i < nv; i++) Vertices[i] = new VertexPNCT { Position = _pos[i], Normal = _nrm[i], Color = _baseCol[i], Uv = uv[i] };
|
||||
Bounds = BoundingBox.CreateFromPoints(_pos);
|
||||
_pose = (float[])_rest.Clone(); _from = (float[])_rest.Clone();
|
||||
_global = new Matrix[nb]; _skin = new Matrix[nb];
|
||||
// Kopf bis Knöchel etwa 150 cm bei einer 180-cm-Figur
|
||||
int head = Bone("Head"), foot = Bone("LeftFoot");
|
||||
Unit = head >= 0 && foot >= 0 ? Vector3.Distance(BindGlobal(head).Translation, BindGlobal(foot).Translation) / 150f : 1f;
|
||||
}
|
||||
|
||||
public Clip? Find(string name) => Clips.Find(c => c.Name == name);
|
||||
|
||||
/// Teamfarbe (Index in Appearance.Colors), -1 = Originalfarben.
|
||||
public void SetColor(int index)
|
||||
{
|
||||
if (index == _color) return;
|
||||
_color = index;
|
||||
var cols = (Color[])_baseCol.Clone();
|
||||
if (index >= 0) Assets.PaintPixels(cols, index);
|
||||
for (int i = 0; i < cols.Length; i++) Vertices[i].Color = cols[i];
|
||||
_dirty = true;
|
||||
if (_texture != null) _painted = index >= 0 ? Assets.Paint(_texture, index) : _texture;
|
||||
foreach (var p in Props)
|
||||
{
|
||||
var pc = (Color[])p.Base.Clone();
|
||||
if (index >= 0) Assets.PaintPixels(pc, index);
|
||||
for (int i = 0; i < pc.Length; i++) p.V[i].Color = pc[i];
|
||||
}
|
||||
}
|
||||
|
||||
/// Überblendung beginnen: die jetzige Haltung wird zum Ausgangspunkt.
|
||||
public void BeginBlend() { if (_posed) Array.Copy(_pose, _from, _pose.Length); }
|
||||
bool _posed; // erst nach der ersten Haltung überblenden (die Ruhehaltung der Figurdatei kann andere Einheiten haben)
|
||||
|
||||
/// Haltung aus einem Clip zur Zeit t; blend 0..1 mischt von der gemerkten Haltung her.
|
||||
/// inPlace hält die Hüfte waagerecht am Platz (Laufen auf der Stelle).
|
||||
public void Pose(Clip clip, float t, bool loop, float blend = 1, bool inPlace = true, bool skin = true, float rootY = 1)
|
||||
{
|
||||
int nb = _names.Length;
|
||||
if (!_posed) { blend = 1; _posed = true; }
|
||||
float f = t * clip.Fps;
|
||||
f = loop ? f % (clip.Frames - 1) : Math.Min(f, clip.Frames - 1);
|
||||
if (f < 0) f += clip.Frames - 1;
|
||||
int a = (int)f, b = Math.Min(a + 1, clip.Frames - 1);
|
||||
float k = f - a;
|
||||
for (int bone = 0; bone < nb; bone++)
|
||||
{
|
||||
int pa = (a * nb + bone) * 10, pb = (b * nb + bone) * 10, o = bone * 10;
|
||||
var tr = Vector3.Lerp(V(clip.Data, pa), V(clip.Data, pb), k);
|
||||
var q = Quaternion.Slerp(Q(clip.Data, pa), Q(clip.Data, pb), k);
|
||||
if (inPlace && _parent[bone] < 0) { var r0 = V(clip.Data, bone * 10); tr.X = r0.X; tr.Z = r0.Z; tr.Y = r0.Y + (tr.Y - r0.Y) * rootY; } // rootY: Sprunghöhe
|
||||
if (blend < 1)
|
||||
{
|
||||
tr = Vector3.Lerp(V(_from, o), tr, blend);
|
||||
q = Quaternion.Slerp(Q(_from, o), q, blend);
|
||||
}
|
||||
_pose[o] = tr.X; _pose[o + 1] = tr.Y; _pose[o + 2] = tr.Z;
|
||||
_pose[o + 3] = q.X; _pose[o + 4] = q.Y; _pose[o + 5] = q.Z; _pose[o + 6] = q.W;
|
||||
_pose[o + 7] = clip.Data[pa + 7]; _pose[o + 8] = clip.Data[pa + 8]; _pose[o + 9] = clip.Data[pa + 9];
|
||||
}
|
||||
Bones();
|
||||
if (skin) { SkinVertices(); _dirty = true; AvoidBody(); }
|
||||
}
|
||||
|
||||
/// Trefferzeitpunkt eines Schlag-Clips: der Schwertarm am weitesten vorn (Blickrichtung +Z).
|
||||
public float ImpactTime(Clip clip)
|
||||
{
|
||||
if (_impact.TryGetValue(clip, out float t)) return t;
|
||||
var keep = (float[])_pose.Clone(); bool posed = _posed;
|
||||
int hand = Bone("RightHand");
|
||||
float best = float.MinValue; t = clip.Length * 0.5f;
|
||||
for (int f = 0; f < clip.Frames && hand >= 0; f++)
|
||||
{
|
||||
_posed = true;
|
||||
Pose(clip, f / clip.Fps, false, 1, true, skin: false);
|
||||
float z = _global[hand].Translation.Z;
|
||||
if (z > best) { best = z; t = f / clip.Fps; }
|
||||
}
|
||||
Array.Copy(keep, _pose, keep.Length); _posed = posed; Bones();
|
||||
return _impact[clip] = t;
|
||||
}
|
||||
readonly Dictionary<Clip, float> _impact = new();
|
||||
|
||||
/// Figur auf 180 Einheiten Höhe, Füße auf y = 0, mittig (aus der jetzigen Haltung, robust gegen Ausreißer).
|
||||
public Matrix FitNow()
|
||||
{
|
||||
float Q(Func<Vector3, float> axis, float q)
|
||||
{
|
||||
var a = Array.ConvertAll(Vertices, v => axis(v.Position));
|
||||
Array.Sort(a);
|
||||
return a[(int)(q * (a.Length - 1))];
|
||||
}
|
||||
float y0 = Q(p => p.Y, 0.002f), y1 = Q(p => p.Y, 0.998f);
|
||||
float cx = (Q(p => p.X, 0.01f) + Q(p => p.X, 0.99f)) / 2, cz = (Q(p => p.Z, 0.01f) + Q(p => p.Z, 0.99f)) / 2;
|
||||
return Matrix.CreateTranslation(-cx, -y0, -cz) * Matrix.CreateScale(180 / MathF.Max(1e-3f, y1 - y0));
|
||||
}
|
||||
|
||||
static Vector3 V(float[] d, int o) => new(d[o], d[o + 1], d[o + 2]);
|
||||
static Quaternion Q(float[] d, int o) => new(d[o + 3], d[o + 4], d[o + 5], d[o + 6]);
|
||||
|
||||
void Bones()
|
||||
{
|
||||
for (int b = 0; b < _names.Length; b++)
|
||||
{
|
||||
int o = b * 10;
|
||||
var local = Matrix.CreateScale(_pose[o + 7], _pose[o + 8], _pose[o + 9]) * Matrix.CreateFromQuaternion(Q(_pose, o)) * Matrix.CreateTranslation(V(_pose, o));
|
||||
_global[b] = _parent[b] >= 0 ? local * _global[_parent[b]] : local; // Eltern stehen vorher
|
||||
_skin[b] = _offset[b] * _global[b];
|
||||
}
|
||||
}
|
||||
|
||||
void SkinVertices()
|
||||
{
|
||||
System.Threading.Tasks.Parallel.For(0, (_pos.Length + 4095) / 4096, chunk =>
|
||||
{
|
||||
for (int i = chunk * 4096, end = Math.Min(_pos.Length, i + 4096); i < end; i++)
|
||||
{
|
||||
Vector3 p = Vector3.Zero, n = Vector3.Zero;
|
||||
for (int k = 0; k < 4; k++)
|
||||
{
|
||||
float w = _bw[i * 4 + k];
|
||||
if (w <= 0) continue;
|
||||
ref var m = ref _skin[_bi[i * 4 + k]];
|
||||
p += Vector3.Transform(_pos[i], m) * w;
|
||||
n += Vector3.TransformNormal(_nrm[i], m) * w;
|
||||
}
|
||||
Vertices[i].Position = p;
|
||||
Vertices[i].Normal = n;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// aura: nur Umriss in der Farbe des Effekts (additiv, ohne Tiefe), für Leuchten hinter der Figur.
|
||||
IndexBuffer? _ib;
|
||||
DynamicVertexBuffer? _vb;
|
||||
bool _dirty;
|
||||
|
||||
public void Draw(GraphicsDevice gd, BasicEffect fx, bool aura = false)
|
||||
{
|
||||
gd.DepthStencilState = aura ? DepthStencilState.None : DepthStencilState.Default;
|
||||
gd.BlendState = aura ? BlendState.Additive : BlendState.Opaque;
|
||||
gd.RasterizerState = RasterizerState.CullNone;
|
||||
fx.TextureEnabled = _texture != null && !aura;
|
||||
fx.Texture = _painted ?? _texture;
|
||||
// Indizes liegen einmal auf der Grafikkarte, Punkte nur nach einer neuen Haltung neu
|
||||
if (_ib == null)
|
||||
{
|
||||
_ib = new IndexBuffer(gd, IndexElementSize.ThirtyTwoBits, Indices.Length, BufferUsage.WriteOnly);
|
||||
_ib.SetData(Indices);
|
||||
_vb = new DynamicVertexBuffer(gd, VertexPNCT.Decl, Vertices.Length, BufferUsage.WriteOnly);
|
||||
_dirty = true;
|
||||
}
|
||||
if (_dirty || _vb!.IsContentLost) { _vb!.SetData(Vertices, 0, Vertices.Length, SetDataOptions.Discard); _dirty = false; }
|
||||
gd.SetVertexBuffer(_vb);
|
||||
gd.Indices = _ib;
|
||||
foreach (var pass in fx.CurrentTechnique.Passes)
|
||||
{
|
||||
pass.Apply();
|
||||
gd.SamplerStates[0] = SamplerState.LinearClamp;
|
||||
gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, Indices.Length / 3);
|
||||
}
|
||||
fx.TextureEnabled = false;
|
||||
var world = fx.World;
|
||||
foreach (var p in Props)
|
||||
{
|
||||
fx.World = p.Local * _global[p.Bone] * p.Correction * world;
|
||||
foreach (var pass in fx.CurrentTechnique.Passes)
|
||||
{
|
||||
pass.Apply();
|
||||
gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, p.V, 0, p.V.Length, p.I, 0, p.I.Length / 3);
|
||||
}
|
||||
}
|
||||
fx.World = world;
|
||||
}
|
||||
|
||||
// ── Waffen: einfache Formen, an einem Handknochen befestigt ──────────
|
||||
|
||||
public sealed class Prop
|
||||
{
|
||||
public int Bone; public Matrix Local;
|
||||
public bool Shield; public float Height, Width, Bend, Length; // Maße in cm (Schild: Höhe x, Breite y; Klinge: Länge entlang x)
|
||||
public Matrix Correction = Matrix.Identity; // Ausweichen vor dem eigenen Körper (Modell-Raum)
|
||||
public float Push, Angle; public Vector3 Axis = Vector3.Up;
|
||||
public VertexPNC[] V = Array.Empty<VertexPNC>(); public int[] I = Array.Empty<int>(); public Color[] Base = Array.Empty<Color>();
|
||||
}
|
||||
public readonly List<Prop> Props = new();
|
||||
|
||||
public int Bone(string name) => Array.FindIndex(_names, n => n == "mixamorig:" + name || n == name);
|
||||
|
||||
/// Lage eines Knochens in der Ruhehaltung (Netz-Raum).
|
||||
Matrix BindGlobal(int b) => Matrix.Invert(_offset[b]);
|
||||
Vector3 BindPos(string bone)
|
||||
{
|
||||
int b = Bone(bone);
|
||||
if (b >= 0) return BindGlobal(b).Translation;
|
||||
// Skelett ohne Finger (Mixamo mit kleinerer Skelettstufe): Fingerpunkte aus einem Rahmen, den das
|
||||
// Skelett selbst liefert (Unterarm, oben = Hüfte zum Kopf, seitlich), mit Werten gemittelt aus vier
|
||||
// vollständigen Figuren (Längen in cm bei 25 cm Unterarm). Unabhängig davon, wie die Figur im
|
||||
// Raum liegt (Meshy-Figuren sind in der Grundhaltung z-oben).
|
||||
string side = bone.StartsWith("Left") ? "Left" : "Right";
|
||||
int hand = Bone(side + "Hand"), fore = Bone(side + "ForeArm"), hips = Bone("Hips"), head = Bone("Head");
|
||||
if (hand < 0 || fore < 0 || hips < 0 || head < 0) return Vector3.Zero;
|
||||
var h = BindGlobal(hand).Translation;
|
||||
float cm = Vector3.Distance(h, BindGlobal(fore).Translation) / 25.25f;
|
||||
var a = Vector3.Normalize(h - BindGlobal(fore).Translation);
|
||||
var up = BindGlobal(head).Translation - BindGlobal(hips).Translation;
|
||||
var u = Vector3.Normalize(up - a * Vector3.Dot(up, a));
|
||||
var sd = Vector3.Cross(a, u);
|
||||
float sg = side == "Right" ? -1 : 1;
|
||||
Vector3 F(float x, float y, float z) => a * x + u * y + sd * (z * sg);
|
||||
var across = Vector3.Normalize(F(0.2f, 0.57f, 0.77f));
|
||||
var mid = h + F(13.8f, 1.4f, 0) * cm;
|
||||
return bone[side.Length..] switch
|
||||
{
|
||||
"HandMiddle1" => mid,
|
||||
"HandIndex1" => mid + across * 3.6f * cm,
|
||||
"HandPinky1" => mid - across * 3.5f * cm,
|
||||
"HandThumb1" => h + F(3.9f, -0.4f, 2.5f) * cm,
|
||||
_ => h
|
||||
};
|
||||
}
|
||||
|
||||
/// Rahmen in der Ruhehaltung (Achsen x, y, z, Ursprung) → lokal zum Knochen.
|
||||
Matrix Attach(int bone, Vector3 x, Vector3 y, Vector3 origin)
|
||||
{
|
||||
x.Normalize(); var z = Vector3.Normalize(Vector3.Cross(x, y)); y = Vector3.Cross(z, x);
|
||||
var frame = new Matrix(x.X, x.Y, x.Z, 0, y.X, y.Y, y.Z, 0, z.X, z.Y, z.Z, 0, origin.X, origin.Y, origin.Z, 1);
|
||||
return frame * _offset[bone]; // Rahmen · (Knochen in Ruhe)⁻¹
|
||||
}
|
||||
|
||||
/// Gladius in der Faust (Knochen-Präfix "Right"/"Left"). Klinge zeigt vom kleinen Finger zum Zeigefinger.
|
||||
public void AddSword(string side = "Right")
|
||||
{
|
||||
var h = BindPos(side + "Hand"); var m = BindPos(side + "HandMiddle1");
|
||||
var ix = BindPos(side + "HandIndex1"); var pk = BindPos(side + "HandPinky1"); var th = BindPos(side + "HandThumb1");
|
||||
var finger = Vector3.Normalize(m - h);
|
||||
var blade = Vector3.Normalize(ix - pk);
|
||||
var palm = Vector3.Normalize(Vector3.Cross(finger, blade));
|
||||
if (Vector3.Dot(palm, th - h) < 0) palm = -palm;
|
||||
var grip = h + (m - h) * 0.75f + palm * 2.5f * Unit;
|
||||
var b = new MeshBuilder();
|
||||
var steel = new Color(196, 200, 206); var brass = new Color(176, 136, 62); var wood = new Color(92, 58, 34);
|
||||
b.Box(new Vector3(-9, 0, 0), new Vector3(1.5f, 3.6f, 3.6f), brass); // Knauf
|
||||
b.Box(new Vector3(-3.5f, 0, 0), new Vector3(10, 3, 3), wood); // Griff
|
||||
b.Box(new Vector3(2.2f, 0, 0), new Vector3(1.6f, 4, 11), brass); // Parierstange
|
||||
b.Box(new Vector3(30, 0, 0), new Vector3(54, 0.8f, 5.2f), steel); // Klinge
|
||||
b.Box(new Vector3(60, 0, 0), new Vector3(6, 0.7f, 2.6f), steel); // Spitze
|
||||
var sword = b.Build(Bone(side + "Hand"), Matrix.CreateScale(Unit) * Attach(Bone(side + "Hand"), blade, palm, grip));
|
||||
sword.Length = 63;
|
||||
Props.Add(sword);
|
||||
}
|
||||
|
||||
/// Gewölbter Schild (Scutum) am Unterarm, Bemalung in Magenta (Teamfarbe), Bronzerand und Buckel.
|
||||
public void AddShield(string side = "Left")
|
||||
{
|
||||
var fa = BindPos(side + "ForeArm"); var h = BindPos(side + "Hand");
|
||||
var m = BindPos(side + "HandMiddle1"); var ix = BindPos(side + "HandIndex1"); var pk = BindPos(side + "HandPinky1"); var th = BindPos(side + "HandThumb1");
|
||||
var arm = Vector3.Normalize(h - fa);
|
||||
var across = Vector3.Normalize(ix - pk);
|
||||
var palm = Vector3.Normalize(Vector3.Cross(Vector3.Normalize(m - h), across));
|
||||
if (Vector3.Dot(palm, th - h) < 0) palm = -palm;
|
||||
// Scutum mit Quergriff: die Faust hält den Griff (kleiner Finger → Zeigefinger), die Knöchel
|
||||
// zeigen zum Schild; der Schild steht senkrecht zum Griff
|
||||
var knuckles = Vector3.Normalize(m - h);
|
||||
var centre = m + knuckles * 7 * Unit;
|
||||
var b = new MeshBuilder();
|
||||
var face = new Color(190, 30, 160); var rim = new Color(150, 112, 52); var boss = new Color(182, 150, 80);
|
||||
const float W = 50, H = 72, BEND = 0.011f;
|
||||
// x: Länge (entlang des Arms), y: Breite, z: nach außen (weg vom Arm), gewölbt um die Längsachse
|
||||
b.Curved(W, H, BEND, face, 1.2f);
|
||||
b.Rim(W, H, BEND, rim);
|
||||
b.Dome(new Vector3(0, 0, 2.5f), 9, 5, boss);
|
||||
// x (Höhe) = Griff (senkrecht gehalten, wie die Mixamo-Schildbewegungen es erwarten),
|
||||
// y (Breite) = Knöchel × Griff, z (außen) = x × y = Knöchelrichtung
|
||||
var shield = b.Build(Bone(side + "Hand"), Matrix.CreateScale(Unit) * Attach(Bone(side + "Hand"), across, Vector3.Cross(knuckles, across), centre));
|
||||
shield.Shield = true; shield.Height = H; shield.Width = W; shield.Bend = BEND;
|
||||
Props.Add(shield);
|
||||
}
|
||||
|
||||
// ── Waffen weichen dem eigenen Körper aus ───────────────────────────
|
||||
// Die Mixamo-Bewegungen kennen Schwert und Schild nicht: in manchen Haltungen läge der Schild
|
||||
// im Oberschenkel oder die Klinge im Rumpf. Der Körper wird grob als Kapseln (Strecke + Radius)
|
||||
// aus den Knochen gebaut; der Schild wird nach außen geschoben, die Klinge um den Griff weggedreht.
|
||||
// Beides federt nach, damit nichts springt oder zittert.
|
||||
|
||||
readonly List<(Vector3 A, Vector3 B, float R)> _body = new();
|
||||
int[]? _bodyBones;
|
||||
|
||||
void BuildBody(out float cm)
|
||||
{
|
||||
_bodyBones ??= new[] { Bone("Hips"), Bone("Neck"), Bone("Head"), Bone("LeftUpLeg"), Bone("LeftLeg"), Bone("LeftFoot"),
|
||||
Bone("RightUpLeg"), Bone("RightLeg"), Bone("RightFoot") };
|
||||
_body.Clear();
|
||||
var bb = _bodyBones;
|
||||
Vector3 P(int i) => bb[i] >= 0 ? _global[bb[i]].Translation : Vector3.Zero;
|
||||
// Maßstab: Oberschenkel etwa 45 cm
|
||||
cm = bb[3] >= 0 && bb[4] >= 0 ? Vector3.Distance(P(3), P(4)) / 45f : 1;
|
||||
if (bb[0] < 0 || bb[1] < 0) return;
|
||||
_body.Add((P(0), P(1), 15 * cm)); // Rumpf
|
||||
if (bb[3] >= 0 && bb[6] >= 0) _body.Add((P(3), P(6), 11 * cm)); // Becken
|
||||
if (bb[2] >= 0) _body.Add((P(2), P(2) + (P(2) - P(1)) * 0.6f, 11 * cm)); // Kopf
|
||||
if (bb[3] >= 0 && bb[4] >= 0 && bb[5] >= 0) { _body.Add((P(3), P(4), 9 * cm)); _body.Add((P(4), P(5), 6.5f * cm)); }
|
||||
if (bb[6] >= 0 && bb[7] >= 0 && bb[8] >= 0) { _body.Add((P(6), P(7), 9 * cm)); _body.Add((P(7), P(8), 6.5f * cm)); }
|
||||
}
|
||||
|
||||
static Vector3 Closest(Vector3 a, Vector3 b, Vector3 p)
|
||||
{
|
||||
var ab = b - a; float l = ab.LengthSquared();
|
||||
return l < 1e-9f ? a : a + ab * MathHelper.Clamp(Vector3.Dot(p - a, ab) / l, 0, 1);
|
||||
}
|
||||
|
||||
void AvoidBody()
|
||||
{
|
||||
if (Props.Count == 0) return;
|
||||
BuildBody(out float cm);
|
||||
if (_body.Count == 0) return;
|
||||
Prop? shield = null;
|
||||
foreach (var p in Props) if (p.Shield) shield = p;
|
||||
if (shield != null) AvoidShield(shield, cm);
|
||||
foreach (var p in Props) if (!p.Shield) AvoidBlade(p, shield, cm);
|
||||
}
|
||||
|
||||
static Vector3 Axis(Matrix m, int row) => row switch
|
||||
{
|
||||
0 => new Vector3(m.M11, m.M12, m.M13), 1 => new Vector3(m.M21, m.M22, m.M23), _ => new Vector3(m.M31, m.M32, m.M33)
|
||||
};
|
||||
|
||||
/// Schild entlang seiner Außenseite verschieben, bis kein Körperteil von innen hineinragt.
|
||||
void AvoidShield(Prop s, float cm)
|
||||
{
|
||||
var m = s.Local * _global[s.Bone];
|
||||
var c = m.Translation;
|
||||
float sc = Axis(m, 0).Length(); // Modell-Einheiten je Schild-cm
|
||||
var ax = Vector3.Normalize(Axis(m, 0)); var ay = Vector3.Normalize(Axis(m, 1)); var az = Vector3.Normalize(Axis(m, 2));
|
||||
float hh = s.Height / 2 * sc, hw = s.Width / 2 * sc, gap = 2 * cm, thick = 1.5f * sc;
|
||||
float need = 0;
|
||||
foreach (var (a, b, r) in _body)
|
||||
for (int k = 0; k <= 8; k++)
|
||||
{
|
||||
var d = Vector3.Lerp(a, b, k / 8f) - c;
|
||||
float u = Vector3.Dot(d, ax), v = Vector3.Dot(d, ay), w = Vector3.Dot(d, az);
|
||||
if (MathF.Abs(u) > hh + r * 0.5f || MathF.Abs(v) > hw + r * 0.5f) continue; // neben dem Schild
|
||||
float vc = MathHelper.Clamp(v, -hw, hw) / sc;
|
||||
float surf = -s.Bend * vc * vc * sc - thick; // Innenseite (gewölbt)
|
||||
if (w > surf + r) continue; // vor dem Schild: nicht durch Schieben lösbar
|
||||
need = MathF.Max(need, w + r + gap - surf);
|
||||
}
|
||||
need = MathF.Min(need, 40 * cm);
|
||||
s.Push += (need - s.Push) * (need > s.Push ? 0.55f : 0.12f); // schnell hinaus, langsam zurück
|
||||
s.Correction = Matrix.CreateTranslation(az * s.Push);
|
||||
}
|
||||
|
||||
/// Klinge um den Griff wegdrehen, wenn sie Körper oder eigenen Schild schneidet.
|
||||
void AvoidBlade(Prop p, Prop? shield, float cm)
|
||||
{
|
||||
var m = p.Local * _global[p.Bone];
|
||||
var grip = m.Translation;
|
||||
float sc = Axis(m, 0).Length();
|
||||
var dir = Vector3.Normalize(Axis(m, 0));
|
||||
float len = p.Length * sc, half = 2.5f * cm;
|
||||
var sm = shield != null ? shield.Local * _global[shield.Bone] * shield.Correction : Matrix.Identity;
|
||||
float ss = Axis(sm, 0).Length();
|
||||
var sx = Vector3.Normalize(Axis(sm, 0)); var sy = Vector3.Normalize(Axis(sm, 1)); var sz = Vector3.Normalize(Axis(sm, 2));
|
||||
|
||||
bool Hits(Vector3 d, out Vector3 away)
|
||||
{
|
||||
away = Vector3.Zero; bool hit = false;
|
||||
for (int k = 2; k <= 10; k++)
|
||||
{
|
||||
var q = grip + d * (len * k / 10f);
|
||||
foreach (var (a, b, r) in _body)
|
||||
{
|
||||
var cp = Closest(a, b, q);
|
||||
if (Vector3.DistanceSquared(cp, q) < (r + half) * (r + half)) { away += q - cp; hit = true; }
|
||||
}
|
||||
if (shield != null)
|
||||
{
|
||||
var dq = q - sm.Translation;
|
||||
float u = Vector3.Dot(dq, sx), v = Vector3.Dot(dq, sy), w = Vector3.Dot(dq, sz);
|
||||
float vc = v / ss, surf = -shield.Bend * vc * vc * ss;
|
||||
if (MathF.Abs(u) < shield.Height / 2 * ss && MathF.Abs(v) < shield.Width / 2 * ss && MathF.Abs(w - surf) < 2.5f * cm)
|
||||
{ away += sz * (w >= surf ? 1 : -1); hit = true; }
|
||||
}
|
||||
}
|
||||
return hit;
|
||||
}
|
||||
|
||||
float target = 0;
|
||||
if (Hits(dir, out var push) && push.LengthSquared() > 1e-9f)
|
||||
{
|
||||
var axis = Vector3.Cross(dir, Vector3.Normalize(push));
|
||||
if (axis.LengthSquared() > 1e-9f)
|
||||
{
|
||||
axis.Normalize();
|
||||
p.Axis = axis;
|
||||
target = MathHelper.ToRadians(50);
|
||||
for (int deg = 6; deg <= 50; deg += 6)
|
||||
if (!Hits(Vector3.Transform(dir, Quaternion.CreateFromAxisAngle(axis, MathHelper.ToRadians(deg))), out _))
|
||||
{ target = MathHelper.ToRadians(deg); break; }
|
||||
}
|
||||
}
|
||||
p.Angle += (target - p.Angle) * (target > p.Angle ? 0.5f : 0.12f);
|
||||
p.Correction = p.Angle < 1e-3f ? Matrix.Identity
|
||||
: Matrix.CreateTranslation(-grip) * Matrix.CreateFromAxisAngle(p.Axis, p.Angle) * Matrix.CreateTranslation(grip);
|
||||
}
|
||||
|
||||
sealed class MeshBuilder
|
||||
{
|
||||
readonly List<VertexPNC> _v = new(); readonly List<int> _i = new();
|
||||
|
||||
void Quad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Color col)
|
||||
{
|
||||
var n = Vector3.Normalize(Vector3.Cross(b - a, c - a));
|
||||
int o = _v.Count;
|
||||
foreach (var p in new[] { a, b, c, d }) _v.Add(new VertexPNC { Position = p, Normal = n, Color = col });
|
||||
_i.AddRange(new[] { o, o + 1, o + 2, o, o + 2, o + 3 });
|
||||
}
|
||||
|
||||
public void Box(Vector3 c, Vector3 s, Color col)
|
||||
{
|
||||
var h = s / 2;
|
||||
Vector3 P(float x, float y, float z) => c + new Vector3(x * h.X, y * h.Y, z * h.Z);
|
||||
Quad(P(-1, -1, 1), P(1, -1, 1), P(1, 1, 1), P(-1, 1, 1), col);
|
||||
Quad(P(1, -1, -1), P(-1, -1, -1), P(-1, 1, -1), P(1, 1, -1), col);
|
||||
Quad(P(-1, 1, -1), P(-1, 1, 1), P(1, 1, 1), P(1, 1, -1), col);
|
||||
Quad(P(-1, -1, 1), P(-1, -1, -1), P(1, -1, -1), P(1, -1, 1), col);
|
||||
Quad(P(1, -1, 1), P(1, -1, -1), P(1, 1, -1), P(1, 1, 1), col);
|
||||
Quad(P(-1, -1, -1), P(-1, -1, 1), P(-1, 1, 1), P(-1, 1, -1), col);
|
||||
}
|
||||
|
||||
static Vector3 Surf(float x, float y, float bend, float off) => new(x, y, -bend * y * y + off);
|
||||
|
||||
public void Curved(float w, float h, float bend, Color col, float thick)
|
||||
{
|
||||
const int NX = 8, NY = 10;
|
||||
for (int side = 0; side < 2; side++)
|
||||
for (int i = 0; i < NX; i++)
|
||||
for (int j = 0; j < NY; j++)
|
||||
{
|
||||
float x0 = -h / 2 + h * i / NX, x1 = -h / 2 + h * (i + 1) / NX;
|
||||
float y0 = -w / 2 + w * j / NY, y1 = -w / 2 + w * (j + 1) / NY;
|
||||
float off = side == 0 ? 0 : -thick;
|
||||
var shade = side == 0 ? col : new Color(110, 78, 46); // Innenseite Holz
|
||||
Quad(Surf(x0, y0, bend, off), Surf(x1, y0, bend, off), Surf(x1, y1, bend, off), Surf(x0, y1, bend, off), shade);
|
||||
}
|
||||
}
|
||||
|
||||
public void Rim(float w, float h, float bend, Color col)
|
||||
{
|
||||
const int N = 10;
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
float y0 = -w / 2 + w * j / N, y1 = -w / 2 + w * (j + 1) / N;
|
||||
foreach (float x in new[] { -h / 2, h / 2 })
|
||||
{
|
||||
var a = Surf(x, y0, bend, 0.6f); var c = Surf(x, y1, bend, 0.6f);
|
||||
Box((a + c) / 2, new Vector3(3, MathF.Abs(y1 - y0) + 0.2f, 3), col);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
float x0 = -h / 2 + h * i / N, x1 = -h / 2 + h * (i + 1) / N;
|
||||
foreach (float y in new[] { -w / 2, w / 2 })
|
||||
Box(Surf((x0 + x1) / 2, y, bend, 0.6f), new Vector3(MathF.Abs(x1 - x0) + 0.2f, 3, 3), col);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dome(Vector3 c, float r, float hgt, Color col)
|
||||
{
|
||||
const int SEG = 12, RING = 4;
|
||||
for (int k = 0; k < RING; k++)
|
||||
for (int s = 0; s < SEG; s++)
|
||||
{
|
||||
float a0 = MathF.PI / 2 * k / RING, a1 = MathF.PI / 2 * (k + 1) / RING;
|
||||
float t0 = MathF.Tau * s / SEG, t1 = MathF.Tau * (s + 1) / SEG;
|
||||
Vector3 P(float a, float t) => c + new Vector3(MathF.Cos(t) * MathF.Cos(a) * r, MathF.Sin(t) * MathF.Cos(a) * r, MathF.Sin(a) * hgt);
|
||||
Quad(P(a0, t0), P(a0, t1), P(a1, t1), P(a1, t0), col);
|
||||
}
|
||||
}
|
||||
|
||||
public Prop Build(int bone, Matrix local)
|
||||
{
|
||||
var v = _v.ToArray();
|
||||
return new Prop { Bone = bone, Local = local, V = v, I = _i.ToArray(), Base = Array.ConvertAll(v, x => x.Color) };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
68
Mono/Gfx/Ui.cs
Normal file
68
Mono/Gfx/Ui.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using FontStashSharp;
|
||||
using GladiatorIdle.Arena;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using D = GladiatorIdle.Gfx.Draw;
|
||||
|
||||
namespace GladiatorIdle.Gfx
|
||||
{
|
||||
/// <summary>
|
||||
/// Einfache Oberfläche im Sofort-Modus (Design-Pixel): jedes Bild werden Knöpfe gezeichnet und
|
||||
/// gleichzeitig geprüft, ob sie geklickt wurden. Maus in Design-Pixel umgerechnet.
|
||||
/// </summary>
|
||||
internal sealed class Ui
|
||||
{
|
||||
public Vector2 Mouse;
|
||||
public bool Click;
|
||||
public bool Hovering { get; private set; }
|
||||
Matrix _inverse;
|
||||
|
||||
public void Begin(Input input, Matrix ui)
|
||||
{
|
||||
_inverse = Matrix.Invert(ui);
|
||||
Mouse = Vector2.Transform(new Vector2(input.Mouse.X, input.Mouse.Y), _inverse);
|
||||
Click = input.LeftClick;
|
||||
Hovering = false;
|
||||
}
|
||||
|
||||
public bool Hover(RectangleF r)
|
||||
{
|
||||
bool h = r.Contains(Mouse);
|
||||
if (h) Hovering = true;
|
||||
return h;
|
||||
}
|
||||
|
||||
/// Klick auf die Fläche (einmal je Klick).
|
||||
public bool Hit(RectangleF r)
|
||||
{
|
||||
if (!Click || !r.Contains(Mouse)) return false;
|
||||
Click = false;
|
||||
SoundManager.PlayClick();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Dunkle Tafel mit Bronzerand.
|
||||
public static void Panel(SpriteBatch sb, RectangleF r, Color? border = null, float alpha = 0.86f)
|
||||
{
|
||||
D.Rect(sb, r, new Color(18, 13, 9) * alpha);
|
||||
D.Frame(sb, r, border ?? D.Border, 2);
|
||||
D.Frame(sb, new RectangleF(r.X + 4, r.Y + 4, r.Width - 8, r.Height - 8), Color.Black * 0.35f, 1);
|
||||
}
|
||||
|
||||
/// Knopf mit Text; liefert true beim Klick.
|
||||
public bool Button(SpriteBatch sb, RectangleF r, string text, bool enabled = true, bool selected = false,
|
||||
float size = 24, Color? accent = null)
|
||||
{
|
||||
bool hover = enabled && Hover(r);
|
||||
var a = accent ?? D.Gold;
|
||||
var fill = !enabled ? new Color(24, 20, 16) : selected ? a * 0.32f : hover ? new Color(70, 52, 32) : new Color(38, 28, 19);
|
||||
D.Rect(sb, r, fill * 0.95f);
|
||||
D.Rect(sb, new RectangleF(r.X + 2, r.Y + 2, r.Width - 4, (r.Height - 4) * 0.45f), Color.White * (hover ? 0.08f : 0.04f));
|
||||
D.Frame(sb, r, !enabled ? new Color(60, 48, 36) : selected || hover ? a : D.Border, selected ? 3 : 2);
|
||||
D.Text(sb, Assets.SansBold, size, text, r.Center, !enabled ? D.Dim : selected ? Color.White : D.Sand, Align.Center);
|
||||
return enabled && Hit(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Mono/GladiatorMono.csproj
Normal file
33
Mono/GladiatorMono.csproj
Normal file
@@ -0,0 +1,33 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>GladiatorIdle</RootNamespace>
|
||||
<AssemblyName>GladiatorMono</AssemblyName>
|
||||
<Product>Gladiator Idle</Product>
|
||||
<Copyright>© 2026 Michael Media</Copyright>
|
||||
<Company>Michael Media</Company>
|
||||
<RollForward>Major</RollForward>
|
||||
<TieredPGO>true</TieredPGO>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Spiellogik und Kern-Bausteine aus dem Hauptprojekt (verlinkt, nicht kopiert) -->
|
||||
<Compile Include="..\Game\**\*.cs" Link="Shared\Game\%(RecursiveDir)%(Filename)%(Extension)" />
|
||||
<Compile Include="..\Core\LocalizationManager.cs;..\Core\AppSettings.cs;..\Core\SoundManager.cs;..\Core\DevShot.cs;..\Core\Credits.cs" Link="Shared\Core\%(Filename)%(Extension)" />
|
||||
<!-- Sprache und Ton eingebettet (gleiche Namen wie im Hauptprojekt); Bilder und Clips
|
||||
lädt der Prototyp von der Platte (Assets/ im Projektordner) -->
|
||||
<EmbeddedResource Include="..\Languages\*.json" LogicalName="GladiatorIdle.Languages.%(Filename)%(Extension)" />
|
||||
<EmbeddedResource Include="..\Assets\Audio\*.mp3" LogicalName="GladiatorIdle.Assets.Audio.%(Filename)%(Extension)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.2.1105" />
|
||||
<PackageReference Include="FontStashSharp.MonoGame" Version="1.3.7" />
|
||||
<PackageReference Include="NAudio" Version="2.2.1" />
|
||||
<PackageReference Include="StbImageSharp" Version="2.27.14" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
34
Mono/Program.cs
Normal file
34
Mono/Program.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
|
||||
namespace GladiatorIdle
|
||||
{
|
||||
/// <summary>
|
||||
/// MonoGame-Prototyp: ein Echtzeit-Duell in der Arena, mit lebendiger Darstellung.
|
||||
/// Gleiche Test-Schalter wie das Hauptspiel (--shot, --lang, --class, --sim, --windowed, --size).
|
||||
/// </summary>
|
||||
internal static class Program
|
||||
{
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
L.Load();
|
||||
AppSettings.Load();
|
||||
AppSettings.ApplyVolumes();
|
||||
DevShot.Parse(Environment.GetCommandLineArgs());
|
||||
if (DevShot.Lang is L.Lang devLang) L.UseForSession(devLang);
|
||||
// erster Start: Sprache des Systems (de/es, sonst en); später in den Einstellungen änderbar
|
||||
else if (!DevShot.Active && !L.HasSavedLanguage)
|
||||
{
|
||||
string sys = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
|
||||
L.Set(sys == "de" ? L.Lang.De : sys == "es" ? L.Lang.Es : L.Lang.En);
|
||||
}
|
||||
if (DevShot.Active) SoundManager.Enabled = false; // Testläufe stumm
|
||||
if (DevShot.Playtest) { Playtest.Run(); return; }
|
||||
|
||||
using var game = new ArenaGame();
|
||||
game.Run();
|
||||
SoundManager.StopAll();
|
||||
SoundManager.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user