hughe update
58
CLAUDE.md
@@ -14,14 +14,32 @@ keine Namen, Figuren, Arenen, Hausroboter, Grafiken, Sounds oder Code aus dem Or
|
||||
|
||||
**Ablauf**
|
||||
1. **Werkstatt:** Roboter aus Teilen bauen – je 1 Chassis, Motor, Räder, Batterie (Pflicht), dazu Panzerung,
|
||||
Hauptwaffe (Keil, Flipper, Axt, Säge, Zange, Spinner) und Turm (Flammen, Minigun, Raketen). Max. 100 kg,
|
||||
Hauptwaffe, Turm und Gadget. Stand: 10 Chassis (Formen box/wedge/dome/frame/hex/barrel/arrow/plow/saucer),
|
||||
13 Waffen (Keil, Lanze, Flipper, Schaufel-Heber, Axt, Morgenstern, Säge, Bohrer, Zange, Bar-/Walzen-/
|
||||
Vertikal-Spinner, Schleuder), 7 Räder, 7 Panzerungen (jede mit eigener Optik: Gitter, Platten, Gummipuffer,
|
||||
Stacheln, Kacheln – `style` in parts.js, Zweig in render3d), 3 Türme, 5 Gadgets; jedes Teil zeigt im Detail seinen Hotkey und
|
||||
führt seine Bewegung in der Werkstatt-Vorschau vor. Max. 100 kg,
|
||||
Batterie muss den Strom liefern. Kaufen / einbauen / verkaufen (50 %), Lack + Akzentfarbe, Name.
|
||||
2. **Liga:** 8 KI-Gegner nacheinander (Stile: Raufbold, Flankierer, Schieber, Schütze), steigende Preise.
|
||||
3. **Kampf (2 min, isometrisch 3D):** 3 Arenen in verschiedenen Größen (`RC.ARENAS` in combat.js: Werkstatt-Grube
|
||||
half 8, Gießerei half 12, Mega-Dome half 16), je mit Stachelwänden, Bodensägen, Flammengittern, 2 Wächtern
|
||||
(Schmiedepresse, Magnetkran) und einer Grube ab Halbzeit. Liga skaliert die Arena mit dem Gegner, Einstellung
|
||||
`arena` (Zufällig/fest), online aus dem Seed. Kamera + Licht + Boden skalieren mit `half`. Harte Rammstöße und
|
||||
Wandtreffer können Roboter auf den Rücken schleudern (`flipped`).
|
||||
**Kampfschaden:** Teile reißen bei festen LP-Anteilen ab (Panzer 60 %, Rad 40 %, Hauptwaffe 25 %, Turm 18 % –
|
||||
deterministisch, `BREAK_AT` in combat.js). Das Teil verlässt das 3D-Modell und poltert über den Boden
|
||||
(`breakPart`/`dropPiece`), wirkt sich aus (Rad: langsamer; Panzer: weniger Schutz; Waffe/Turm: tot) und steht
|
||||
live im HUD (LP-Zahlen + durchgestrichene Teil-Symbole je Roboter, rote Bildschirmkante unter 30 %).
|
||||
**Türme feuern geradeaus** (kein Auto-Zielen) – gezielt wird, indem man den Roboter dreht.
|
||||
|
||||
3. **Kampf (2 min, isometrisch 3D):** 6 Arenen, jede mit eigener Grundform und eigenem Markenzeichen
|
||||
(`RC.ARENAS` in combat.js). `shape`: `square` | `octagon` | `round`; die Wandkollision läuft über
|
||||
`RC.wallPush(A, x, z, rad)` (liefert Normale → Abprall und Stachelschaden), **Achtung:** bei round/octagon
|
||||
müssen Presse und Kran nach innen versetzt werden, sonst stehen sie außerhalb der Wand.
|
||||
Arena-Felder: `blocks` (Deckung: pillar/crate/scrap/barrier – Geschosse detonieren daran, Strahlwaffen gehen
|
||||
hindurch), `belts` (Förderband zieht mit), `oil` (Pfütze: weniger Grip, träge Lenkung über `r.onOil`),
|
||||
`rams` (Wandramme stößt im Takt zu). Dazu wie gehabt Stachelwände, Bodensägen, Flammengitter, 2 Wächter
|
||||
(Schmiedepresse, Magnetkran) und eine Grube ab Halbzeit (Mega-Dome früher, `pitOpensAt`).
|
||||
Workshop 8 ▪ Scrapyard 10 (Wrackberge + Öl) ▪ Foundry 12 achteckig (Band) ▪ Crucible 14 rund (Säule + Rammen)
|
||||
▪ Mega-Dome 16 achteckig (4 Säulen) ▪ Colosseum 20 rund (Mittelblock + Bänder zur Grube).
|
||||
Liga skaliert die Arena mit dem Gegner, Einstellung `arena` (Zufällig/fest), online aus dem Seed.
|
||||
Kamera + Licht + Boden skalieren mit `half`. Harte Rammstöße und Wandtreffer können Roboter auf den
|
||||
Rücken schleudern (`flipped`).
|
||||
4. **Sieg:** K.o., Gegner in der Grube, oder nach Zeit über Schaden (Fallen-Schaden zählt für den Gegner).
|
||||
5. **Ergebnis:** Preisgeld (+ K.o./Gruben-Bonus) bzw. Antrittsgeld (35 %), Schadensbonus (0,6 Credits je Schaden,
|
||||
auch bei Niederlage), Reparatur (6 % Teilewert × Schaden), Ruhm → zurück in die Werkstatt. Start: 800 Credits.
|
||||
@@ -38,19 +56,38 @@ Leicht (Standard: Spieler-LP ×1,4, KI −0,2) / Normal / Schwer (`DIFF` in game
|
||||
(Stick, A Waffe, B Turm, Start Pause); Touch-Knöpfe auf Touchgeräten.
|
||||
|
||||
**Stil:** Industrielle Show-Arena bei Nacht, Flutlicht, kantige Bastel-Roboter aus Blech, Funken, Warnstreifen.
|
||||
Akzent `#FF7A1A`, Überschriften „Russo One“ (Fallback Segoe UI Black). Grafik derzeit komplett prozedural (three.js).
|
||||
Akzent `#FF7A1A`, Überschriften „Russo One“ – die Schrift liegt **lokal** in `game/assets/Fonts/RussoOne-Regular.ttf`
|
||||
(SIL OFL 1.1, `@font-face` in `index.html`, wird in die Release-HTML eingebettet); Fallback Segoe UI Black.
|
||||
**Vollbild-Look:** die HUD-Leiste liegt *in* der Bühne (`#hud` in `#stage`, `z-index 7`), kein Rahmen ums Spielfeld;
|
||||
was sie zeigt, steuert `body[data-mode=…]` (Titel: aus · Kampf: nur ⏸ und Ton). Gemeinsame CSS-Tokens in `:root`
|
||||
(`--steel`, `--sheen`, `--hl`, `--chamfer`, `--hazard`) – neue UI damit bauen, nicht mit Einzelwerten.
|
||||
Tap-Ziele ≥ 34 px, Hauptknöpfe ≥ 42 px, Hover nur in `@media (hover: hover)`, kein `backdrop-filter` (CPU).
|
||||
**Keine Scrollbalken:** jede Ansicht muss in die Bühne passen (Spaltenzahl/Größen anpassen statt scrollen);
|
||||
die Balken sind global ausgeblendet, `overflow:auto` bleibt nur als Notnetz für dynamische Listen (Lobby).
|
||||
Grafik sonst prozedural (three.js).
|
||||
Stilblock für ComfyGen: *isometric 3/4 view game sprite, chunky handmade combat robot, scratched painted steel,
|
||||
bolts and hazard stripes, bold clean shapes, soft studio lighting, high detail, plain solid black background*
|
||||
|
||||
**Erste Version (drin):** Werkstatt mit 25 Teilen in 7 Slots, 1 Arena, 8 Liga-Gegner + Training, Saisons,
|
||||
Speichern, en/de, Synth-Sounds. **Später:** Firebase-Rangliste (URL von Michael), asynchrones PvP (hochgeladene
|
||||
Roboter, KI-gesteuert), echtes PvP (WebRTC), Replays/Zuschauer, weitere Arenen + Gewichtsklassen, Icon/Musik/SFX
|
||||
über ComfyGen, Schrift „Russo One“ lokal in `assets/Fonts`.
|
||||
über ComfyGen. Titel-Logo `assets/Sprites/logo.png` (Prompt `logo` in `sprite-generator/prompts.py`,
|
||||
`gen adopt --wide --size 1024 logo`) – fehlt es, zeigt der Titel den Schriftzug; ComfyUI muss dafür laufen.
|
||||
|
||||
**Online-Technik:** Der Host rechnet und sendet Snapshots – er schreibt **nur einen** Request gleichzeitig
|
||||
(`sending`-Sperre in netfight.js) und drosselt bei langsamer Leitung, sonst stapeln sich die Uploads und *beim
|
||||
Host* ruckelt es, während der Gast flüssig bleibt. Zahlen werden auf 3 Nachkommastellen gerundet (Paketgröße).
|
||||
Rangliste: `Kit.scores.top()` zeigt **jeden Spieler nur einmal** (bester Lauf) – jeder Eintrag ist eine eigene
|
||||
Zeile in der DB, die Entdopplung passiert beim Lesen (Fix liegt in `_Tools\Library\web\kit\kit-scores.js`).
|
||||
|
||||
**Online (Firebase, optional):** Titel → „Online spielen" (nur wenn `NET_CFG.apiKey` gesetzt), Login per
|
||||
E-Mail/Passwort, globale Lobby (alle Online-Spieler + Länderflagge), Klick auf Spieler = Herausfordern → Live-Kampf.
|
||||
Rangliste läuft schon mit `DB_URL` allein. Einrichtung + Grenzen: `docs/firebase/README.md`.
|
||||
|
||||
**Performance:** Render ist auf ~60 fps gedeckelt (Menüs ~16 fps), Pixel-Ratio-Deckel hoch 1,5 / mittel 1,25 /
|
||||
niedrig 1,0, Schatten-Map 1024 (soft nur bei Hoch), `powerPreference high-performance`. Standard-Grafik „Mittel“.
|
||||
Dev: `?fps` zeigt die effektive Bildrate. Logik (`Kit.loop update`) bleibt fix 60 Hz.
|
||||
|
||||
**Verschleierung:** `.\build.ps1 -Web -Obfuscate` jagt die eigenen Skripte durch terser (lokal via `npm install`).
|
||||
Client bleibt grundsätzlich lesbar – nur erschwert, kein Kopierschutz.
|
||||
|
||||
@@ -72,8 +109,11 @@ Client bleibt grundsätzlich lesbar – nur erschwert, kein Kopierschutz.
|
||||
- Tests: `node tests/sim.test.js` (Regeln, Kämpfe ohne NaN, Grube), `node tests/balance.js [-v]` (Zahlen).
|
||||
- Grafik/Sound: `sprite-generator/prompts.py` + `audio.py` → `gen generate`, `gen adopt --all` (Sprites), `gen adopt_scene bg_*` (Hintergründe als JPG),
|
||||
`gen make_tileable tex_floor`, `gen adopt_audio --all`. Fehlende Bilder → Ersatz-Symbol (`RC.pic`), fehlende Sounds → Synth.
|
||||
- `game/uicheck.js` Layout-Selbsttest: `&uicheck` misst Scrollen, Überläufe, Überlappungen, zu kleine Tap-Ziele,
|
||||
abgeschnittene Texte und ob die Schrift geladen ist – Ergebnis als Text in `<pre id="uicheck">` + `document.title`
|
||||
(so per `chrome --headless --dump-dom` auslesbar, **ohne Screenshot**). Nach jeder UI-Änderung laufen lassen.
|
||||
- Dev-Parameter: `index.html?title` (Titel ohne Intro), `?play` (Shop als Gast), `?fight=N` (Training gegen Liga-Gegner N), `&auto` (KI fährt
|
||||
für dich), `&ff=30` (30 s vorspulen), `&cam=chase|fpv` (Kamera).
|
||||
für dich), `&ff=30` (30 s vorspulen), `&cam=chase|fpv` (Kamera), `&uicheck` (Layout-Prüfung), `&touch` (Touch-Pad am PC zeigen).
|
||||
|
||||
## Arbeitsweise
|
||||
|
||||
|
||||
@@ -79,5 +79,7 @@ D:\Oculusquest\Projekt\_Tools\Library\new-project.ps1 -UpdateKit -Path .
|
||||
|
||||
## Lizenzen
|
||||
|
||||
three.js © three.js authors, MIT-Lizenz (`game/vendor/three.min.js`). Eigenes Spiel – keine Inhalte aus
|
||||
three.js © three.js authors, MIT-Lizenz (`game/vendor/three.min.js`).
|
||||
Schrift „Russo One" © 2011–2012 Jovanny Lemonad, SIL Open Font License 1.1
|
||||
(`game/assets/Fonts/RussoOne-Regular.ttf`, Lizenztext daneben in `OFL.txt`). Eigenes Spiel – keine Inhalte aus
|
||||
Robot Rage / Robot Kampen oder deren Ports.
|
||||
|
||||
47
game/ai.js
@@ -6,16 +6,19 @@
|
||||
(function (root) {
|
||||
'use strict';
|
||||
const RC = (root.RC = root.RC || {});
|
||||
const A = () => RC.ARENA;
|
||||
const clamp = (v, a, b) => (v < a ? a : v > b ? b : v);
|
||||
const wrap = a => { while (a > Math.PI) a -= 2 * Math.PI; while (a < -Math.PI) a += 2 * Math.PI; return a; };
|
||||
|
||||
function danger(s, x, z, me) {
|
||||
const ar = A(), m = 0.35;
|
||||
const ar = s.arena || RC.ARENA, m = 0.35;
|
||||
if (s.left < ar.pitOpensAt + 2 && Math.abs(x - ar.pit.x) < ar.pit.hw + me.st.rad && Math.abs(z - ar.pit.z) < ar.pit.hd + me.st.rad) return 3;
|
||||
for (const h of ar.saws) if (RC.hazardOn(h, s.t + 0.4) && Math.hypot(x - h.x, z - h.z) < h.r + me.st.rad) return 2;
|
||||
for (const h of ar.flames) if (RC.hazardOn(h, s.t + 0.4) && Math.abs(x - h.x) < h.hw + m && Math.abs(z - h.z) < h.hd + m) return 2;
|
||||
for (const g of [ar.press, ar.crane]) if (Math.abs(x - g.x) < g.hw + m && Math.abs(z - g.z) < g.hd + m) return 2;
|
||||
for (const r of ar.rams || []) if (RC.hazardOn(r, s.t + 0.4) && Math.abs(x - r.x) < r.hw + m && Math.abs(z - r.z) < r.hd + m) return 2;
|
||||
// solid cover and slicks: drive round them, they are not deadly
|
||||
for (const b of ar.blocks || []) if (Math.abs(x - b.x) < b.hw + me.st.rad && Math.abs(z - b.z) < b.hd + me.st.rad) return 1;
|
||||
for (const o of ar.oil || []) if (Math.hypot(x - o.x, z - o.z) < o.r) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -52,23 +55,21 @@
|
||||
const back = e.a + Math.PI + (rand() < 0.5 ? 0.9 : -0.9);
|
||||
tx = e.x + Math.cos(back) * 1.8; tz = e.z + Math.sin(back) * 1.8;
|
||||
} else if (style === 'pusher') { // line up enemy -> pit (or press corner) and shove
|
||||
const ar = A(), goal = s.pitOpen >= 1 ? ar.pit : ar.press;
|
||||
const ar = s.arena, goal = s.pitOpen >= 1 ? ar.pit : ar.press;
|
||||
const gx = goal.x - e.x, gz = goal.z - e.z, gl = Math.hypot(gx, gz) || 1;
|
||||
const bx = e.x - gx / gl * 1.6, bz = e.z - gz / gl * 1.6;
|
||||
const lined = Math.hypot(me.x - bx, me.z - bz) < 1.0 || dist < me.st.rad + e.st.rad + 0.25;
|
||||
if (!lined && dist > 1.1) { tx = bx; tz = bz; }
|
||||
} else if (style === 'gunner' && t) { // keep distance, circle
|
||||
const want = t.type === 'flamer' ? 1.8 : 4.2;
|
||||
if (dist < want) {
|
||||
const away = Math.atan2(me.z - e.z, me.x - e.x) + 0.9;
|
||||
tx = e.x + Math.cos(away) * want; tz = e.z + Math.sin(away) * want;
|
||||
}
|
||||
} else if (style === 'gunner' && t) { // face the enemy (fixed turret), hold the range
|
||||
tx = e.x; tz = e.z;
|
||||
}
|
||||
let cmd = steer(me, tx, tz, 0.75 + skill * 0.25);
|
||||
// gunner too close: back off but keep the nose (and the turret) on the enemy
|
||||
if (style === 'gunner' && t && dist < ((t.type === 'flamer' || t.type === 'zapper') ? 1.4 : 2.8)) cmd = { turn: cmd.turn, throttle: -0.7 };
|
||||
|
||||
// avoid hazards in front (skilled robots look further)
|
||||
const look = 0.9 + skill * 1.0, fx = Math.cos(me.a), fz = Math.sin(me.a);
|
||||
const dng = danger(s, me.x + fx * look, me.z + fz * look, me);
|
||||
const dng = danger(s, me.x + fx * look, me.z + fz * look, me); // includes blocks + oil now
|
||||
// enemy right in front and closer than the hazard: keep attacking (it lands in there, not me)
|
||||
const enemyAhead = dist < look + me.st.rad + e.st.rad && Math.abs(wrap(Math.atan2(e.z - me.z, e.x - me.x) - me.a)) < 0.6;
|
||||
if (dng && !enemyAhead && (dng === 3 || dist > 2.2) && rand() < 0.3 + skill * 0.6) {
|
||||
@@ -85,7 +86,7 @@
|
||||
const pushing = style === 'pusher' && s.pitOpen >= 1;
|
||||
contact = rammer && !pushing && dist < me.st.rad + e.st.rad + 0.3 ? contact + react : 0;
|
||||
// only back off with room behind (no spike wall, no trap)
|
||||
const half = A().half - me.st.rad - 0.4;
|
||||
const half = s.arena.half - me.st.rad - 0.4;
|
||||
const bx = me.x - fx * 1.4, bz = me.z - fz * 1.4;
|
||||
const roomBehind = Math.abs(bx) < half && Math.abs(bz) < half && !danger(s, bx, bz, me);
|
||||
if (contact > 0.45 && retreat <= 0 && roomBehind && rand() < 0.25 + skill * 0.7) { retreat = 0.35 + rand() * 0.3; contact = 0; }
|
||||
@@ -101,12 +102,18 @@
|
||||
const out = { throttle: h.throttle, turn: h.turn, fire: false, fire2: false };
|
||||
if (style === 'dummy') return out;
|
||||
if (w) {
|
||||
if (w.type === 'spinner') out.fire = dist < 6;
|
||||
if (w.type === 'spinner' || w.type === 'vspinner') out.fire = dist < 6;
|
||||
else if (w.type === 'lifter') out.fire = inZ && rand() < 0.5 + skill * 0.5;
|
||||
else if (w.type === 'saw') out.fire = dist < 2.6;
|
||||
else if (w.type === 'wedge') out.fire = dist > 1.6 && dist < 4.5 && Math.abs(wrap(Math.atan2(e.z - me.z, e.x - me.x) - me.a)) < 0.25 && rand() < 0.08 + skill * 0.1;
|
||||
else out.fire = inZ && rand() < 0.25 + skill * 0.7;
|
||||
}
|
||||
if (t) out.fire2 = dist < t.range * (t.type === 'flamer' ? 1.05 : 0.9);
|
||||
if (t) {
|
||||
const ahead = Math.abs(wrap(Math.atan2(e.z - me.z, e.x - me.x) - me.a));
|
||||
const close = t.type === 'flamer' || t.type === 'zapper';
|
||||
out.fire2 = dist < t.range * (close ? 1.05 : 0.9) && ahead < (close ? 0.5 : 0.3);
|
||||
}
|
||||
if (me.st.gadget) out.fire3 = RC.Combat.wantGadget(s, me, e);
|
||||
return out;
|
||||
}
|
||||
return { think };
|
||||
@@ -115,21 +122,21 @@
|
||||
const pal = (body, accent) => ({ body, accent });
|
||||
RC.LEAGUE = [
|
||||
{ id: 'rustbucket', name: 'Rustbucket', style: 'brawler', skill: 0.1, prize: 250,
|
||||
build: { chassis: 'crate', motor: 'sparky', wheels: 'rubber', battery: 'lead', armour: null, weapon: 'wedge', tower: null }, paint: pal(0x8a5a3a, 0xd9a066) },
|
||||
build: { chassis: 'cage', motor: 'sparky', wheels: 'rubber', battery: 'lead', armour: null, weapon: 'wedge', tower: null }, paint: pal(0x8a5a3a, 0xd9a066) },
|
||||
{ id: 'tintoad', name: 'Tin Toad', style: 'pusher', skill: 0.2, prize: 330,
|
||||
build: { chassis: 'doorstop', motor: 'sparky', wheels: 'rubber', battery: 'lead', armour: null, weapon: 'wedge', tower: null }, paint: pal(0x5d8a3a, 0xc8e070) },
|
||||
{ id: 'buzzkill', name: 'Buzzkill', style: 'brawler', skill: 0.3, prize: 430,
|
||||
build: { chassis: 'crate', motor: 'sparky', wheels: 'rubber', battery: 'lead', armour: null, weapon: 'saw', tower: null }, paint: pal(0xd8b020, 0x202020) },
|
||||
build: { chassis: 'hexpod', motor: 'sparky', wheels: 'rubber', battery: 'lead', armour: null, weapon: 'saw', tower: null }, paint: pal(0xd8b020, 0x202020) },
|
||||
{ id: 'flapjack', name: 'Flapjack', style: 'flanker', skill: 0.38, prize: 560,
|
||||
build: { chassis: 'doorstop', motor: 'sparky', wheels: 'bigtyre', battery: 'lead', armour: null, weapon: 'flipper', tower: null }, paint: pal(0x2a6fd8, 0xffffff) },
|
||||
build: { chassis: 'fang', motor: 'sparky', wheels: 'bigtyre', battery: 'lead', armour: null, weapon: 'flipper', tower: null }, paint: pal(0x2a6fd8, 0xffffff) },
|
||||
{ id: 'pincer', name: 'Pincer', style: 'pusher', skill: 0.55, prize: 700,
|
||||
build: { chassis: 'bulwark', motor: 'bulldog', wheels: 'tracks', battery: 'nicd', armour: 'steel', weapon: 'crusher', tower: null }, paint: pal(0xc0392b, 0xf0c040) },
|
||||
build: { chassis: 'boiler', motor: 'bulldog', wheels: 'tracks', battery: 'lipo', armour: 'steel', weapon: 'crusher', tower: null, gadget: 'repair' }, paint: pal(0xc0392b, 0xf0c040) },
|
||||
{ id: 'thunderclap', name: 'Thunderclap', style: 'brawler', skill: 0.65, prize: 880,
|
||||
build: { chassis: 'bulwark', motor: 'hornet', wheels: 'bigtyre', battery: 'nicd', armour: 'titan', weapon: 'hammer', tower: 'flamer' }, paint: pal(0x6a3fb0, 0xffa020) },
|
||||
build: { chassis: 'plough', motor: 'hornet', wheels: 'bigtyre', battery: 'lipo', armour: 'titan', weapon: 'hammer', tower: 'flamer', gadget: 'shield' }, paint: pal(0x6a3fb0, 0xffa020) },
|
||||
{ id: 'gravedigger', name: 'Gravedigger', style: 'brawler', skill: 0.8, prize: 1100,
|
||||
build: { chassis: 'scarab', motor: 'hornet', wheels: 'tracks', battery: 'lipo', armour: 'titan', weapon: 'flipper', tower: 'rockets' }, paint: pal(0x2b2f36, 0x50e080) },
|
||||
build: { chassis: 'scarab', motor: 'hornet', wheels: 'tracks', battery: 'lipo', armour: 'titan', weapon: 'flipper', tower: 'rockets', gadget: 'turbo' }, paint: pal(0x2b2f36, 0x50e080) },
|
||||
{ id: 'overlord', name: 'Overlord', style: 'flanker', skill: 0.95, prize: 1450,
|
||||
build: { chassis: 'scarab', motor: 'comet', wheels: 'rubber', battery: 'lipo', armour: 'steel', weapon: 'spinner', tower: null }, paint: pal(0x101418, 0xff3030) },
|
||||
build: { chassis: 'discus', motor: 'comet', wheels: 'rubber', battery: 'lipo', armour: 'steel', weapon: 'spinner', tower: null, gadget: 'righter' }, paint: pal(0x101418, 0xff3030) },
|
||||
];
|
||||
RC.DUMMY = { id: 'dummy', name: 'Dummy', style: 'dummy', skill: 0, prize: 0,
|
||||
build: { chassis: 'crate', motor: 'sparky', wheels: 'rubber', battery: 'lead', armour: 'steel', weapon: null, tower: null }, paint: pal(0x8c8c8c, 0xff7a1a) };
|
||||
|
||||
93
game/assets/Fonts/OFL.txt
Normal file
@@ -0,0 +1,93 @@
|
||||
Copyright (c) 2011-2012, Jovanny Lemonad (jovanny.ru), with Reserved Font Name "Russo"
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
BIN
game/assets/Fonts/RussoOne-Regular.ttf
Normal file
BIN
game/assets/Sprites/logo.png
Normal file
|
After Width: | Height: | Size: 620 KiB |
BIN
game/assets/Sprites/logo_emblem.png
Normal file
|
After Width: | Height: | Size: 408 KiB |
BIN
game/assets/Sprites/part_boiler.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
game/assets/Sprites/part_buffer.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
game/assets/Sprites/part_cage.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
game/assets/Sprites/part_ceramic.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
game/assets/Sprites/part_discus.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
game/assets/Sprites/part_drill.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
game/assets/Sprites/part_drum.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
game/assets/Sprites/part_drumwh.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
game/assets/Sprites/part_emp.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
game/assets/Sprites/part_fang.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
game/assets/Sprites/part_hexpod.png
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
game/assets/Sprites/part_hover.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
game/assets/Sprites/part_lance.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
game/assets/Sprites/part_launcher.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
game/assets/Sprites/part_lifter.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
game/assets/Sprites/part_mace.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
game/assets/Sprites/part_mesh.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
game/assets/Sprites/part_mortar.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
game/assets/Sprites/part_omni.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
game/assets/Sprites/part_plough.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
game/assets/Sprites/part_repair.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
game/assets/Sprites/part_righter.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
game/assets/Sprites/part_shield.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
game/assets/Sprites/part_spiked.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
game/assets/Sprites/part_studs.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
game/assets/Sprites/part_swarm.png
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
game/assets/Sprites/part_turbo.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
game/assets/Sprites/part_vdisc.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
game/assets/Sprites/part_zapper.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
game/assets/Sprites/slot_gadget.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
340
game/combat.js
@@ -15,10 +15,15 @@
|
||||
// Arena definitions. `half` = floor from -half..half. Hazards scale with the size. The active arena is
|
||||
// RC.ARENA; a fight snapshots it into s.arena so several arenas can exist. render3d.js reads s.arena.
|
||||
function arena(o) {
|
||||
const h = o.half, g = h - 1.75; // guardian corners
|
||||
const h = o.half, shape = o.shape || 'square';
|
||||
// guardians sit in the corners of a square arena; on a round/octagon floor they move inwards
|
||||
// along the diagonal, otherwise they would stand outside the wall
|
||||
const g = (h - 1.75) * (shape === 'square' ? 1 : shape === 'round' ? 0.7 : 0.66);
|
||||
return {
|
||||
id: o.id, name: o.name, theme: o.theme || 'steel', half: h,
|
||||
duration: 120, pitOpensAt: 60,
|
||||
shape: o.shape || 'square', // square | octagon | round
|
||||
blocks: o.blocks || [], belts: o.belts || [], oil: o.oil || [], rams: o.rams || [],
|
||||
duration: 120, pitOpensAt: o.pitOpensAt || 60,
|
||||
pit: { x: 0, z: o.pitZ != null ? o.pitZ : h * 0.52, hw: o.pitW || 1.35, hd: o.pitW || 1.35 },
|
||||
saws: o.saws, flames: o.flames,
|
||||
press: { x: g, z: -g, hw: 1.6, hd: 1.6 }, // guardian 1: forge press (corner)
|
||||
@@ -28,17 +33,49 @@
|
||||
}
|
||||
const saw = (x, z, phase) => ({ x, z, r: 0.95, period: 6, on: 2.2, phase });
|
||||
const flame = (x, z, phase) => ({ x, z, hw: 0.9, hd: 0.9, period: 7, on: 1.8, phase });
|
||||
const saw2 = saw, flame2 = flame;
|
||||
const block = (kind, x, z, hw, hd, h2) => ({ kind, x, z, hw, hd, h: h2 || 0.8 });
|
||||
const belt = (x, z, hw, hd, ax, az, force) => ({ x, z, hw, hd, ax, az, force });
|
||||
const ram = (x, z, hw, hd, nx, nz, phase) => ({ x, z, hw, hd, nx, nz, period: 5, on: 1.3, phase });
|
||||
RC.ARENAS = [
|
||||
arena({ id: 'workshop', name: 'Workshop Pit', theme: 'steel', half: 8,
|
||||
// tight starter pit: two scrap heaps are the only cover
|
||||
arena({ id: 'workshop', name: 'Workshop Pit', theme: 'steel', half: 8, shape: 'square',
|
||||
saws: [saw(-3.2, -3.4, 0), saw(3.2, -3.4, 3)],
|
||||
flames: [flame(-2.7, 3.3, 1), flame(2.7, 3.3, 4.5)] }),
|
||||
arena({ id: 'foundry', name: 'The Foundry', theme: 'lava', half: 12, pitW: 1.7,
|
||||
flames: [flame(-2.7, 3.3, 1), flame(2.7, 3.3, 4.5)],
|
||||
blocks: [block('scrap', -2.7, -1.2, 0.8, 0.8), block('scrap', 2.7, -1.2, 0.8, 0.8)] }),
|
||||
// wreck yard: lots of cover and two oil slicks that kill your steering
|
||||
arena({ id: 'scrapyard', name: 'Scrapyard', theme: 'steel', half: 10, shape: 'square', pitW: 1.5,
|
||||
saws: [saw(-4, -4, 0), saw(4, -4, 2.5), saw(0, 4.5, 1.5)],
|
||||
flames: [flame(-5.5, 2, 0), flame(5.5, 2, 3), flame(0, -6, 2)],
|
||||
blocks: [block('scrap', -3.8, -1.5, 1.0, 0.9, 1.0), block('scrap', 3.8, -1.5, 1.0, 0.9, 1.0),
|
||||
block('scrap', 0, -5.2, 1.4, 0.8, 0.9), block('crate', -2.8, 3.0, 0.6, 0.6, 0.7), block('crate', 2.8, 3.0, 0.6, 0.6, 0.7)],
|
||||
oil: [{ x: -2.4, z: 1.0, r: 1.6 }, { x: 2.6, z: -3.4, r: 1.5 }] }),
|
||||
// foundry: a belt drags you sideways into the flame channel
|
||||
arena({ id: 'foundry', name: 'The Foundry', theme: 'lava', half: 12, shape: 'octagon', pitW: 1.7,
|
||||
saws: [saw(-5, -4.5, 0), saw(5, -4.5, 3), saw(0, 4.5, 1.5)],
|
||||
flames: [flame(-4.5, 1, 0), flame(4.5, 1, 3.5), flame(0, -7.5, 2), flame(-7, 6, 5)] }),
|
||||
arena({ id: 'arena64', name: 'Mega Dome', theme: 'blue', half: 16, pitW: 2.1,
|
||||
flames: [flame(-4.5, 1, 0), flame(4.5, 1, 3.5), flame(0, -7.5, 2), flame(-7, 6, 5)],
|
||||
blocks: [block('barrier', -6.2, -5, 1.3, 0.4, 0.6), block('barrier', 6.2, -5, 1.3, 0.4, 0.6)],
|
||||
belts: [belt(0, 1, 4.0, 1.1, 1, 0, 9)] }),
|
||||
// crucible: one pillar in the middle, two wall rams punching inwards
|
||||
arena({ id: 'crucible', name: 'The Crucible', theme: 'lava', half: 14, shape: 'round', pitW: 1.9,
|
||||
saws: [saw(-5.5, -5, 0), saw(5.5, -5, 3), saw(-5.5, 5, 1.5), saw(5.5, 5, 4.5)],
|
||||
flames: [flame(-6, 1.5, 0), flame(6, 1.5, 3), flame(0, 8, 2), flame(0, -8, 4.5)],
|
||||
blocks: [block('pillar', 0, 0, 1.1, 1.1, 1.8)],
|
||||
rams: [ram(-11.8, 0, 1.5, 2.2, 1, 0, 0), ram(11.8, 0, 1.5, 2.2, -1, 0, 2.5)] }),
|
||||
// dome: four pillars to duck behind, and the pit opens early
|
||||
arena({ id: 'arena64', name: 'Mega Dome', theme: 'blue', half: 16, shape: 'octagon', pitW: 2.1, pitOpensAt: 80,
|
||||
saws: [saw(-6.5, -6, 0), saw(6.5, -6, 3), saw(-6.5, 6, 1.5), saw(6.5, 6, 4.5), saw(0, 0, 2)],
|
||||
flames: [flame(-8, 2, 0), flame(8, 2, 2), flame(0, 9, 4), flame(0, -9, 1), flame(-10, -4, 3), flame(10, -4, 5)] }),
|
||||
flames: [flame(-8, 2, 0), flame(8, 2, 2), flame(0, 9, 4), flame(0, -9, 1), flame(-10, -4, 3), flame(10, -4, 5)],
|
||||
blocks: [block('pillar', -5, -5, 0.9, 0.9, 2.0), block('pillar', 5, -5, 0.9, 0.9, 2.0),
|
||||
block('pillar', -5, 5, 0.9, 0.9, 2.0), block('pillar', 5, 5, 0.9, 0.9, 2.0)] }),
|
||||
// colosseum: huge, a wreck mound in the centre and two belts feeding the pit
|
||||
arena({ id: 'colosseum', name: 'Grand Colosseum', theme: 'blue', half: 20, shape: 'round', pitW: 2.4,
|
||||
saws: [saw(-8, -7, 0), saw(8, -7, 3), saw(-8, 7, 1.5), saw(8, 7, 4.5), saw(0, -11, 3.5)],
|
||||
flames: [flame(-10, 2, 0), flame(10, 2, 2), flame(0, 13, 4), flame(0, -13, 1), flame(-13, -5, 3), flame(13, -5, 5)],
|
||||
blocks: [block('scrap', 0, 0, 2.0, 1.6, 1.3), block('crate', -7, -2, 0.8, 0.8, 0.9), block('crate', 7, -2, 0.8, 0.8, 0.9)],
|
||||
belts: [belt(-3.6, 6.5, 1.3, 3.0, 0, 1, 9), belt(3.6, 6.5, 1.3, 3.0, 0, 1, 9)] }),
|
||||
];
|
||||
|
||||
let ARENA = RC.ARENAS[0];
|
||||
RC.ARENA = ARENA;
|
||||
RC.setArena = id => { ARENA = RC.ARENAS.find(a => a.id === id) || RC.ARENAS[0]; RC.ARENA = ARENA; return ARENA; };
|
||||
@@ -50,6 +87,44 @@
|
||||
let s = seed >>> 0 || 1;
|
||||
return () => { s = (s + 0x6d2b79f5) >>> 0; let t = s; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; };
|
||||
}
|
||||
// Keep a point inside the arena outline. null = clear of the wall, otherwise the corrected
|
||||
// spot plus the wall normal pointing INTO the arena. Used by the physics, the AI and the map.
|
||||
function wallPush(A, x, z, rad) {
|
||||
const lim = A.half - rad;
|
||||
if (A.shape === 'round') {
|
||||
const d = Math.hypot(x, z);
|
||||
if (d <= lim || d < 1e-6) return null;
|
||||
return { x: (x / d) * lim, z: (z / d) * lim, nx: -x / d, nz: -z / d };
|
||||
}
|
||||
let cx = x, cz = z, nx = 0, nz = 0, hit = false;
|
||||
if (cx > lim) { cx = lim; nx = -1; hit = true; } else if (cx < -lim) { cx = -lim; nx = 1; hit = true; }
|
||||
if (cz > lim) { cz = lim; nz = -1; hit = true; } else if (cz < -lim) { cz = -lim; nz = 1; hit = true; }
|
||||
if (A.shape === 'octagon') { // four corner cuts: |x| + |z| <= dlim
|
||||
const dlim = lim * 1.34, sx = Math.sign(cx) || 1, sz = Math.sign(cz) || 1;
|
||||
const over = Math.abs(cx) + Math.abs(cz) - dlim;
|
||||
if (over > 0) {
|
||||
cx -= sx * over / 2; cz -= sz * over / 2;
|
||||
nx = -sx * Math.SQRT1_2; nz = -sz * Math.SQRT1_2; hit = true;
|
||||
}
|
||||
}
|
||||
if (!hit) return null;
|
||||
const len = Math.hypot(nx, nz) || 1;
|
||||
return { x: cx, z: cz, nx: nx / len, nz: nz / len };
|
||||
}
|
||||
// Is this spot inside a static obstacle? Returns the push-out normal, or null.
|
||||
function blockPush(A, r, rad) {
|
||||
for (const b of A.blocks) {
|
||||
const dx = r.x - b.x, dz = r.z - b.z;
|
||||
const ox = b.hw + rad - Math.abs(dx), oz = b.hd + rad - Math.abs(dz);
|
||||
if (ox <= 0 || oz <= 0) continue;
|
||||
if (ox < oz) { const sx = Math.sign(dx) || 1; r.x = b.x + sx * (b.hw + rad); return { nx: sx, nz: 0 }; }
|
||||
const sz = Math.sign(dz) || 1; r.z = b.z + sz * (b.hd + rad); return { nx: 0, nz: sz };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
RC.wallPush = wallPush;
|
||||
RC.inBlock = (A, x, z, m = 0) => A.blocks.some(b => Math.abs(x - b.x) < b.hw + m && Math.abs(z - b.z) < b.hd + m);
|
||||
|
||||
const inRect = (o, x, z, m = 0) => Math.abs(x - o.x) < o.hw + m && Math.abs(z - o.z) < o.hd + m;
|
||||
const hazardOn = (h, t) => ((t + h.phase) % h.period) < h.on;
|
||||
RC.hazardOn = hazardOn;
|
||||
@@ -60,6 +135,9 @@
|
||||
i, name, st, x: p.x, z: p.z, a: p.a, vx: 0, vz: 0, av: 0, y: 0, vy: 0,
|
||||
hp: st.hp, maxHp: st.hp, dead: false, out: null, fall: 0,
|
||||
flipped: 0, stun: 0, lifted: 0, grabbedBy: null, grab: 0,
|
||||
shield: 0, gcd: 0, gUses: st.gadget && st.gadget.charges || 0,
|
||||
lost: { armour: false, wheels: false, weapon: false, tower: false }, // parts torn off during the fight
|
||||
onOil: false, // standing in a slick: less grip, lazy steering
|
||||
cd: 0, cd2: 0, spin: 0, swing: 0, flipAnim: 0, boost: 0, sawOn: false, flameOn: false, gunOn: false,
|
||||
turretA: p.a, dealt: 0, taken: 0, pressT: 0, craneT: 0, fx: 0,
|
||||
};
|
||||
@@ -78,6 +156,28 @@
|
||||
return s;
|
||||
}
|
||||
|
||||
// a part that broke off no longer works (and bare metal takes more damage)
|
||||
const weaponOf = r => (r.lost.weapon ? null : r.st.weapon);
|
||||
const towerOf = r => (r.lost.tower ? null : r.st.tower);
|
||||
const reduceOf = r => (r.lost.armour ? r.st.reduce * 0.3 : r.st.reduce);
|
||||
|
||||
// battle damage: at these shares of health the next hit tears a part off (no randomness,
|
||||
// so both sides of an online fight and the tests see exactly the same thing)
|
||||
const BREAK_AT = [['armour', 0.6], ['wheels', 0.4], ['weapon', 0.25], ['tower', 0.18]];
|
||||
function breakCheck(s, r) {
|
||||
if (r.dead || r.out) return;
|
||||
const f = r.hp / r.maxHp;
|
||||
for (const [part, at] of BREAK_AT) {
|
||||
if (r.lost[part] || f >= at) continue;
|
||||
if (part === 'armour' && !r.st.armour) continue;
|
||||
if (part === 'weapon' && !r.st.weapon) continue;
|
||||
if (part === 'tower' && !r.st.tower) continue;
|
||||
r.lost[part] = true;
|
||||
if (part === 'weapon') { r.spin = 0; r.swing = 0; if (r.grab > 0) release(s, r, s.robots[1 - r.i]); }
|
||||
s.events.push({ type: 'broke', who: r.i, part, x: r.x, z: r.z });
|
||||
}
|
||||
}
|
||||
|
||||
const fwd = r => [Math.cos(r.a), Math.sin(r.a)];
|
||||
// enemy position in my frame: [forward, side]
|
||||
function local(me, e) {
|
||||
@@ -86,7 +186,7 @@
|
||||
}
|
||||
function inZone(s, me, e, extra = 0) {
|
||||
if (e.out || me.out) return false;
|
||||
const w = me.st.weapon; if (!w) return false;
|
||||
const w = weaponOf(me); if (!w) return false;
|
||||
const [lf, ls] = local(me, e);
|
||||
return lf > 0 && lf < me.st.len / 2 + w.reach + e.st.rad * 0.75 + extra && Math.abs(ls) < me.st.wid / 2 + e.st.rad * 0.55;
|
||||
}
|
||||
@@ -101,7 +201,8 @@
|
||||
|
||||
function damage(s, target, amount, src, opt = {}) {
|
||||
if (target.dead || target.out || amount <= 0 || s.result) return 0;
|
||||
let d = amount * (1 - target.st.reduce * (1 - (opt.pierce || 0)));
|
||||
let d = amount * (1 - reduceOf(target) * (1 - (opt.pierce || 0)));
|
||||
if (target.shield > 0 && target.st.gadget) d *= (1 - (target.st.gadget.reduce || 0.6)); // deflector field
|
||||
const from = opt.from || src; // where the hit comes from (rockets: impact point)
|
||||
if (from && !opt.noZone) d *= zoneMul(target, from.x, from.z);
|
||||
d = Math.min(d, target.hp);
|
||||
@@ -109,6 +210,7 @@
|
||||
// judges: hazard damage counts for the opponent (pushing into traps pays off)
|
||||
if (src) src.dealt += d; else s.robots[1 - target.i].dealt += d;
|
||||
if (d >= 0.5 || opt.tick) s.events.push({ type: 'dmg', who: target.i, amount: d, x: target.x, z: target.z, tick: !!opt.tick, kind: opt.kind || 'hit' });
|
||||
breakCheck(s, target);
|
||||
if (target.hp <= 0.001) {
|
||||
target.hp = 0; target.dead = true;
|
||||
s.events.push({ type: 'ko', who: target.i, x: target.x, z: target.z });
|
||||
@@ -138,6 +240,7 @@
|
||||
|
||||
for (let k = 0; k < 2; k++) drive(s, R[k], R[1 - k], (s.result ? null : inputs[k]) || {}, dt);
|
||||
collide(s, R[0], R[1], dt);
|
||||
for (let k = 0; k < 2; k++) gadgets(s, R[k], R[1 - k], (s.result ? null : inputs[k]) || {}, dt);
|
||||
for (let k = 0; k < 2; k++) weapons(s, R[k], R[1 - k], (s.result ? null : inputs[k]) || {}, dt);
|
||||
rockets(s, dt);
|
||||
hazards(s, dt);
|
||||
@@ -165,17 +268,19 @@
|
||||
let vf = r.vx * fx + r.vz * fz, vs = -r.vx * fz + r.vz * fx;
|
||||
if (canDrive) {
|
||||
const thr = clamp(inp.throttle || 0, -1, 1), trn = clamp(inp.turn || 0, -1, 1);
|
||||
let top = st.top * (r.boost > 0 ? 1.65 : 1) * (r.grab > 0 ? 0.6 : 1) * (thr < 0 ? 0.75 : 1);
|
||||
const target = thr * top, acc = st.accel * (r.boost > 0 ? 2 : 1);
|
||||
const hurt = r.lost.wheels ? 0.75 : 1; // burst wheel: slower, clumsier
|
||||
const oil = r.onOil ? 0.55 : 1; // oil slick: hardly any steering
|
||||
let top = st.top * hurt * (r.boost > 0 ? 1.65 : 1) * (r.grab > 0 ? 0.6 : 1) * (thr < 0 ? 0.75 : 1);
|
||||
const target = thr * top, acc = st.accel * (r.lost.wheels ? 0.85 : 1) * (r.boost > 0 ? 2 : 1);
|
||||
const braking = Math.abs(target) < Math.abs(vf) || target * vf < 0;
|
||||
const rate = acc * (braking ? 1.6 : 1) * dt;
|
||||
vf += clamp(target - vf, -rate, rate);
|
||||
r.av += (trn * st.turn - r.av) * Math.min(1, 12 * dt);
|
||||
r.av += (trn * st.turn * (r.lost.wheels ? 0.8 : 1) * oil - r.av) * Math.min(1, 12 * dt);
|
||||
} else {
|
||||
r.av *= Math.max(0, 1 - 6 * dt);
|
||||
}
|
||||
if (grounded && !held) {
|
||||
vs *= Math.max(0, 1 - st.grip * dt);
|
||||
vs *= Math.max(0, 1 - st.grip * (r.onOil ? 0.3 : 1) * dt);
|
||||
if (!canDrive) vf *= Math.max(0, 1 - 2.5 * dt);
|
||||
else if (!(inp.throttle)) vf *= Math.max(0, 1 - 3 * dt);
|
||||
}
|
||||
@@ -195,13 +300,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
// spike walls
|
||||
const lim = s.arena.half - st.rad * 0.9;
|
||||
for (const ax of ['x', 'z']) {
|
||||
const vk = ax === 'x' ? 'vx' : 'vz';
|
||||
if (Math.abs(r[ax]) > lim) {
|
||||
const sgn = Math.sign(r[ax]), vn = r[vk] * sgn;
|
||||
r[ax] = sgn * lim;
|
||||
// spike walls (follow the arena outline: square, octagon or round)
|
||||
const rad = st.rad * 0.9;
|
||||
const w = wallPush(s.arena, r.x, r.z, rad);
|
||||
if (w) {
|
||||
r.x = w.x; r.z = w.z;
|
||||
const vn = -(r.vx * w.nx + r.vz * w.nz); // speed straight into the wall
|
||||
if (vn > 0) {
|
||||
if (vn > 1.8 && !r.out) {
|
||||
s.events.push({ type: 'wall', who: r.i, x: r.x, z: r.z, speed: vn });
|
||||
@@ -209,9 +313,20 @@
|
||||
// slammed into the spikes hard -> bounces up and can land on its back
|
||||
if (vn > 3.5 && r.y < 0.05 && !r.st.invertible && !r.st.lowProfile && s.rand() < 0.3) { r.vy = Math.max(r.vy, 2); r.flipped = 2.2; r.av += (s.rand() - 0.5) * 6; }
|
||||
}
|
||||
r[vk] = -r[vk] * 0.45;
|
||||
r.vx += w.nx * vn * 1.45; r.vz += w.nz * vn * 1.45; // bounce (0.45 restitution)
|
||||
}
|
||||
}
|
||||
// static obstacles: drive into one and you stop, hit it hard and it hurts
|
||||
const bp = blockPush(s.arena, r, rad);
|
||||
if (bp) {
|
||||
const vn = -(r.vx * bp.nx + r.vz * bp.nz);
|
||||
if (vn > 0) {
|
||||
if (vn > 2.2 && !r.out) {
|
||||
s.events.push({ type: 'wall', who: r.i, x: r.x, z: r.z, speed: vn });
|
||||
damage(s, r, (vn - 2.2) * 2.6, null, { kind: 'ram' });
|
||||
}
|
||||
r.vx += bp.nx * vn * 1.3; r.vz += bp.nz * vn * 1.3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +356,7 @@
|
||||
const facing = fx * sx + fz * sz;
|
||||
const myV = me.vx * sx + me.vz * sz;
|
||||
if (facing > 0.55 && myV > 1.2) {
|
||||
const w = me.st.weapon;
|
||||
const w = weaponOf(me);
|
||||
const ram = w && w.type === 'wedge' ? w.ram : 1;
|
||||
damage(s, e, (impact - 1) * 2.2 * ram, me, { kind: 'ram' });
|
||||
// a wedge scoops lighter robots up; any hard enough ram can send one tumbling onto its roof
|
||||
@@ -259,7 +374,7 @@
|
||||
|
||||
function weapons(s, r, e, inp, dt) {
|
||||
const ok = !r.dead && !r.out && r.lifted <= 0 && r.grabbedBy === null && r.flipped <= 0;
|
||||
const w = r.st.weapon, [fx, fz] = fwd(r);
|
||||
const w = weaponOf(r), [fx, fz] = fwd(r);
|
||||
r.sawOn = false; r.flameOn = false; r.gunOn = false;
|
||||
if (r.swing > 0) { // hammer comes down
|
||||
r.swing -= dt;
|
||||
@@ -314,6 +429,33 @@
|
||||
s.events.push({ type: 'grab', who: r.i, x: e.x, z: e.z });
|
||||
}
|
||||
break;
|
||||
case 'lifter':
|
||||
// scoop: tips the enemy up again and again (short cooldown) - made for shoving into the pit
|
||||
if (inp.fire && r.cd <= 0) {
|
||||
r.cd = w.cd; r.flipAnim = 0.3;
|
||||
s.events.push({ type: 'flip', who: r.i, x: r.x + fx, z: r.z + fz });
|
||||
if (inZone(s, r, e) && e.y < 0.2 && e.grabbedBy === null && e.lifted <= 0) {
|
||||
const light = Math.sqrt(70 / e.st.mass);
|
||||
e.vy = Math.max(e.vy, w.launch * light * 0.8);
|
||||
e.vx += fx * 1.6 * light; e.vz += fz * 1.6 * light;
|
||||
e.stun = Math.max(e.stun, 0.3); // wheels off the floor: no steering
|
||||
damage(s, e, w.dmg, r, { kind: 'flip' });
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'vspinner':
|
||||
// vertical disc: throws the enemy into the air instead of sideways
|
||||
r.spin = inp.fire ? Math.min(1, r.spin + dt / w.spinup) : Math.max(0, r.spin - dt * 0.35);
|
||||
if (r.spin > 0.25 && r.cd <= 0 && inZone(s, r, e)) {
|
||||
const k = r.spin, light = Math.sqrt(70 / e.st.mass);
|
||||
damage(s, e, w.dmg * k, r, { kind: 'spin' });
|
||||
e.vy = Math.max(e.vy, 6.5 * k * light);
|
||||
e.vx += fx * 1.5 * k; e.vz += fz * 1.5 * k; e.av += 7 * k;
|
||||
if (!e.st.invertible && s.rand() < 0.5 * k) e.flipped = 2.2;
|
||||
r.spin *= 0.3; r.cd = 0.35;
|
||||
s.events.push({ type: 'spinhit', who: r.i, x: (r.x + e.x) / 2, z: (r.z + e.z) / 2, k });
|
||||
}
|
||||
break;
|
||||
case 'spinner':
|
||||
r.spin = inp.fire ? Math.min(1, r.spin + dt / w.spinup) : Math.max(0, r.spin - dt * 0.35);
|
||||
if (r.spin > 0.25 && r.cd <= 0 && inZone(s, r, e)) {
|
||||
@@ -327,27 +469,45 @@
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (w && w.type === 'spinner') r.spin = Math.max(0, r.spin - dt * 0.5);
|
||||
} else if (w && (w.type === 'spinner' || w.type === 'vspinner')) r.spin = Math.max(0, r.spin - dt * 0.5);
|
||||
|
||||
// turret: turns towards the enemy by itself
|
||||
const t = r.st.tower;
|
||||
// turret is bolted facing forward: you aim it by turning the robot, it does not track the enemy
|
||||
const t = towerOf(r);
|
||||
if (!t) return;
|
||||
const want = Math.atan2(e.z - r.z, e.x - r.x), diff = wrap(want - r.turretA);
|
||||
r.turretA = wrap(r.turretA + clamp(diff, -3.2 * dt, 3.2 * dt));
|
||||
r.turretA = r.a;
|
||||
if (!ok || !inp.fire2) return;
|
||||
const want = Math.atan2(e.z - r.z, e.x - r.x);
|
||||
const dist = Math.hypot(e.x - r.x, e.z - r.z), aimed = Math.abs(wrap(want - r.turretA));
|
||||
if (t.type === 'flamer') {
|
||||
r.flameOn = true;
|
||||
if (dist < t.range + e.st.rad && aimed < t.cone && !e.out) damage(s, e, t.dps * dt, r, { pierce: 0.5, noZone: true, kind: 'fire', tick: true });
|
||||
} else if (t.type === 'minigun') {
|
||||
r.gunOn = aimed < 0.25;
|
||||
if (r.gunOn && dist < t.range && !e.out) {
|
||||
r.gunOn = true; // always fires straight ahead, hits only what is in front
|
||||
if (aimed < 0.25 && dist < t.range && !e.out) {
|
||||
damage(s, e, t.dps * dt, r, { kind: 'bullet', tick: true });
|
||||
r.fx -= dt; if (r.fx <= 0) { r.fx = 0.08; s.events.push({ type: 'sparks', x: e.x, z: e.z, n: 2, y: 0.4 }); }
|
||||
}
|
||||
} else if (t.type === 'rockets' && r.cd2 <= 0) {
|
||||
} else if (t.type === 'zapper') {
|
||||
r.gunOn = true; // short electric arc straight ahead
|
||||
if (aimed < 0.4 && dist < t.range + e.st.rad && !e.out) {
|
||||
damage(s, e, t.dps * dt, r, { pierce: 0.8, noZone: true, kind: 'bullet', tick: true });
|
||||
e.stun = Math.max(e.stun, 0.12);
|
||||
}
|
||||
} else if (t.type === 'mortar' && r.cd2 <= 0) {
|
||||
r.cd2 = t.cd;
|
||||
s.rockets.push({ owner: r.i, x: r.x, z: r.z, y: r.st.h + 0.45, a: r.turretA, t: 3.2, sp: 6.5 });
|
||||
// lobbed shell: flies a real arc and bursts where it lands
|
||||
const flight = clamp(dist / 9, 0.5, 1.8);
|
||||
s.rockets.push({ kind: 'mortar', owner: r.i, x: r.x, z: r.z, y: r.st.h + 0.5, a: r.turretA,
|
||||
sp: Math.min(dist / flight, 14), vy: 9 * flight, t: 5, dmg: t.dmg, splash: t.splash });
|
||||
s.events.push({ type: 'launch', who: r.i, x: r.x, z: r.z });
|
||||
} else if ((t.type === 'rockets' || t.type === 'swarm') && r.cd2 <= 0) {
|
||||
r.cd2 = t.cd;
|
||||
const swarm = t.type === 'swarm', n = swarm ? (t.shots || 3) : 1;
|
||||
for (let k = 0; k < n; k++) {
|
||||
const spread = swarm ? (k - (n - 1) / 2) * 0.35 : 0;
|
||||
s.rockets.push({ kind: 'rocket', owner: r.i, x: r.x, z: r.z, y: r.st.h + 0.45, a: r.turretA + spread,
|
||||
t: swarm ? 8 : 5, sp: 6.5, max: swarm ? 13 : 11, turn: swarm ? 3.4 : 2.4, dmg: t.dmg });
|
||||
}
|
||||
s.events.push({ type: 'launch', who: r.i, x: r.x, z: r.z });
|
||||
}
|
||||
}
|
||||
@@ -357,21 +517,87 @@
|
||||
if (e.grabbedBy === r.i) { e.grabbedBy = null; }
|
||||
}
|
||||
|
||||
// gadgets (input.fire3): one-shot abilities on a cooldown
|
||||
function gadgets(s, r, e, inp, dt) {
|
||||
r.gcd = Math.max(0, r.gcd - dt);
|
||||
if (r.shield > 0) r.shield = Math.max(0, r.shield - dt);
|
||||
const g = r.st.gadget;
|
||||
if (!g || r.out || r.dead || !inp.fire3 || r.gcd > 0) return;
|
||||
const held = r.lifted > 0 || r.grabbedBy !== null;
|
||||
switch (g.type) {
|
||||
case 'righter': // flip back upright
|
||||
if (r.flipped > 0) { r.flipped = 0; r.av += (s.rand() - 0.5) * 2; }
|
||||
r.gcd = g.cd;
|
||||
s.events.push({ type: 'righted', who: r.i, x: r.x, z: r.z });
|
||||
break;
|
||||
case 'turbo': // speed burst (reuses the boost mechanic)
|
||||
if (held || r.flipped > 0 || r.stun > 0) return;
|
||||
r.boost = Math.max(r.boost, g.dur); r.gcd = g.cd;
|
||||
break;
|
||||
case 'shield': // temporary damage field
|
||||
r.shield = g.dur; r.gcd = g.cd;
|
||||
break;
|
||||
case 'repair': // one charge = flat heal
|
||||
if (r.gUses <= 0) return;
|
||||
r.hp = Math.min(r.maxHp, r.hp + r.maxHp * g.heal); r.gUses--; r.gcd = g.cd;
|
||||
break;
|
||||
case 'emp': // stun the enemy if close
|
||||
r.gcd = g.cd;
|
||||
if (!e.out && Math.hypot(e.x - r.x, e.z - r.z) < g.range + e.st.rad) {
|
||||
e.stun = Math.max(e.stun, g.stun); e.spin = 0; e.boost = 0; e.shield = 0;
|
||||
s.events.push({ type: 'emp_hit', who: e.i, x: e.x, z: e.z });
|
||||
}
|
||||
break;
|
||||
}
|
||||
s.events.push({ type: 'gadget', who: r.i, g: g.type, x: r.x, z: r.z });
|
||||
}
|
||||
|
||||
// should the AI / autofire helper fire the gadget now?
|
||||
function wantGadget(s, me, e) {
|
||||
const g = me.st.gadget;
|
||||
if (!g || me.gcd > 0 || me.out || me.dead) return false;
|
||||
const dist = e.out ? 999 : Math.hypot(e.x - me.x, e.z - me.z);
|
||||
switch (g.type) {
|
||||
case 'righter': return me.flipped > 0;
|
||||
case 'turbo': return me.flipped <= 0 && me.stun <= 0 && dist > 2 && dist < 9;
|
||||
case 'shield': return dist < 3 && me.flipped <= 0;
|
||||
case 'repair': return me.gUses > 0 && me.hp < me.maxHp * 0.45;
|
||||
case 'emp': return !e.out && dist < g.range * 0.9 && (e.boost > 0 || e.spin > 0.2 || dist < 2.5);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function rockets(s, dt) {
|
||||
for (let i = s.rockets.length - 1; i >= 0; i--) {
|
||||
const k = s.rockets[i], tgt = s.robots[1 - k.owner], own = s.robots[k.owner];
|
||||
k.t -= dt;
|
||||
const wall = () => Math.abs(k.x) > s.arena.half || Math.abs(k.z) > s.arena.half;
|
||||
if (k.kind === 'mortar') {
|
||||
// thrown in an arc, bursts on the floor with a blast radius
|
||||
k.vy -= 17 * dt;
|
||||
k.x += Math.cos(k.a) * k.sp * dt; k.z += Math.sin(k.a) * k.sp * dt; k.y += k.vy * dt;
|
||||
const direct = !tgt.out && k.y < 0.9 && Math.hypot(tgt.x - k.x, tgt.z - k.z) < tgt.st.rad + 0.2;
|
||||
if (direct || k.y <= 0.06 || wall() || k.t <= 0) {
|
||||
s.events.push({ type: 'boom', x: k.x, z: k.z, y: Math.max(0.12, k.y), big: true });
|
||||
if (!tgt.out) {
|
||||
const d = Math.hypot(tgt.x - k.x, tgt.z - k.z);
|
||||
if (d < k.splash) damage(s, tgt, k.dmg * (1 - (d / k.splash) * 0.6), own, { from: { x: k.x, z: k.z }, kind: 'rocket' });
|
||||
}
|
||||
s.rockets.splice(i, 1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// seeker: turns after the target and can chase it across the arena
|
||||
const want = Math.atan2(tgt.z - k.z, tgt.x - k.x);
|
||||
if (!tgt.out) k.a = wrap(k.a + clamp(wrap(want - k.a), -2.4 * dt, 2.4 * dt));
|
||||
k.sp = Math.min(11, k.sp + dt * 6);
|
||||
if (!tgt.out) k.a = wrap(k.a + clamp(wrap(want - k.a), -(k.turn || 2.4) * dt, (k.turn || 2.4) * dt));
|
||||
k.sp = Math.min(k.max || 11, k.sp + dt * 6);
|
||||
k.x += Math.cos(k.a) * k.sp * dt; k.z += Math.sin(k.a) * k.sp * dt;
|
||||
k.y += ((tgt.y + 0.35) - k.y) * Math.min(1, dt * 3);
|
||||
const hit = !tgt.out && Math.hypot(tgt.x - k.x, tgt.z - k.z) < tgt.st.rad + 0.1;
|
||||
const wall = Math.abs(k.x) > s.arena.half || Math.abs(k.z) > s.arena.half;
|
||||
if (hit || wall || k.t <= 0) {
|
||||
if (hit || wall() || k.t <= 0) {
|
||||
s.events.push({ type: 'boom', x: k.x, z: k.z, y: k.y });
|
||||
if (hit) {
|
||||
damage(s, tgt, own.st.tower.dmg, own, { from: { x: k.x - Math.cos(k.a), z: k.z - Math.sin(k.a) }, kind: 'rocket' });
|
||||
damage(s, tgt, k.dmg != null ? k.dmg : 17, own, { from: { x: k.x - Math.cos(k.a), z: k.z - Math.sin(k.a) }, kind: 'rocket' });
|
||||
tgt.vx += Math.cos(k.a) * 1.6; tgt.vz += Math.sin(k.a) * 1.6;
|
||||
}
|
||||
s.rockets.splice(i, 1);
|
||||
@@ -394,6 +620,15 @@
|
||||
}
|
||||
// flame grilles
|
||||
for (const h of A.flames) if (ground && hazardOn(h, s.t) && inRect(h, r.x, r.z, r.st.rad * 0.3)) damage(s, r, 14 * dt, null, { pierce: 0.5, kind: 'fire', tick: true });
|
||||
// conveyor belts drag everything that stands on them
|
||||
for (const b of A.belts) if (ground && inRect(b, r.x, r.z, r.st.rad * 0.2)) { r.vx += b.ax * b.force * dt; r.vz += b.az * b.force * dt; }
|
||||
// oil slicks (checked here, used by drive() on the next step)
|
||||
r.onOil = ground && A.oil.some(o => Math.hypot(r.x - o.x, r.z - o.z) < o.r + r.st.rad * 0.4);
|
||||
// wall rams shove anyone loitering in front of them
|
||||
for (const m of A.rams) if (ground && hazardOn(m, s.t) && inRect(m, r.x, r.z, r.st.rad * 0.3)) {
|
||||
r.vx += m.nx * 26 * dt; r.vz += m.nz * 26 * dt;
|
||||
damage(s, r, 9 * dt, null, { kind: 'ram', tick: true });
|
||||
}
|
||||
// pit
|
||||
if (s.pitOpen >= 1 && ground && r.grabbedBy === null && inRect(A.pit, r.x, r.z, -0.15)) {
|
||||
r.out = 'pit'; r.vx *= 0.2; r.vz *= 0.2;
|
||||
@@ -453,6 +688,33 @@
|
||||
}
|
||||
}
|
||||
|
||||
RC.Combat = { create, step, inZone, local };
|
||||
// What the HUD shows per equipped slot (no DOM, so Node tests can check it):
|
||||
// p = share of the cooldown still running (1 = just used, 0 = ready), on = doing its thing right now,
|
||||
// n = charges left where a part has them (repair kit).
|
||||
function cooldowns(r) {
|
||||
const out = [], w = r.st.weapon, t = r.st.tower, g = r.st.gadget;
|
||||
const broke = k => (r.lost && r.lost[k]) || false;
|
||||
const frac = (left, full) => (full > 0 ? clamp(left / full, 0, 1) : 0);
|
||||
if (w) {
|
||||
const e = { slot: 'weapon', id: w.id, p: 0, on: false, broke: broke('weapon') };
|
||||
if (w.type === 'saw') e.on = !!r.sawOn;
|
||||
else if (w.type === 'spinner' || w.type === 'vspinner') { e.p = 1 - clamp(r.spin, 0, 1); e.on = r.spin > 0.25; }
|
||||
else {
|
||||
e.p = frac(r.cd, w.cd);
|
||||
e.on = (w.type === 'hammer' && r.swing > 0) || (w.type === 'crusher' && r.grab > 0) || (w.type === 'wedge' && r.boost > 0);
|
||||
}
|
||||
out.push(e);
|
||||
}
|
||||
if (t) {
|
||||
const e = { slot: 'tower', id: t.id, p: 0, on: false, broke: broke('tower') };
|
||||
if (t.type === 'rockets' || t.type === 'mortar' || t.type === 'swarm') e.p = frac(r.cd2, t.cd);
|
||||
else e.on = t.type === 'flamer' ? !!r.flameOn : !!r.gunOn; // minigun + zapper
|
||||
out.push(e);
|
||||
}
|
||||
if (g) out.push({ slot: 'gadget', id: g.id, p: frac(r.gcd, g.cd), on: r.shield > 0 || (g.type === 'turbo' && r.boost > 0), n: g.charges ? r.gUses : undefined });
|
||||
return out;
|
||||
}
|
||||
|
||||
RC.Combat = { create, step, inZone, local, wantGadget, cooldowns };
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = RC;
|
||||
})(typeof window !== 'undefined' ? window : globalThis);
|
||||
|
||||
281
game/game.js
@@ -5,7 +5,7 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
const $ = Kit.$;
|
||||
const W = 960, H = 540; // design size of the stage
|
||||
const W = 1280, H = 720; // design size of the stage (16:9, higher res = denser UI)
|
||||
const ID = 'robotclash'; // localStorage prefix
|
||||
|
||||
// Paste the Firebase Realtime Database URL here to switch the online fame ranking on
|
||||
@@ -26,7 +26,7 @@
|
||||
const t = L.t;
|
||||
const store = Kit.store(ID);
|
||||
// steer: 'simple' (keys = screen direction) | 'tank' · diff: 'easy' | 'normal' | 'hard' · autofire: weapon fires by itself in reach
|
||||
const settings = Object.assign({ gfx: 'high', intro: true, steer: 'tank', diff: 'easy', autofire: true, cam: 'fpv', arena: 'random' }, store.get('settings', {}));
|
||||
const settings = Object.assign({ gfx: 'medium', intro: true, steer: 'tank', diff: 'easy', autofire: true, cam: 'fpv', arena: 'random' }, store.get('settings', {}));
|
||||
// v2: Michael found "simple" steering worse -> tank is the default again, old saved choice reset once
|
||||
// v3: fights start in first person (cockpit) -> old saved camera reset once
|
||||
if (!settings.v || settings.v < 2) settings.steer = 'tank';
|
||||
@@ -39,9 +39,18 @@
|
||||
money: 800, fame: 0, best: 0, season: 1, beaten: 0, wins: 0, losses: 0, games: 0,
|
||||
owned: Object.values(RC.STARTER).filter(Boolean), build: Object.assign({}, RC.STARTER),
|
||||
paint: { body: 0xff7a1a, accent: 0x15171b }, robotName: 'Clank', flag: 'XX', tutorialSeen: false,
|
||||
robots: [], active: 0, // hangar: saved robot builds; the active one mirrors build/paint/robotName
|
||||
});
|
||||
const MAX_ROBOTS = 6;
|
||||
const newRobotDef = n => ({ name: n || 'Robot', build: Object.assign({}, RC.STARTER), paint: { body: 0xff7a1a, accent: 0x15171b, decal: null, drawn: false } });
|
||||
// keep the active hangar slot in sync with the live build/paint/robotName before saving
|
||||
function syncActive() {
|
||||
if (!save || !save.robots || !save.robots[save.active]) return;
|
||||
const r = save.robots[save.active];
|
||||
r.name = save.robotName; r.build = save.build; r.paint = save.paint;
|
||||
}
|
||||
let slot = null, save = null; // per account, set by enterAccount()
|
||||
const persist = () => { if (slot && save) slot.save(save); };
|
||||
const persist = () => { if (slot && save) { syncActive(); slot.save(save); } };
|
||||
const audio = Kit.createAudio({
|
||||
prefix: ID,
|
||||
files: ['sfx_click', 'sfx_buy', 'sfx_hit', 'sfx_saw', 'sfx_boom', 'sfx_win', 'sfx_lose', 'music_title', 'music_garage', 'music_fight'],
|
||||
@@ -49,6 +58,7 @@
|
||||
});
|
||||
const scores = Kit.scores({ url: DB_URL });
|
||||
const DEV = new URLSearchParams(location.search);
|
||||
if (DEV.has('touch')) document.body.classList.add('forcetouch'); // dev: &touch shows the touch pad on desktop
|
||||
const net = RC.Net(NET_CFG);
|
||||
const FLAGS = ['DE', 'AT', 'CH', 'GB', 'US', 'FR', 'ES', 'IT', 'NL', 'PL', 'TR', 'RU', 'BR', 'JP', 'KR', 'XX'];
|
||||
const flagHtml = c => `<span class="fl fl-${FLAGS.includes(c) ? c : 'XX'}"></span>`;
|
||||
@@ -58,7 +68,7 @@
|
||||
const input = Kit.input({
|
||||
keys: {
|
||||
ArrowUp: 'up', w: 'up', ArrowDown: 'down', s: 'down', ArrowLeft: 'left', a: 'left', ArrowRight: 'right', d: 'right',
|
||||
' ': 'fire', Shift: 'fire2', e: 'fire2', p: 'pause', Escape: 'pause', m: 'mute', Enter: 'ok', c: 'cam',
|
||||
' ': 'fire', Shift: 'fire2', e: 'fire2', g: 'fire3', p: 'pause', Escape: 'pause', m: 'mute', Enter: 'ok', c: 'cam',
|
||||
},
|
||||
onPress(a) {
|
||||
if (mode === 'intro') { skipIntro(); return; }
|
||||
@@ -96,6 +106,7 @@
|
||||
case 'press': audio.sfx('sfx_hit'); audio.noise(0.5, 0.65, 300); audio.tone(55, 0.5, 'sine', 0.6, -20); break;
|
||||
case 'crane': audio.tone(140, 0.6, 'sawtooth', 0.07, 140); break;
|
||||
case 'drop': case 'land': audio.noise(0.22, 0.35, 500); break;
|
||||
case 'broke': audio.sfx('sfx_hit'); audio.noise(0.45, 0.5, 900); audio.tone(240, 0.35, 'sawtooth', 0.22, -190); break;
|
||||
case 'pit_open': for (let k = 0; k < 3; k++) audio.tone(700, 0.3, 'square', 0.12, -250, k * 0.4); break;
|
||||
case 'pit': audio.tone(420, 1.2, 'sawtooth', 0.14, -360); break;
|
||||
case 'grab': audio.tone(150, 0.25, 'square', 0.12, -60); break;
|
||||
@@ -117,7 +128,9 @@
|
||||
let ctx = cv.getContext('2d');
|
||||
let view = null;
|
||||
try { view = RC.Render($('gl'), W, H); view.setQuality(settings.gfx); } catch (err) { console.error(err); }
|
||||
Kit.fit($('app'), { canvases: [[cv, W, H]], onFit(sc) { ctx = cv.getContext('2d'); if (view) view.resize(sc); } });
|
||||
// cap upscaling so the UI does not get huge on big / high-DPI screens (960x540 stage, max ~2x)
|
||||
Kit.fit($('app'), { max: 2.0, margin: document.documentElement.classList.contains('exe') ? 1 : 0.98,
|
||||
canvases: [[cv, W, H]], onFit(sc) { ctx = cv.getContext('2d'); if (view) view.resize(sc); } });
|
||||
Kit.host.dragArea(document.body);
|
||||
const hex = n => '#' + (n >>> 0).toString(16).padStart(6, '0');
|
||||
const img = name => Kit.asset('assets/Sprites/' + name);
|
||||
@@ -126,9 +139,11 @@
|
||||
$('icoFame').innerHTML = `<img src="${img('ico_fame.png')}" alt="" onerror="this.classList.add('missing')">`;
|
||||
|
||||
const shop = RC.Shop({
|
||||
t, getSave: () => save, onSave: () => { persist(); hud(); }, // buy / sell -> credits in the header
|
||||
t, getSave: () => save, onSave: () => { persist(); hud(); }, // buy/sell/rename -> header
|
||||
onBuild: () => view.showGarage(save.build, paintObj()),
|
||||
onPaint: () => view.setPaint(paintObj()),
|
||||
onPreview: b => { if (mode === 'garage') view.showGarage(b, paintObj()); }, // show the selected part on the robot
|
||||
onHangarView: el => renderHangar(el), // Hangar tab content
|
||||
sfx: SFX,
|
||||
});
|
||||
|
||||
@@ -164,6 +179,9 @@
|
||||
overlay.style.backgroundImage = opt.bg ? `linear-gradient(rgba(5,6,10,.55), rgba(5,6,10,.75)), url("${img(opt.bg)}")` : '';
|
||||
}
|
||||
function hideOverlay() { overlay.classList.add('hide'); overlay.innerHTML = ''; overlay.style.backgroundImage = ''; }
|
||||
// fade a menu in once; the class is dropped again so live lists (lobby) do not flicker on every refresh
|
||||
let enterT = 0;
|
||||
function overlayEnter() { overlay.classList.add('enter'); clearTimeout(enterT); enterT = setTimeout(() => overlay.classList.remove('enter'), 220); }
|
||||
const esc = s => String(s).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
|
||||
const seasonMul = () => 1 + (save.season - 1) * 0.5;
|
||||
const weaponName = b => (b.weapon ? RC.PARTS[b.weapon].name : t('unarmed')) + (b.tower ? ' + ' + RC.PARTS[b.tower].name : '');
|
||||
@@ -180,11 +198,14 @@
|
||||
$('hFame').textContent = save ? Kit.fmt(save.fame) : '–';
|
||||
$('hLeague').textContent = save ? t('league_chip', { s: save.season, n: save.beaten, m: RC.LEAGUE.length }) : '–';
|
||||
$('hUser').textContent = fbUser() ? '👤 ' + fbUser().name : accounts.current ? (accounts.current.guest ? '👤 ' + t('guest') : '👤 ' + accounts.current.name) : save ? '👤 ' + t('guest') : '👤 –';
|
||||
$('bMute').textContent = audio.muted ? t('sound_off') : t('sound_on');
|
||||
$('bMute').textContent = audio.muted ? '🔇' : '🔊';
|
||||
$('bMute').title = (audio.muted ? t('sound_off') : t('sound_on')) + ' (M)';
|
||||
}
|
||||
function setScreen(m) {
|
||||
if (m !== 'garage' && painter.isOpen) painter.close();
|
||||
if (m !== mode) overlayEnter();
|
||||
mode = m;
|
||||
document.body.dataset.mode = m; // CSS shows/places the HUD per screen
|
||||
document.body.classList.toggle('fighting', m === 'fight' || m === 'pause');
|
||||
show('shop', m === 'garage');
|
||||
show('fightHud', m === 'fight' || m === 'pause' || m === 'result');
|
||||
@@ -225,11 +246,17 @@
|
||||
const btns = acc
|
||||
? `<button class="primary" id="bPlay">${t('play_as', { name: esc(acc.name) })}</button>${online}<button id="bSwitch">${t('switch_account')}</button>`
|
||||
: `<button class="primary" id="bLogin">${t('login')}</button><button id="bReg">${t('register')}</button><button id="bGuest">${t('play_guest')}</button>${online}`;
|
||||
overlay.innerHTML = `<div class="title"><div class="big">ROBOT CLASH</div><div class="tag">${t('menu_text')}</div>
|
||||
<div class="row">${btns}</div>
|
||||
<div class="row"><button id="bSet">⚙ ${t('settings')}</button><button id="bHelp">${t('how_to')}</button>
|
||||
// logo picture when ComfyGen made one, otherwise the lettering (never both, never nothing)
|
||||
const logo = `<img class="tlogoimg" src="${Kit.asset('assets/Sprites/logo.png')}" alt="ROBOT CLASH"
|
||||
onerror="this.remove()" onload="this.nextElementSibling.style.display='none'"><div class="big">ROBOT CLASH</div>`;
|
||||
overlay.innerHTML = `<div class="title"><div class="tpanel">
|
||||
${logo}
|
||||
<div class="tag">${t('menu_text')}</div>
|
||||
<div class="hazbar"></div>
|
||||
<div class="tmenu">${btns}</div>
|
||||
<div class="trow2"><button id="bSet">⚙ ${t('settings')}</button><button id="bHelp">${t('how_to')}</button>
|
||||
<button id="bLang" title="English / Deutsch">🌐 ${t('lang_self')}</button>${scores.enabled ? `<button id="bRank">🏆 ${t('ranking')}</button>` : ''}</div>
|
||||
<p class="credits">${CREDITS}</p></div>`;
|
||||
<p class="credits">${CREDITS}</p></div></div>`;
|
||||
overlay.classList.remove('hide'); overlay.classList.add('clear'); overlay.style.backgroundImage = '';
|
||||
const on = (id, f) => { const el = $(id); if (el) el.onclick = () => { SFX.click(); f(); }; };
|
||||
on('bPlay', () => enterAccount());
|
||||
@@ -297,34 +324,42 @@
|
||||
overlay.querySelectorAll('input').forEach(el => el.addEventListener('keydown', e => { e.stopPropagation(); if (e.key === 'Enter') $('oGo').click(); }));
|
||||
}
|
||||
function showLobby() {
|
||||
if (!lobbyRoom) lobbyRoom = 'all'; // filter: 'all' or a country code
|
||||
setScreen('lobby'); renderLobby();
|
||||
}
|
||||
// compact one-view lobby: country filter + flag dropdowns, slim player list
|
||||
// two-pane lobby: country rooms on the left, players of the chosen room on the right (own style, not copied art)
|
||||
function renderLobby() {
|
||||
if (!lobbyRoom) return renderRooms();
|
||||
const here = lobbyRows.filter(r => (FLAGS.includes(r.flag) ? r.flag : 'XX') === lobbyRoom);
|
||||
const meRow = `<div class="prow me"><span class="pf">${flagHtml(lobbyRoom)}</span><span class="pn">${esc(playerName())} <span class="muted">(${t('you')})</span></span><span class="pfame">⭐ ${Kit.fmt(save.fame | 0)}</span><span class="pbusy"></span></div>`;
|
||||
const list = here.map(r => `<div class="prow" data-uid="${r.uid}"><span class="pf">${flagHtml(r.flag)}</span><span class="pn">${esc(r.name)}</span><span class="pfame">⭐ ${Kit.fmt(r.fame | 0)}</span>${r.state === 'idle' ? `<button class="chal" data-uid="${r.uid}">${t('challenge')}</button>` : `<span class="pbusy">${t('busy')}</span>`}</div>`).join('');
|
||||
card(`<h2>${flagHtml(lobbyRoom)} ${t('room_title', { room: t('cc_' + lobbyRoom) })}</h2>
|
||||
<p class="muted">${t('room_count', { n: here.length + 1 })}</p>
|
||||
<div class="plist">${meRow}${list || `<div class="muted" style="padding:14px">${t('lobby_empty')}</div>`}</div>
|
||||
${pendingOut ? `<p class="muted">${t('waiting_accept')} <button class="link" id="lCancel">${t('cancel')}</button></p>` : ''}
|
||||
<div class="row"><button id="lRooms">🌍 ${t('other_rooms')}</button><button id="lQuick">${t('quick_match')}</button><button id="lBack">${t('back')}</button></div>`, { wide: true, bg: 'bg_title.jpg' });
|
||||
const code = r => (FLAGS.includes(r.flag) ? r.flag : 'XX');
|
||||
const all = lobbyRows;
|
||||
const myFlag = FLAGS.includes(save.flag) ? save.flag : 'XX';
|
||||
// I am in the lobby too: count myself in my own country (and in "all"), and only list me there
|
||||
const total = all.length + 1;
|
||||
const cnt = f => all.filter(r => code(r) === f).length + (f === myFlag ? 1 : 0);
|
||||
const here = lobbyRoom === 'all' ? all : all.filter(r => code(r) === lobbyRoom);
|
||||
const showMe = lobbyRoom === 'all' || lobbyRoom === myFlag;
|
||||
const flagOpts = FLAGS.map(f => `<option value="${f}" ${f === myFlag ? 'selected' : ''}>${t('cc_' + f)}</option>`).join('');
|
||||
const room = (f, label, flag) => `<button class="rroom ${lobbyRoom === f ? 'on' : ''}" data-f="${f}"><span class="rfl">${flag ? flagHtml(f) : ''}</span><span class="rn">${label}</span><span class="cnt ${cnt(f) ? 'live' : ''}">${f === 'all' ? total : cnt(f)}</span></button>`;
|
||||
const rooms = room('all', t('all_countries'), false) + FLAGS.map(f => room(f, t('cc_' + f), true)).join('');
|
||||
const prow = (r, me) => `<div class="prow ${me ? 'me' : ''}" ${me ? '' : `data-uid="${r.uid}"`}><span class="pf">${flagHtml(me ? save.flag : r.flag)}</span><span class="pn">${esc(me ? playerName() : r.name)}${me ? ` <span class="muted">(${t('you')})</span>` : ''}</span><span class="pfame">\u2B50 ${Kit.fmt((me ? save.fame : r.fame) | 0)}</span>${me ? '<span class="pbusy"></span>' : (r.state === 'idle' ? `<button class="chal" data-uid="${r.uid}">${t('challenge')}</button>` : `<span class="pbusy">${t('busy')}</span>`)}</div>`;
|
||||
const list = here.map(r => prow(r, false)).join('');
|
||||
const title = lobbyRoom === 'all' ? '🌍 ' + t('all_countries') : flagHtml(lobbyRoom) + ' ' + t('cc_' + lobbyRoom);
|
||||
overlay.innerHTML = `<div class="lobbyfull">
|
||||
<div class="lobbyL"><div class="lobbyLh">🌍 ${t('lobby')}</div><div class="roomlist">${rooms}</div></div>
|
||||
<div class="lobbyR">
|
||||
<div class="lobbyRh">${title} <span class="muted">(${here.length + (showMe ? 1 : 0)})</span><span class="grow"></span>
|
||||
<label class="flagpick">${t('your_flag')} <select id="lFlag">${flagOpts}</select></label></div>
|
||||
<div class="plist">${showMe ? prow(null, true) : ''}${list || (showMe ? '' : `<div class="muted" style="padding:16px;text-align:center">${t('lobby_empty')}</div>`)}</div>
|
||||
${pendingOut ? `<p class="muted" style="margin:6px 0 0">${t('waiting_accept')} <button class="link" id="lCancel">${t('cancel')}</button></p>` : ''}
|
||||
<div class="row" style="margin-top:8px"><button id="lBack">${t('back')}</button><button class="primary" id="lQuick">${t('quick_match')}</button></div>
|
||||
</div></div>`;
|
||||
overlay.classList.remove('hide'); overlay.classList.remove('clear');
|
||||
overlay.style.backgroundImage = `linear-gradient(rgba(5,6,10,.6), rgba(5,6,10,.8)), url("${img('bg_title.jpg')}")`;
|
||||
overlay.querySelectorAll('.rroom').forEach(b => { b.onclick = () => { SFX.click(); lobbyRoom = b.dataset.f; renderLobby(); }; });
|
||||
$('lFlag').onchange = e => { save.flag = e.target.value; persist(); if (lobby) lobby.refresh(); renderLobby(); };
|
||||
overlay.querySelectorAll('.chal').forEach(b => { b.onclick = () => { SFX.click(); pendingOut = b.dataset.uid; lobby.challenge(b.dataset.uid); renderLobby(); }; });
|
||||
if ($('lCancel')) $('lCancel').onclick = () => { SFX.click(); lobby.cancel(); pendingOut = null; renderLobby(); };
|
||||
$('lQuick').onclick = () => { const idle = here.find(r => r.state === 'idle'); if (idle) { SFX.click(); pendingOut = idle.uid; lobby.challenge(idle.uid); renderLobby(); } else SFX.deny(); };
|
||||
$('lRooms').onclick = () => { SFX.click(); lobbyRoom = null; renderLobby(); };
|
||||
$('lBack').onclick = () => { SFX.click(); lobbyRoom = null; if (save) openGarage(); else showTitle(); };
|
||||
}
|
||||
// room picker: every country with how many players sit in it right now
|
||||
function renderRooms() {
|
||||
const count = f => lobbyRows.filter(r => (FLAGS.includes(r.flag) ? r.flag : 'XX') === f).length;
|
||||
const rooms = FLAGS.map(f => { const n = count(f); return `<button class="room ${n ? 'live' : ''}" data-f="${f}">${flagHtml(f)}<span class="rn">${t('cc_' + f)}</span><span class="rc">${n ? '● ' + n : '0'}</span></button>`; }).join('');
|
||||
card(`<h2>🌍 ${t('lobby')}</h2><p class="muted">${t('pick_room')}</p>
|
||||
<div class="rooms">${rooms}</div>
|
||||
<div class="row"><button id="lBack">${t('back')}</button></div>`, { wide: true, bg: 'bg_title.jpg' });
|
||||
overlay.querySelectorAll('.room').forEach(b => { b.onclick = () => {
|
||||
SFX.click(); lobbyRoom = b.dataset.f; save.flag = lobbyRoom; persist(); if (lobby) lobby.refresh(); renderLobby();
|
||||
}; });
|
||||
$('lQuick').onclick = () => { const idle = here.find(r => r.state === 'idle') || all.find(r => r.state === 'idle'); if (idle) { SFX.click(); pendingOut = idle.uid; lobby.challenge(idle.uid); renderLobby(); } else SFX.deny(); };
|
||||
$('lBack').onclick = () => { SFX.click(); if (save) openGarage(); else showTitle(); };
|
||||
}
|
||||
function showIncoming(c) {
|
||||
@@ -400,16 +435,66 @@
|
||||
shop.reset();
|
||||
if (!save.tutorialSeen) { save.tutorialSeen = true; persist(); showHelp(openGarage); } else openGarage();
|
||||
}
|
||||
// saves from older versions: missing parts, invalid ids
|
||||
// saves from older versions: missing parts, invalid ids, hangar migration
|
||||
function repairSave() {
|
||||
save.owned = (save.owned || []).filter(id => RC.PARTS[id]);
|
||||
for (const sl of RC.SLOTS) {
|
||||
if (save.build[sl] && !RC.PARTS[save.build[sl]]) save.build[sl] = null;
|
||||
if (save.build[sl] && !save.owned.includes(save.build[sl])) save.owned.push(save.build[sl]);
|
||||
// hangar migration: older saves have only build/paint/robotName -> make it robot slot 0
|
||||
if (!Array.isArray(save.robots) || !save.robots.length) {
|
||||
save.robots = [{ name: save.robotName || 'Clank', build: save.build || Object.assign({}, RC.STARTER), paint: save.paint || { body: 0xff7a1a, accent: 0x15171b } }];
|
||||
save.active = 0;
|
||||
}
|
||||
for (const sl of Object.keys(RC.REQUIRED)) if (!save.build[sl]) { save.build[sl] = RC.STARTER[sl]; if (!save.owned.includes(RC.STARTER[sl])) save.owned.push(RC.STARTER[sl]); }
|
||||
save.active = Kit.clamp(save.active | 0, 0, save.robots.length - 1);
|
||||
const fixBuild = b => {
|
||||
for (const sl of RC.SLOTS) {
|
||||
if (b[sl] && !RC.PARTS[b[sl]]) b[sl] = null;
|
||||
if (b[sl] && !save.owned.includes(b[sl])) save.owned.push(b[sl]);
|
||||
}
|
||||
for (const sl of Object.keys(RC.REQUIRED)) if (!b[sl]) { b[sl] = RC.STARTER[sl]; if (!save.owned.includes(RC.STARTER[sl])) save.owned.push(RC.STARTER[sl]); }
|
||||
};
|
||||
for (const r of save.robots) { r.build = r.build || Object.assign({}, RC.STARTER); r.paint = r.paint || { body: 0xff7a1a, accent: 0x15171b }; r.name = r.name || 'Robot'; fixBuild(r.build); }
|
||||
// load the active robot into the live fields the rest of the game uses
|
||||
const a = save.robots[save.active];
|
||||
save.build = a.build; save.paint = a.paint; save.robotName = a.name;
|
||||
save.beaten = Kit.clamp(save.beaten | 0, 0, RC.LEAGUE.length - 1);
|
||||
}
|
||||
// hangar: switch / add / delete robot slots (owned parts are shared)
|
||||
function switchRobot(i) {
|
||||
if (i === save.active || !save.robots[i]) return;
|
||||
syncActive();
|
||||
save.active = i;
|
||||
const a = save.robots[i];
|
||||
save.build = a.build; save.paint = a.paint; save.robotName = a.name;
|
||||
persist();
|
||||
RC.layerFromData(layer, save.paint.decal, () => { if (mode === 'garage') view.showGarage(save.build, paintObj()); });
|
||||
shop.reset(); shop.render(); view.showGarage(save.build, paintObj()); renderHangar();
|
||||
}
|
||||
function addRobot() {
|
||||
if (save.robots.length >= MAX_ROBOTS) { SFX.deny(); return; }
|
||||
syncActive();
|
||||
save.robots.push(newRobotDef(t('robot_n', { n: save.robots.length + 1 })));
|
||||
switchRobot(save.robots.length - 1);
|
||||
SFX.buy();
|
||||
}
|
||||
function delRobot(i) {
|
||||
if (save.robots.length <= 1) { SFX.deny(); return; }
|
||||
save.robots.splice(i, 1);
|
||||
save.active = Kit.clamp(save.active >= i ? save.active - (save.active === i ? 0 : 1) : save.active, 0, save.robots.length - 1);
|
||||
const a = save.robots[save.active]; save.build = a.build; save.paint = a.paint; save.robotName = a.name;
|
||||
persist(); RC.layerFromData(layer, save.paint.decal, () => {}); shop.reset(); shop.render(); view.showGarage(save.build, paintObj()); renderHangar();
|
||||
}
|
||||
// hangar management (shop top-tab): list of robots with weapon, switch / delete + add button
|
||||
function renderHangar(el) {
|
||||
el = el || $('hangarView'); if (!el) return;
|
||||
const rows = save.robots.map((r, i) => `<div class="hmrow ${i === save.active ? 'on' : ''}" data-i="${i}">
|
||||
<div><div class="hmn">${esc(r.name)}</div><div class="hmw">${esc(weaponName(r.build))}</div></div>
|
||||
${i === save.active ? `<span class="muted" style="font-size:12px">${t('active_robot')}</span>` : `<button data-use="${i}">${t('use')}</button>`}
|
||||
${save.robots.length > 1 ? `<button data-del="${i}" title="${t('delete')}">✕</button>` : '<span></span>'}</div>`).join('');
|
||||
el.innerHTML = `<div class="hmgr">${rows}</div>
|
||||
${save.robots.length < MAX_ROBOTS ? `<button class="primary" id="hAdd" style="margin-top:8px">+ ${t('new_robot')}</button>` : `<p class="muted" style="margin-top:8px">${t('hangar_full')}</p>`}`;
|
||||
el.querySelectorAll('[data-use]').forEach(b => { b.onclick = () => { SFX.click(); switchRobot(+b.dataset.use); shop.setTab('build'); } ; });
|
||||
el.querySelectorAll('[data-del]').forEach(b => { b.onclick = () => { SFX.click(); delRobot(+b.dataset.del); renderHangar(); } ; });
|
||||
if ($('hAdd')) $('hAdd').onclick = () => { addRobot(); shop.setTab('build'); };
|
||||
}
|
||||
function signOut() {
|
||||
persist();
|
||||
if (lobby && onlineReady) { lobby.leave(); onlineReady = false; lobbyRows = []; pendingOut = null; }
|
||||
@@ -431,6 +516,7 @@
|
||||
|
||||
// ---------------------------------------------------------------- settings / help / ranking
|
||||
function showSettings(back) {
|
||||
overlayEnter();
|
||||
const prev = mode;
|
||||
const seg = (id, val, opts) => `<div class="seg" id="${id}">${opts.map(([v, label]) => `<button data-v="${v}" class="${v === val ? 'on' : ''}">${label}</button>`).join('')}</div>`;
|
||||
const who = fbAcc() || (accounts.current && !accounts.current.guest ? accounts.current : null);
|
||||
@@ -478,11 +564,13 @@
|
||||
<b>${t('key_pad')}</b><span>${t('key_pad_text')}</span></div>`;
|
||||
}
|
||||
function showHelp(back) {
|
||||
overlayEnter();
|
||||
card(`<h2>${t('how_to')}</h2><p>${t('help_text')}</p>${keysHtml()}
|
||||
<p style="margin-top:12px">${t('help_arena')}</p><button class="primary" id="bOk">${t('ok')}</button>`, { bg: 'bg_title.jpg' });
|
||||
$('bOk').onclick = () => { SFX.click(); back(); };
|
||||
}
|
||||
function showRanking(back) {
|
||||
overlayEnter();
|
||||
card(`<h2>🏆 ${t('ranking')}</h2><ol class="board" id="board"><li class="muted">${t('loading')}</li></ol><div class="row"><button class="primary" id="bBack">${t('back')}</button></div>`, { bg: 'bg_title.jpg' });
|
||||
$('bBack').onclick = () => { SFX.click(); back(); };
|
||||
fillBoard();
|
||||
@@ -519,6 +607,8 @@
|
||||
view.showGarage(save.build, paintObj());
|
||||
audio.music('music_garage');
|
||||
shop.render(); hud();
|
||||
$('zIn').onclick = () => { SFX.click(); view.zoomGarage(1.18); };
|
||||
$('zOut').onclick = () => { SFX.click(); view.zoomGarage(1 / 1.18); };
|
||||
}
|
||||
$('bGMenu').onclick = () => { SFX.click(); persist(); startIntroOrTitle(); };
|
||||
$('bGOnline').onclick = () => { SFX.click(); persist(); startOnline(); };
|
||||
@@ -567,9 +657,10 @@
|
||||
const seed = online ? online.seed : (Date.now() & 0xffff) + save.games * 31;
|
||||
// arena: league scales with the opponent, online derives from the shared seed, training uses the setting
|
||||
const ids = RC.ARENAS.map(a => a.id), idx = RC.LEAGUE.indexOf(opp);
|
||||
const bySize = RC.ARENAS.slice().sort((a, b) => a.half - b.half).map(a => a.id); // small -> big for league progression
|
||||
const arenaId = DEV.get('arena') ? DEV.get('arena')
|
||||
: online ? ids[seed % ids.length]
|
||||
: idx >= 0 ? ids[Math.min(ids.length - 1, Math.floor(idx / 3))]
|
||||
: idx >= 0 ? bySize[Math.min(bySize.length - 1, Math.floor(idx * bySize.length / RC.LEAGUE.length))]
|
||||
: settings.arena === 'random' || !settings.arena ? ids[(Math.random() * ids.length) | 0] : settings.arena;
|
||||
const s = RC.Combat.create({ robots: [stA, stB], seed, names: [save.robotName, opp.name], arena: arenaId });
|
||||
const skill = Kit.clamp(opp.skill + (save.season - 1) * 0.12 + D.skill, 0, 1);
|
||||
@@ -598,6 +689,9 @@
|
||||
setScreen('fight');
|
||||
audio.music('music_fight');
|
||||
banner('📍 ' + t('arena_' + s.arena.id), '#ff7a1a', 2.2);
|
||||
const pg = $('padGadget'); if (pg) pg.style.display = s.robots[0].st.gadget ? '' : 'none';
|
||||
buildCds();
|
||||
buildDmg(0, save.build); buildDmg(1, opp.build);
|
||||
fightHud();
|
||||
}
|
||||
|
||||
@@ -608,23 +702,23 @@
|
||||
const b = i => !!(gp.buttons[i] && gp.buttons[i].pressed);
|
||||
if (b(9) && every('gpStart', 400)) togglePause();
|
||||
return { throttle: -dz(gp.axes[1] || 0) + (b(12) ? 1 : 0) - (b(13) ? 1 : 0), turn: dz(gp.axes[0] || 0) + (b(15) ? 1 : 0) - (b(14) ? 1 : 0),
|
||||
fire: b(0) || b(7), fire2: b(1) || b(2) || b(6) };
|
||||
fire: b(0) || b(7), fire2: b(1) || b(2) || b(6), fire3: b(3) || b(5) };
|
||||
}
|
||||
// up/down + left/right from keys, touch pad and gamepad
|
||||
function playerInput() {
|
||||
let ky = (input.down('up') ? 1 : 0) - (input.down('down') ? 1 : 0);
|
||||
let kx = (input.down('right') ? 1 : 0) - (input.down('left') ? 1 : 0);
|
||||
let fire = input.down('fire'), fire2 = input.down('fire2');
|
||||
let fire = input.down('fire'), fire2 = input.down('fire2'), fire3 = input.down('fire3');
|
||||
const g = pad();
|
||||
if (g) { ky = Kit.clamp(ky + g.throttle, -1, 1); kx = Kit.clamp(kx + g.turn, -1, 1); fire = fire || g.fire; fire2 = fire2 || g.fire2; }
|
||||
if (g) { ky = Kit.clamp(ky + g.throttle, -1, 1); kx = Kit.clamp(kx + g.turn, -1, 1); fire = fire || g.fire; fire2 = fire2 || g.fire2; fire3 = fire3 || g.fire3; }
|
||||
const s = F.s, me = s.robots[0], en = s.robots[1];
|
||||
let k = { throttle: ky, turn: kx, fire, fire2 };
|
||||
let k = { throttle: ky, turn: kx, fire, fire2, fire3 };
|
||||
if (settings.steer === 'simple' && view.camMode === 'iso') {
|
||||
// keys = direction on screen; the robot turns towards it and drives
|
||||
// (iso camera: screen up = world (-1,-1), screen right = world (1,-1))
|
||||
const dx = (kx - ky) / Math.SQRT2, dz = (-kx - ky) / Math.SQRT2;
|
||||
const wrap = a => { while (a > Math.PI) a -= 2 * Math.PI; while (a < -Math.PI) a += 2 * Math.PI; return a; };
|
||||
if (Math.hypot(dx, dz) < 0.2) k = { throttle: 0, turn: 0, fire, fire2 };
|
||||
if (Math.hypot(dx, dz) < 0.2) k = { throttle: 0, turn: 0, fire, fire2, fire3 };
|
||||
else {
|
||||
let diff = wrap(Math.atan2(dz, dx) - me.a);
|
||||
// target behind: drive backwards there instead of a slow 180° turn on the spot
|
||||
@@ -634,18 +728,25 @@
|
||||
if (back) diff = wrap(diff + Math.PI);
|
||||
const ad = Math.abs(diff);
|
||||
const thr = ad < 0.9 ? 1 : ad < 1.6 ? 0.6 : 0.2; // keep rolling while turning
|
||||
k = { throttle: back ? -thr : thr, turn: Kit.clamp(diff * 3.5, -1, 1), fire, fire2 };
|
||||
k = { throttle: back ? -thr : thr, turn: Kit.clamp(diff * 3.5, -1, 1), fire, fire2, fire3 };
|
||||
}
|
||||
}
|
||||
// weapon helper: fires the main weapon in reach, the tower when in range
|
||||
if (settings.autofire) {
|
||||
const w = me.st.weapon, tw = me.st.tower, dist = Math.hypot(en.x - me.x, en.z - me.z);
|
||||
if (w && !k.fire) {
|
||||
if (w.type === 'spinner') k.fire = dist < 5;
|
||||
if (w.type === 'spinner' || w.type === 'vspinner') k.fire = dist < 5;
|
||||
else if (w.type === 'saw') k.fire = dist < 2.4;
|
||||
else if (w.type !== 'wedge') k.fire = RC.Combat.inZone(s, me, en);
|
||||
}
|
||||
if (tw && !k.fire2) k.fire2 = dist < tw.range * 0.95;
|
||||
if (tw && !k.fire2) {
|
||||
// the turret fires forward now, so only help when the enemy is actually in front
|
||||
const d = Math.atan2(en.z - me.z, en.x - me.x) - me.a;
|
||||
const ahead = Math.abs(Math.atan2(Math.sin(d), Math.cos(d)));
|
||||
const near = tw.type === 'flamer' || tw.type === 'zapper';
|
||||
k.fire2 = dist < tw.range * 0.95 && ahead < (near ? 0.5 : 0.3);
|
||||
}
|
||||
if (me.st.gadget && !k.fire3) k.fire3 = RC.Combat.wantGadget(s, me, en);
|
||||
}
|
||||
return k;
|
||||
}
|
||||
@@ -661,19 +762,26 @@
|
||||
// minimap for chase / cockpit view: arena, traps, pit, both robots
|
||||
function minimap() {
|
||||
const touch = window.matchMedia && matchMedia('(pointer: coarse)').matches;
|
||||
const s = F.s, A = RC.ARENA, S = touch ? 104 : 128, X = W - S - 14, Y = touch ? 84 : H - S - 14, k = S / (A.half * 2);
|
||||
const s = F.s, A = s.arena, S = touch ? 104 : 128, X = W - S - 14, Y = touch ? 84 : H - S - 14, k = S / (A.half * 2);
|
||||
// rotate 45° like the iso view, so "up" matches the arena camera
|
||||
const P = (x, z) => [X + S / 2 + (x - z) * k * 0.7071, Y + S / 2 + (x + z) * k * 0.7071];
|
||||
ctx.save();
|
||||
ctx.fillStyle = 'rgba(10,12,16,.72)'; ctx.strokeStyle = 'rgba(255,255,255,.25)'; ctx.lineWidth = 1;
|
||||
const poly = pts => { ctx.beginPath(); pts.forEach(([x, z], i) => { const [px, py] = P(x, z); if (i) ctx.lineTo(px, py); else ctx.moveTo(px, py); }); ctx.closePath(); };
|
||||
const h = A.half;
|
||||
poly([[-h, -h], [h, -h], [h, h], [-h, h]]); ctx.fill(); ctx.stroke();
|
||||
if (A.shape === 'round') poly(Array.from({ length: 20 }, (_, i) => { const a = i / 20 * Math.PI * 2; return [Math.cos(a) * h, Math.sin(a) * h]; }));
|
||||
else if (A.shape === 'octagon') { const d = h * 0.67; poly([[-d, -h], [d, -h], [h, -d], [h, d], [d, h], [-d, h], [-h, d], [-h, -d]]); }
|
||||
else poly([[-h, -h], [h, -h], [h, h], [-h, h]]);
|
||||
ctx.fill(); ctx.stroke();
|
||||
const rect = (o, col) => { ctx.fillStyle = col; poly([[o.x - o.hw, o.z - o.hd], [o.x + o.hw, o.z - o.hd], [o.x + o.hw, o.z + o.hd], [o.x - o.hw, o.z + o.hd]]); ctx.fill(); };
|
||||
rect(A.press, 'rgba(242,181,28,.35)'); rect(A.crane, 'rgba(242,181,28,.35)');
|
||||
rect(A.pit, s.pitOpen >= 1 ? 'rgba(255,40,40,.85)' : 'rgba(255,255,255,.12)');
|
||||
for (const f of A.flames) rect(f, RC.hazardOn(f, s.t) ? 'rgba(255,110,20,.85)' : 'rgba(255,110,20,.25)');
|
||||
for (const sw of A.saws) { const [px, py] = P(sw.x, sw.z); ctx.fillStyle = RC.hazardOn(sw, s.t) ? 'rgba(255,60,60,.9)' : 'rgba(200,200,200,.3)'; ctx.beginPath(); ctx.arc(px, py, sw.r * k, 0, 7); ctx.fill(); }
|
||||
for (const bl of A.belts) rect(bl, 'rgba(80,170,255,.35)');
|
||||
for (const o of A.oil) { const [px, py] = P(o.x, o.z); ctx.fillStyle = 'rgba(12,12,20,.65)'; ctx.beginPath(); ctx.arc(px, py, o.r * k, 0, 7); ctx.fill(); }
|
||||
for (const m of A.rams) rect(m, RC.hazardOn(m, s.t) ? 'rgba(255,60,60,.8)' : 'rgba(200,200,200,.25)');
|
||||
for (const b of A.blocks) rect(b, 'rgba(150,160,175,.6)');
|
||||
s.robots.forEach((r, i) => {
|
||||
if (r.out) return;
|
||||
const [px, py] = P(r.x, r.z), [qx, qy] = P(r.x + Math.cos(r.a), r.z + Math.sin(r.a)), ang = Math.atan2(qy - py, qx - px);
|
||||
@@ -708,10 +816,11 @@
|
||||
}
|
||||
for (const e of events) {
|
||||
SFX.event(e);
|
||||
if (e.type === 'dmg') F.acc[e.who] += e.amount;
|
||||
if (e.type === 'dmg') { F.acc[e.who] += e.amount; if (e.amount >= 3) flashBox(e.who); }
|
||||
else if (e.type === 'pit_open') banner(t('pit_open'), '#ff4a3a', 2);
|
||||
else if (e.type === 'pit') banner(t('into_pit'), '#ff4a3a', 2.2);
|
||||
else if (e.type === 'ko') banner(t('knockout'), '#ff7a1a', 2.2);
|
||||
else if (e.type === 'broke') banner(t(e.who === 0 ? 'broke_you' : 'broke_enemy', { p: t('slot_' + e.part) }), e.who === 0 ? '#ff5a4a' : '#ffc940', 1.8);
|
||||
}
|
||||
view.events(events);
|
||||
s.events.length = 0;
|
||||
@@ -730,10 +839,59 @@
|
||||
if (s.result && s.endIn <= 0 && !F.ended) { F.ended = true; endFight(); }
|
||||
}
|
||||
|
||||
// cooldown chips for the parts actually fitted (built once, only --p changes per frame)
|
||||
const CD_KEY = { weapon: '␣', tower: '⇧', gadget: 'G' };
|
||||
function buildCds() {
|
||||
const el = $('fCds');
|
||||
el.innerHTML = RC.Combat.cooldowns(F.s.robots[0]).map(c =>
|
||||
`<div class="cdchip" data-slot="${c.slot}" style="--p:0"><div class="in">${RC.pic('part_' + c.id, '🔧')}</div>` +
|
||||
`<b class="k">${CD_KEY[c.slot]}</b>${c.n === undefined ? '' : `<b class="n">${c.n}</b>`}</div>`).join('');
|
||||
}
|
||||
// condition panel: every part that can be torn off, shown per robot and greyed out when it is gone
|
||||
const BREAKABLE = ['armour', 'wheels', 'weapon', 'tower'];
|
||||
function buildDmg(i, build) {
|
||||
const icons = BREAKABLE.filter(k => build[k]).map(k =>
|
||||
`<span class="pt" data-part="${k}" title="${t('slot_' + k)}">${RC.pic('part_' + build[k], GLYPH_SLOT[k])}</span>`).join('');
|
||||
$('fD' + i).innerHTML = `<span class="hpn"></span><span class="pts">${icons}</span>`;
|
||||
}
|
||||
const GLYPH_SLOT = { armour: '🛡️', wheels: '🛞', weapon: '🪓', tower: '🔥' };
|
||||
|
||||
// short red flash on the box that just took a solid hit
|
||||
let hitT = [0, 0];
|
||||
function flashBox(who) {
|
||||
const el = $(who === 0 ? 'fLeft' : 'fRight');
|
||||
el.classList.add('hit');
|
||||
clearTimeout(hitT[who]);
|
||||
hitT[who] = setTimeout(() => el.classList.remove('hit'), 120);
|
||||
}
|
||||
|
||||
function fightHud() {
|
||||
if (!F) return;
|
||||
const s = F.s;
|
||||
for (let i = 0; i < 2; i++) $('fH' + i).style.width = (s.robots[i].hp / s.robots[i].maxHp * 100).toFixed(1) + '%';
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const r = s.robots[i], pct = r.hp / r.maxHp;
|
||||
$('fH' + i).style.width = (pct * 100).toFixed(1) + '%';
|
||||
$('fG' + i).style.width = (pct * 100).toFixed(1) + '%'; // trails behind (CSS transition)
|
||||
$(i === 0 ? 'fLeft' : 'fRight').classList.toggle('hurt', pct < 0.25 && !r.dead);
|
||||
// readable damage: hit points left, and every torn-off part crossed out live
|
||||
const el = $('fD' + i), hpn = el.querySelector('.hpn');
|
||||
const txt = `${Math.ceil(r.hp)}/${Math.round(r.maxHp)}`;
|
||||
if (hpn && hpn.textContent !== txt) hpn.textContent = txt;
|
||||
for (const ps of el.querySelectorAll('.pt')) ps.classList.toggle('gone', !!(r.lost && r.lost[ps.dataset.part]));
|
||||
}
|
||||
const own = s.robots[0].hp / s.robots[0].maxHp;
|
||||
$('dmgvig').style.opacity = own < 0.3 && !s.robots[0].out ? ((0.3 - own) / 0.3 * 0.6).toFixed(2) : 0;
|
||||
const cds = RC.Combat.cooldowns(s.robots[0]), chips = $('fCds').children;
|
||||
for (let i = 0; i < chips.length && i < cds.length; i++) {
|
||||
const ch = chips[i], c = cds[i];
|
||||
ch.style.setProperty('--p', c.p.toFixed(2));
|
||||
ch.classList.toggle('on', !!c.on);
|
||||
ch.classList.toggle('spent', c.n === 0);
|
||||
ch.classList.toggle('broke', !!c.broke);
|
||||
const n = ch.querySelector('.n');
|
||||
if (n && n.textContent !== String(c.n)) n.textContent = c.n;
|
||||
if (c.slot === 'gadget') { const pg = $('padGadget'); if (pg) pg.style.setProperty('--p', c.p.toFixed(2)); }
|
||||
}
|
||||
const sec = Math.ceil(s.left);
|
||||
$('fTime').textContent = `${Math.floor(sec / 60)}:${String(sec % 60).padStart(2, '0')}`;
|
||||
$('fTime').classList.toggle('low', sec <= 10);
|
||||
@@ -741,7 +899,7 @@
|
||||
let st = '';
|
||||
if (me.lifted) st = t('st_lifted'); else if (me.grabbedBy !== null) st = t('st_grabbed');
|
||||
else if (me.flipped > 0 && !me.st.invertible) st = t('st_flipped'); else if (me.stun > 0) st = t('st_stunned');
|
||||
else if (s.pitAlarm) st = t('pit_is_open'); else if (s.left - RC.ARENA.pitOpensAt < 10 && s.left > RC.ARENA.pitOpensAt) st = t('pit_soon');
|
||||
else if (s.pitAlarm) st = t('pit_is_open'); else if (s.left - s.arena.pitOpensAt < 10 && s.left > s.arena.pitOpensAt) st = t('pit_soon');
|
||||
$('fState').textContent = st;
|
||||
}
|
||||
|
||||
@@ -839,11 +997,21 @@
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- loop
|
||||
let lastNow = 0;
|
||||
let lastNow = 0, fpsN = 0, fpsT = 0, fpsVal = 0;
|
||||
function render(alpha, now) {
|
||||
// cap rendering: ~60 fps during action, ~16 fps when a static menu covers the arena (saves CPU/GPU on
|
||||
// high-refresh monitors and in menus). update() stays fixed 60 Hz via the loop, so physics is unaffected.
|
||||
const active = mode === 'fight' || mode === 'pause' || mode === 'intro' || mode === 'garage';
|
||||
const minGap = active ? 15.5 : 60;
|
||||
if (lastNow && now - lastNow < minGap) return;
|
||||
const dt = Math.min(0.05, lastNow ? (now - lastNow) / 1000 : 0.016); lastNow = now;
|
||||
if (view) view.frame(mode === 'pause' ? 0 : dt, now);
|
||||
ctx.clearRect(0, 0, W, H);
|
||||
if (DEV.has('fps')) { // dev: ?fps shows the effective render rate
|
||||
fpsN++; if (now - fpsT > 500) { fpsVal = Math.round(fpsN * 1000 / (now - fpsT)); fpsN = 0; fpsT = now; }
|
||||
ctx.fillStyle = '#6dff9e'; ctx.font = '14px monospace'; ctx.textAlign = 'left'; ctx.textBaseline = 'top';
|
||||
ctx.fillText(fpsVal + ' fps · ' + settings.gfx, 10, 10);
|
||||
}
|
||||
if (mode === 'intro' && view) {
|
||||
const it = view.introTime;
|
||||
if (it > 5.6) {
|
||||
@@ -884,6 +1052,7 @@
|
||||
const loop = Kit.loop({ step: 1000 / 60, update, render }).start();
|
||||
|
||||
function togglePause() {
|
||||
overlayEnter();
|
||||
if (F && F.online && mode === 'fight') { banner(t('no_pause_online'), '#ffffff', 1.4); return; }
|
||||
if (mode === 'fight') {
|
||||
mode = 'pause'; loop.pause();
|
||||
@@ -923,7 +1092,10 @@
|
||||
if (DEV.get('equip')) for (const id of DEV.get('equip').split(',')) { const p = RC.PARTS[id]; if (p) { if (!save.owned.includes(id)) save.owned.push(id); save.build[p.slot] = id; } }
|
||||
if (DEV.get('arena')) settings.arena = DEV.get('arena');
|
||||
RC.layerFromData(layer, save.paint.decal, () => { if (mode === 'garage') view.showGarage(save.build, paintObj()); });
|
||||
if (DEV.get('hangar')) { const n = Math.min(MAX_ROBOTS, +DEV.get('hangar') || 3); while (save.robots.length < n) save.robots.push(newRobotDef(t('robot_n', { n: save.robots.length + 1 }))); }
|
||||
if (DEV.has('fight')) startFight(RC.LEAGUE[Kit.clamp(+DEV.get('fight') || 0, 0, 7)], true); else openGarage();
|
||||
if (DEV.get('shoptab') && mode === 'garage') shop.setTab(DEV.get('shoptab'));
|
||||
if (DEV.get('sel') && mode === 'garage') { const id = DEV.get('sel'), p = RC.PARTS[id]; if (p) { const tb = document.querySelector(`.tab[data-slot="${p.slot}"]`); if (tb) tb.click(); const it = document.querySelector(`.item[data-id="${id}"]`); if (it) it.click(); } }
|
||||
// dev: ?play&screen=league|vs|settings|help|lobby|pause opens that screen (layout screenshots)
|
||||
const scr = DEV.get('screen');
|
||||
if (scr === 'league') { save.beaten = Math.max(save.beaten, 3); showLeague(); }
|
||||
@@ -949,4 +1121,5 @@
|
||||
} else if (DEV.has('online') && net.enabled) { startIntroOrTitle(); startOnline(); }
|
||||
else if (DEV.has('title')) startIntroOrTitle();
|
||||
else startIntro();
|
||||
if (DEV.has('uicheck') && RC.uiCheckRun) RC.uiCheckRun(); // dev: &uicheck prints layout faults as text
|
||||
})();
|
||||
|
||||
379
game/index.html
@@ -6,26 +6,53 @@
|
||||
<title>Robot Clash</title>
|
||||
<link rel="icon" href="assets/Sprites/icon.png">
|
||||
<style>
|
||||
/* Headline font, shipped with the game so it also works offline / in the exe.
|
||||
Russo One (c) 2011-2012 Jovanny Lemonad - SIL Open Font License 1.1 (assets/Fonts/OFL.txt).
|
||||
build-web.mjs turns the url() into a data: URI for the single-file release. */
|
||||
@font-face { font-family: "Russo One"; font-style: normal; font-weight: 400;
|
||||
src: url('assets/Fonts/RussoOne-Regular.ttf') format('truetype'); font-display: swap; }
|
||||
:root {
|
||||
--bg: #090b10; --panel: #151920; --panel2: #1c212b; --line: #2d3442; --text: #e8ebf2; --dim: #8d95a8;
|
||||
--accent: #ff7a1a; --good: #6dff9e; --warn: #ff5a4a; --blue: #4fa8ff; --gold: #ffc940;
|
||||
--head: "Russo One", "Segoe UI Black", "Arial Black", Impact, sans-serif;
|
||||
/* shared look: soft metal sheen, 1px top highlight, chamfered corners, hazard tape */
|
||||
--r1: 4px; --r2: 8px; --r3: 12px;
|
||||
--steel: linear-gradient(#242a35, #1a1f28);
|
||||
--sheen: linear-gradient(rgba(255,255,255,.04), rgba(0,0,0,.07));
|
||||
--hl: inset 0 1px 0 rgba(255,255,255,.07);
|
||||
--chamfer: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
|
||||
--hazard: repeating-linear-gradient(45deg, var(--accent) 0 6px, #1a1008 6px 12px);
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
/* never show a scrollbar - screens are built to fit; overflow stays reachable by wheel/touch */
|
||||
* { scrollbar-width: none; -ms-overflow-style: none; }
|
||||
*::-webkit-scrollbar { width: 0; height: 0; display: none; }
|
||||
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
|
||||
font: 15px/1.35 "Segoe UI", system-ui, sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; }
|
||||
body { display: flex; align-items: center; justify-content: center;
|
||||
background: radial-gradient(circle at 50% 25%, #1d1f26 0%, var(--bg) 70%); }
|
||||
body { display: flex; align-items: center; justify-content: center; background: #05060a; }
|
||||
|
||||
/* fixed design size, scaled to the window by Kit.fit */
|
||||
#app { position: relative; width: 960px; display: flex; flex-direction: column; gap: 8px; }
|
||||
#hud { display: flex; gap: 8px; align-items: center; height: 38px; }
|
||||
#app { position: relative; width: 1280px; display: flex; flex-direction: column; }
|
||||
/* HUD lives INSIDE the stage (full-screen game look), above the overlay so menus keep it reachable */
|
||||
#hud { position: absolute; left: 0; right: 0; top: 0; z-index: 7; display: flex; gap: 8px; align-items: center;
|
||||
height: 44px; padding: 0 12px; pointer-events: none;
|
||||
background: linear-gradient(rgba(6,8,12,.9) 35%, rgba(6,8,12,0)); }
|
||||
#hud > * { pointer-events: auto; }
|
||||
#hud button { min-height: 34px; padding: 4px 10px; }
|
||||
#hud .icobtn { width: 36px; height: 34px; padding: 0; font-size: 15px; }
|
||||
/* per screen: title has its own menu, the fight only keeps pause + sound under the health box */
|
||||
body[data-mode="intro"] #hud, body[data-mode="title"] #hud, body[data-mode="account"] #hud { display: none; }
|
||||
body[data-mode="fight"] #hud, body[data-mode="pause"] #hud { top: 92px; height: 36px; background: none; }
|
||||
body[data-mode="fight"] #hud > *, body[data-mode="pause"] #hud > * { display: none; }
|
||||
body[data-mode="fight"] #hud > .icobtn, body[data-mode="pause"] #hud > .icobtn { display: block; }
|
||||
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; display: flex; align-items: center; gap: 6px; }
|
||||
.chip b { color: var(--accent); font-variant-numeric: tabular-nums; }
|
||||
.chip .pic { width: 22px; height: 22px; }
|
||||
.grow { flex: 1; }
|
||||
.logo { font-family: var(--head); letter-spacing: .06em; color: var(--accent); font-size: 20px; padding: 0 6px; }
|
||||
#stage { position: relative; width: 960px; height: 540px; border: 2px solid var(--line); border-radius: 10px; overflow: hidden; background: #000; }
|
||||
#stage { position: relative; width: 1280px; height: 720px; overflow: hidden; background: #000; }
|
||||
#stage::after { content: ''; position: absolute; inset: 0; z-index: 8; pointer-events: none;
|
||||
background: radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0,0,0,.3) 100%); }
|
||||
#stage > canvas { position: absolute; left: 0; top: 0; display: block; }
|
||||
#cv { pointer-events: none; z-index: 2; }
|
||||
#gl { z-index: 1; }
|
||||
@@ -38,27 +65,52 @@
|
||||
.pic img { position: relative; width: 100%; height: 100%; object-fit: contain; }
|
||||
.pic img.missing { visibility: hidden; }
|
||||
|
||||
button { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
|
||||
border-radius: 8px; padding: 6px 12px; cursor: pointer; }
|
||||
button:hover { border-color: var(--accent); }
|
||||
button.primary { background: linear-gradient(#ff8f3a, #e8650a); color: #1a0c02; border-color: #ffa25a; font-weight: 700; padding: 10px 24px; font-family: var(--head); letter-spacing: .04em; box-shadow: 0 3px 0 #7a3000; }
|
||||
button.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #7a3000; }
|
||||
button:disabled { opacity: .4; cursor: default; }
|
||||
button:disabled:hover { border-color: var(--line); }
|
||||
button.link { background: none; border: none; color: var(--accent); padding: 2px 4px; text-decoration: underline; }
|
||||
button { font: inherit; color: var(--text); background: var(--steel); border: 1px solid var(--line);
|
||||
border-radius: var(--r2); padding: 6px 12px; min-height: 34px; cursor: pointer; box-shadow: var(--hl);
|
||||
transition: border-color .1s, filter .1s, transform .06s; }
|
||||
button:active { transform: translateY(1px); }
|
||||
@media (hover: hover) { button:hover { border-color: var(--accent); filter: brightness(1.12); } }
|
||||
/* main action: chamfered, hazard-orange, with a solid edge instead of a blurred shadow (clip-path cuts shadows) */
|
||||
button.primary { background: linear-gradient(#ff8f3a, #e8650a); color: #1a0c02; border: 1px solid #ffa25a;
|
||||
border-bottom: 3px solid #7a3000; font-weight: 700; padding: 8px 20px; min-height: 42px;
|
||||
font-family: var(--head); letter-spacing: .05em; text-transform: uppercase; clip-path: var(--chamfer); box-shadow: none; }
|
||||
button.primary:active { transform: translateY(2px); border-bottom-width: 1px; }
|
||||
button:disabled { opacity: .4; cursor: default; filter: none; }
|
||||
button:disabled:hover { border-color: var(--line); filter: none; }
|
||||
button.link { background: none; border: none; color: var(--accent); padding: 2px 4px; min-height: 0;
|
||||
text-decoration: underline; box-shadow: none; }
|
||||
input[type=text], input[type=password], input[type=email] { font: inherit; width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line);
|
||||
background: #0b0e14; color: var(--text); }
|
||||
input:focus { outline: none; border-color: var(--accent); }
|
||||
|
||||
/* menus fade in once per screen (#overlay.enter is removed again, so live lists do not flicker) */
|
||||
@keyframes cardIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
|
||||
#overlay.enter > * { animation: cardIn .14s ease-out; }
|
||||
.tab, .item, .fitted .frow, .rroom, .prow { transition: border-color .1s, background-color .1s, transform .1s; }
|
||||
@media (hover: hover) { .item:hover { transform: translateY(-2px); } }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*, *::before, *::after { animation: none !important; transition: none !important; }
|
||||
}
|
||||
|
||||
/* every panel shares the same sheen + top highlight */
|
||||
.card, .fbox, #detail, .item, .prow, .hmrow, .rroom, .opp, .stats, .chip, .tab, .fitted .frow {
|
||||
background-image: var(--sheen); box-shadow: var(--hl); }
|
||||
|
||||
/* overlays (menus) */
|
||||
#overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
|
||||
#overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding-top: 40px;
|
||||
background: rgba(5, 6, 10, .62) center / cover no-repeat; z-index: 6; }
|
||||
#overlay::before { content: ''; position: absolute; inset: 0; pointer-events: none;
|
||||
background: radial-gradient(ellipse at 50% 45%, transparent 35%, rgba(0,0,0,.55) 100%); }
|
||||
body[data-mode="title"] #overlay, body[data-mode="intro"] #overlay { padding-top: 0; }
|
||||
#overlay.hide { display: none; }
|
||||
#overlay.clear { background-color: transparent; }
|
||||
.card { background: rgba(21, 25, 32, .94); border: 1px solid var(--line); border-radius: 14px; padding: 22px 30px;
|
||||
min-width: 380px; max-width: 760px; max-height: 520px; overflow-y: auto; text-align: center; box-shadow: 0 20px 60px #000a; }
|
||||
min-width: 380px; max-width: 760px; max-height: 600px; overflow-y: auto; text-align: center; box-shadow: 0 20px 60px #000a; }
|
||||
.card h1 { margin: 0 0 6px; font: 44px var(--head); letter-spacing: .05em; color: var(--accent); text-shadow: 0 3px 0 #5a2600; }
|
||||
.card h2 { margin: 0 0 8px; font: 26px var(--head); letter-spacing: .04em; color: var(--accent); }
|
||||
.card h2 { margin: 0 0 10px; padding-bottom: 8px; font: 26px var(--head); letter-spacing: .04em; color: var(--accent);
|
||||
position: relative; }
|
||||
.card h2::after { content: ''; position: absolute; left: 50%; transform: translateX(-50%); bottom: 0;
|
||||
width: 84px; height: 4px; border-radius: 2px; background: var(--hazard); opacity: .85; }
|
||||
.card h3 { margin: 12px 0 6px; font: 14px var(--head); letter-spacing: .06em; color: var(--dim); text-align: left; }
|
||||
.card p { color: var(--dim); margin: 6px 0 14px; }
|
||||
.board { list-style: none; padding: 0; margin: 14px 0 0; text-align: left; font-variant-numeric: tabular-nums; max-height: 150px; overflow: auto; }
|
||||
@@ -73,13 +125,22 @@
|
||||
.keys b { color: var(--text); }
|
||||
.err { color: var(--warn); font-size: 13px; min-height: 18px; margin: 6px 0; }
|
||||
|
||||
/* title screen */
|
||||
.title { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 38px;
|
||||
background: linear-gradient(180deg, rgba(4,5,8,0) 30%, rgba(4,5,8,.85) 100%); }
|
||||
.title .big { font: 76px var(--head); letter-spacing: .06em; color: var(--accent); text-shadow: 0 5px 0 #5a2600, 0 0 40px rgba(255,122,26,.5); line-height: 1; }
|
||||
.title .tag { color: #c9cfdc; margin: 6px 0 18px; text-shadow: 0 2px 4px #000; }
|
||||
.title .row { margin-top: 8px; }
|
||||
.title .credits { margin-top: 18px; }
|
||||
/* title screen: menu column on the left, the 3D camera ride stays visible on the right */
|
||||
.title { position: absolute; inset: 0; display: flex; align-items: center; justify-content: flex-start;
|
||||
background: linear-gradient(90deg, rgba(4,5,8,.93) 0%, rgba(4,5,8,.8) 30%, rgba(4,5,8,0) 62%); }
|
||||
.tpanel { width: 420px; padding: 0 20px 0 44px; display: flex; flex-direction: column; gap: 10px; text-align: left; }
|
||||
.tlogoimg { width: 100%; max-height: 170px; object-fit: contain; object-position: left center;
|
||||
filter: drop-shadow(0 6px 18px #000); animation: logoglow 3.6s ease-in-out infinite; }
|
||||
@keyframes logoglow { 50% { filter: drop-shadow(0 6px 18px #000) drop-shadow(0 0 14px rgba(255,122,26,.45)); } }
|
||||
.title .big { font: 62px var(--head); letter-spacing: .05em; color: var(--accent); line-height: .98;
|
||||
text-shadow: 0 5px 0 #5a2600, 0 0 40px rgba(255,122,26,.5); }
|
||||
.title .tag { color: #c9cfdc; margin: 0; text-shadow: 0 2px 4px #000; }
|
||||
.hazbar { height: 5px; border-radius: 3px; background: var(--hazard); opacity: .9; }
|
||||
.tmenu { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
|
||||
.tmenu button { min-height: 48px; width: 100%; }
|
||||
.trow2 { display: flex; gap: 6px; flex-wrap: wrap; }
|
||||
.trow2 button { flex: 1 1 auto; font-size: 13px; min-height: 36px; padding: 4px 10px; }
|
||||
.title .credits { margin-top: 10px; }
|
||||
.skip { position: absolute; right: 16px; bottom: 12px; font-size: 12px; color: rgba(255,255,255,.55); }
|
||||
.form { width: 320px; margin: 0 auto; text-align: left; display: flex; flex-direction: column; gap: 8px; }
|
||||
.form label { font-size: 13px; color: var(--dim); }
|
||||
@@ -90,13 +151,13 @@
|
||||
/* settings */
|
||||
.set { display: grid; grid-template-columns: 150px 1fr; gap: 10px 14px; align-items: center; text-align: left; min-width: 460px; }
|
||||
.set input[type=range] { width: 100%; accent-color: var(--accent); }
|
||||
.seg { display: flex; gap: 4px; }
|
||||
.seg button { flex: 1; padding: 5px 8px; font-size: 13px; }
|
||||
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
|
||||
.seg button { flex: 1 1 56px; padding: 5px 8px; font-size: 13px; }
|
||||
.seg button.on { background: var(--accent); color: #1a0c02; border-color: var(--accent); font-weight: 700; }
|
||||
/* compact settings: two columns of label + control */
|
||||
.set2 { display: grid; grid-template-columns: 96px 1fr 96px 1fr; gap: 7px 12px; align-items: center; text-align: left; min-width: 680px; }
|
||||
.set2 .sl, .setacc .sl { font-size: 13px; color: var(--dim); }
|
||||
.set2 .seg button { padding: 6px 4px; font-size: 12px; min-height: 32px; }
|
||||
.set2 .seg button { padding: 6px 4px; font-size: 12px; min-height: 34px; }
|
||||
.set2 input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; }
|
||||
.setacc { display: grid; grid-template-columns: 96px 1fr auto; gap: 12px; align-items: center; text-align: left; margin-top: 12px;
|
||||
padding-top: 10px; border-top: 1px solid var(--line); }
|
||||
@@ -122,14 +183,24 @@
|
||||
.res .plus { color: var(--good); } .res .minus { color: var(--warn); }
|
||||
|
||||
/* shop */
|
||||
#shop { position: absolute; inset: 0; display: grid; grid-template-columns: 340px 1fr; z-index: 3; pointer-events: none; }
|
||||
#shop { position: absolute; inset: 44px 0 0; display: grid; grid-template-columns: 340px 1fr; z-index: 3; pointer-events: none; }
|
||||
#shop.hide, #fightHud.hide { display: none; }
|
||||
#shop > * { pointer-events: auto; }
|
||||
#sLeft { display: flex; flex-direction: column; padding: 12px; gap: 8px; pointer-events: none; }
|
||||
#sLeft > * { pointer-events: auto; }
|
||||
#rname { width: 100%; font: 24px var(--head); letter-spacing: .04em; background: transparent; border: 1px solid transparent;
|
||||
border-radius: 6px; color: var(--text); padding: 2px 6px; text-shadow: 0 2px 6px #000; }
|
||||
#rname:hover, #rname:focus { border-color: var(--line); outline: none; background: rgba(11,14,20,.8); }
|
||||
/* hangar: robot slots at the top of the shop */
|
||||
.hangar { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 4px; }
|
||||
.hslot { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; font-size: 12px; max-width: 120px; }
|
||||
.hslot .hn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.hslot.on { background: var(--accent); color: #1a0c02; border-color: var(--accent); font-weight: 700; }
|
||||
.hslot .hdel { font-size: 11px; opacity: .7; padding: 0 2px; border-radius: 4px; }
|
||||
.hslot .hdel:hover { background: rgba(0,0,0,.25); opacity: 1; }
|
||||
.hadd { padding: 4px 11px; font-size: 15px; font-weight: 700; color: var(--accent); }
|
||||
/* name plate riveted to the robot, always readable (not only on hover) */
|
||||
#rname { width: 100%; font: 24px var(--head); letter-spacing: .04em; background: rgba(11,14,20,.82);
|
||||
border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--r2);
|
||||
color: var(--text); padding: 4px 10px; text-shadow: 0 2px 6px #000; box-shadow: var(--hl); }
|
||||
#rname:hover, #rname:focus { border-color: var(--accent); outline: none; }
|
||||
.mech { display: flex; gap: 8px; align-items: flex-end; }
|
||||
.mech .pic { width: 50px; height: 60px; font-size: 34px; border-radius: 8px; overflow: hidden; background: rgba(0,0,0,.35); border: 1px solid var(--line); }
|
||||
.mech .bubble { background: rgba(250,246,238,.95); color: #1b1d22; border-radius: 10px 10px 10px 2px; padding: 5px 8px; font-size: 12px; max-width: 262px; box-shadow: 0 4px 14px #0008; }
|
||||
@@ -148,37 +219,100 @@
|
||||
.paint span.sw.on { border-color: #fff; }
|
||||
.paint .lb { width: 46px; }
|
||||
#sRight { background: rgba(14,16,22,.9); border-left: 1px solid var(--line); display: flex; flex-direction: column; padding: 10px 12px; gap: 8px; min-height: 0; }
|
||||
.tabs { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
|
||||
.tab { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 4px 2px 3px; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11px; cursor: pointer; }
|
||||
.tab .pic { width: 34px; height: 34px; font-size: 26px; }
|
||||
.tab:hover { border-color: var(--accent); }
|
||||
.tab.on { background: linear-gradient(#3a2414, #241710); border-color: var(--accent); color: var(--accent); font-weight: 700; }
|
||||
#buildView { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
|
||||
#buildView.hide, #paintView.hide, #hangarView.hide { display: none; }
|
||||
#paintView, #hangarView { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
|
||||
/* top mode tabs (Parts / Paint / Hangar) */
|
||||
.shoptabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
|
||||
.shoptabs button { padding: 6px 4px; font: 12.5px var(--head); letter-spacing: .03em; }
|
||||
.shoptabs button.on { background: var(--accent); color: #1a0c02; border-color: var(--accent); }
|
||||
/* zoom bar under the preview */
|
||||
.zoombar { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 12px; color: var(--dim); margin-bottom: 2px; }
|
||||
.zoombar button { width: 30px; height: 26px; padding: 0; font-size: 16px; font-weight: 700; }
|
||||
/* fitted parts strip (bottom of the parts view): 7 compact chips, does not cover the robot preview */
|
||||
.fittedwrap { border-top: 1px solid var(--line); padding-top: 5px; }
|
||||
.flabel { font: 10.5px var(--head); letter-spacing: .12em; text-transform: uppercase; color: var(--dim); margin-bottom: 4px; }
|
||||
.fitted { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
|
||||
.fitted .frow { display: flex; flex-direction: column; align-items: center; gap: 1px; background: rgba(8,10,14,.75);
|
||||
border: 1px solid #262c36; border-radius: var(--r1); padding: 3px 3px 2px; font-size: 11.5px; cursor: pointer;
|
||||
position: relative; min-width: 0; box-shadow: none; }
|
||||
@media (hover: hover) { .fitted .frow:hover { border-color: var(--accent); } }
|
||||
.fitted .frow .pic { width: 18px; height: 18px; font-size: 14px; }
|
||||
.fitted .frow .fn { width: 100%; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.fitted .frow .fn.empty { color: var(--dim); }
|
||||
.fitted .frow .frm { position: absolute; top: -5px; right: -4px; font-size: 11px; color: #fff; background: var(--warn);
|
||||
width: 15px; height: 15px; border-radius: 50%; display: flex; align-items: center; justify-content: center; line-height: 1; }
|
||||
/* hangar management (top-tab Hangar) */
|
||||
.hmgr { display: flex; flex-direction: column; gap: 6px; }
|
||||
.hmrow { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; background: var(--panel2);
|
||||
border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }
|
||||
.hmrow.on { border-color: var(--accent); background: #2a1c10; }
|
||||
.hmrow .hmn { font: 15px var(--head); letter-spacing: .02em; }
|
||||
.hmrow .hmw { font-size: 12px; color: var(--dim); }
|
||||
/* category tabs: a strip of folder tabs sitting ON the card panel - clearly navigation, not parts */
|
||||
.tabs { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; border-bottom: 2px solid var(--line); }
|
||||
.tab { background: #141922; border: 1px solid var(--line); border-bottom: none;
|
||||
border-radius: var(--r2) var(--r2) 0 0; margin-bottom: -2px; padding: 3px 2px 5px;
|
||||
display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: pointer;
|
||||
font-size: 11.5px; letter-spacing: .02em; color: var(--dim); }
|
||||
.tab .pic { width: 24px; height: 24px; font-size: 19px; }
|
||||
@media (hover: hover) { .tab:hover { border-color: var(--accent); } }
|
||||
.tab.on { background: linear-gradient(#3a2414, #1d1410); border-color: var(--accent); color: var(--accent);
|
||||
font-weight: 700; border-bottom: 2px solid #1d1410; } /* open tab merges into the panel below */
|
||||
.tab.miss { border-color: var(--warn); }
|
||||
#cards { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; align-content: start; padding: 2px; }
|
||||
.item { background: linear-gradient(#20252f, #181c24); border: 1px solid var(--line); border-radius: 10px; padding: 6px 6px 5px; cursor: pointer; text-align: center; position: relative; }
|
||||
.item:hover { border-color: #5a6478; }
|
||||
#cards { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
|
||||
align-content: start; padding: 9px; background: rgba(0,0,0,.26); border: 1px solid var(--line); border-top: none;
|
||||
border-radius: 0 0 var(--r2) var(--r2); }
|
||||
.item { background: linear-gradient(#252b37, #171b23); border: 1px solid #39414f; border-radius: var(--r2);
|
||||
padding: 5px 5px 4px; cursor: pointer; text-align: center; position: relative;
|
||||
box-shadow: var(--hl), 0 2px 0 rgba(0,0,0,.45); }
|
||||
@media (hover: hover) { .item:hover { border-color: #5a6478; } }
|
||||
.item.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,122,26,.3); }
|
||||
.item > .pic { width: 100%; height: 62px; font-size: 42px; }
|
||||
.item > .pic { width: 100%; height: 52px; font-size: 38px; }
|
||||
.item .nm { font-size: 12px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.item .pr { font-size: 12px; color: var(--gold); display: flex; gap: 3px; justify-content: center; align-items: center; font-variant-numeric: tabular-nums; }
|
||||
.item .pr { font-size: 12px; color: var(--gold); display: flex; gap: 3px; justify-content: center; align-items: center;
|
||||
font-variant-numeric: tabular-nums; background: rgba(0,0,0,.3); border-radius: var(--r1); padding: 0 4px; margin: 2px auto 0; width: fit-content; }
|
||||
.item .pr .pic { width: 14px; height: 14px; }
|
||||
.item .pr.no { color: var(--warn); }
|
||||
.item .badge { position: absolute; top: 5px; left: 5px; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--accent); color: #1a0c02; }
|
||||
.item .badge.own { background: #3c4556; color: var(--text); }
|
||||
#detail { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: grid; grid-template-columns: 92px 1fr auto; gap: 10px; align-items: center; min-height: 110px; }
|
||||
#detail > .pic { width: 92px; height: 92px; font-size: 60px; }
|
||||
#detail { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: grid; grid-template-columns: 76px 1fr auto; gap: 10px; align-items: center; min-height: 86px; }
|
||||
#detail > .pic { width: 76px; height: 76px; font-size: 52px; }
|
||||
#detail .nm { font: 17px var(--head); letter-spacing: .03em; }
|
||||
#detail .ds { font-size: 12.5px; color: var(--dim); margin: 2px 0 5px; }
|
||||
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
|
||||
.chips span { background: #0f1218; border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: 11.5px; display: inline-flex; gap: 3px; align-items: center; font-variant-numeric: tabular-nums; }
|
||||
.chips span .pic { width: 13px; height: 13px; font-size: 11px; }
|
||||
.chips span.up { color: var(--good); border-color: #2e5a3e; } .chips span.down { color: var(--warn); border-color: #5a2e2e; }
|
||||
.chips span.key { color: var(--accent); border-color: #5a3a18; background: #1d1409; font-weight: 700; }
|
||||
#detail .act { display: flex; flex-direction: column; gap: 6px; min-width: 120px; }
|
||||
#detail .act button { padding: 8px 10px; }
|
||||
#detail .act button { padding: 8px 10px; min-height: 40px; }
|
||||
#detail .act .primary { min-height: 44px; font-size: 15px; }
|
||||
.gbar { display: flex; gap: 6px; align-items: center; }
|
||||
.gbar .err { flex: 1; margin: 0; font-size: 12px; text-align: left; }
|
||||
.gbar .primary { padding: 9px 26px; }
|
||||
|
||||
/* paint tab: proper colour chips instead of tiny dots */
|
||||
#paintView { gap: 10px; }
|
||||
.psec h4 { margin: 0 0 6px; font: 12px var(--head); letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
|
||||
.pgrid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 7px; }
|
||||
.pgrid.wide { grid-template-columns: repeat(8, 1fr); }
|
||||
.pgrid .sw { position: relative; height: 40px; border-radius: var(--r2); border: 2px solid #000a;
|
||||
cursor: pointer; box-shadow: var(--hl), 0 2px 0 rgba(0,0,0,.4); transition: transform .1s; }
|
||||
@media (hover: hover) { .pgrid .sw:hover { transform: translateY(-2px); } }
|
||||
.pgrid .sw.on { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
|
||||
.pgrid .sw.on::after { content: '✓'; position: absolute; inset: 0; display: flex; align-items: center;
|
||||
justify-content: center; color: #fff; font-size: 19px; font-weight: 700; text-shadow: 0 1px 3px #000; }
|
||||
.pgrid .duo { display: flex; overflow: hidden; }
|
||||
.pgrid .duo i { flex: 1; }
|
||||
.pcustom { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
|
||||
background: var(--panel2); background-image: var(--sheen); border: 1px solid var(--line);
|
||||
border-left: 3px solid var(--accent); border-radius: var(--r3); padding: 12px 14px; box-shadow: var(--hl); }
|
||||
.pcustom .pct { display: flex; flex-direction: column; gap: 3px; text-align: left; }
|
||||
.pcustom .pct b { font: 16px var(--head); letter-spacing: .03em; }
|
||||
.pcustom .pct .muted { font-size: 12.5px; }
|
||||
.pcustom .primary { font-size: 22px; padding: 10px 22px; }
|
||||
|
||||
/* paint booth (painter.js) */
|
||||
#painter { grid-column: 2; grid-row: 1; background: rgba(14,16,22,.94); border-left: 1px solid var(--line); display: flex; flex-direction: column; padding: 10px 12px; gap: 7px; }
|
||||
.pt-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
||||
@@ -228,20 +362,34 @@
|
||||
.fl-KR { background: radial-gradient(circle, #cd2e3a 0 14%, #0047a0 15% 28%, transparent 29%), #fff; }
|
||||
.fl-XX { background: repeating-linear-gradient(45deg, #5a6272 0 5px, #454c5a 5px 10px); }
|
||||
.flag.on { background: var(--accent); border-color: var(--accent); }
|
||||
.plist { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin: 4px 0; }
|
||||
.prow { display: grid; grid-template-columns: 34px 1fr auto auto; gap: 10px; align-items: center;
|
||||
background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
|
||||
.prow .pf { line-height: 0; } .prow .pn { font: 16px var(--head); letter-spacing: .02em; text-align: left; }
|
||||
.prow .pfame { color: var(--gold); font-size: 13px; font-variant-numeric: tabular-nums; }
|
||||
.prow .chal { padding: 8px 16px; background: var(--accent); color: #1a0c02; border-color: var(--accent); font-weight: 700; }
|
||||
.prow .pbusy { color: var(--dim); font-size: 13px; padding: 8px 10px; }
|
||||
/* two-pane lobby: country rooms left, player list right (own style) */
|
||||
.lobbyfull { display: grid; grid-template-columns: 318px 1fr; gap: 12px; width: 1040px; height: 560px;
|
||||
background: rgba(21, 25, 32, .95); border: 1px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: 0 20px 60px #000a; }
|
||||
.lobbyL, .lobbyR { display: flex; flex-direction: column; min-height: 0; }
|
||||
.lobbyLh { font: 15px var(--head); letter-spacing: .05em; color: var(--accent); margin-bottom: 8px; }
|
||||
.roomlist { flex: 1; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; align-content: start; padding-right: 2px; }
|
||||
.roomlist .rroom:first-child { grid-column: 1 / -1; }
|
||||
.rroom { display: grid; grid-template-columns: 22px 1fr auto; gap: 6px; align-items: center; padding: 5px 8px; text-align: left; font-size: 12.5px; background: var(--panel2); }
|
||||
.rroom .rfl { line-height: 0; } .rroom .rfl .fl { width: 22px; height: 14px; }
|
||||
.rroom .rn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.rroom .cnt { font-variant-numeric: tabular-nums; color: var(--dim); font-size: 12px; min-width: 16px; text-align: right; }
|
||||
.rroom .cnt.live { color: var(--good); font-weight: 700; }
|
||||
.rroom.on { background: var(--accent); color: #1a0c02; border-color: var(--accent); font-weight: 700; }
|
||||
.rroom.on .cnt { color: #1a0c02; }
|
||||
.lobbyRh { display: flex; align-items: center; gap: 8px; font: 18px var(--head); letter-spacing: .03em; margin-bottom: 8px; }
|
||||
.lobbyRh .grow { flex: 1; }
|
||||
.lobbyRh .flagpick { font: 12px "Segoe UI", sans-serif; color: var(--dim); display: flex; gap: 6px; align-items: center; }
|
||||
.lobbyRh select { font: inherit; font-size: 13px; color: var(--text); background: #0b0e14; border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; cursor: pointer; }
|
||||
.lobbyR .plist { flex: 1; max-height: none; }
|
||||
.plist { max-height: 316px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin: 4px 0; min-width: 440px; }
|
||||
.prow { display: grid; grid-template-columns: 28px 1fr auto auto; gap: 9px; align-items: center;
|
||||
background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; padding: 4px 9px; }
|
||||
.prow .pf { line-height: 0; } .prow .pn { font-size: 13px; font-weight: 700; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.prow .pfame { color: var(--gold); font-size: 12.5px; font-variant-numeric: tabular-nums; }
|
||||
.prow .chal { padding: 5px 14px; font-size: 13px; background: var(--accent); color: #1a0c02; border-color: var(--accent); font-weight: 700; }
|
||||
.prow .pbusy { color: var(--dim); font-size: 12px; padding: 5px 8px; }
|
||||
.prow.me { border-color: var(--accent); background: #2a1c10; }
|
||||
/* country rooms */
|
||||
.rooms { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0; }
|
||||
.room { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center; padding: 10px 12px; min-height: 48px; text-align: left; }
|
||||
.room .rn { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.room .rc { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
|
||||
.room.live .rc { color: var(--good); font-weight: 700; }
|
||||
.prow .pf .fl { width: 26px; height: 17px; }
|
||||
|
||||
/* fight HUD */
|
||||
#fightHud { position: absolute; left: 0; right: 0; top: 0; padding: 10px 14px; display: grid; grid-template-columns: 1fr 150px 1fr;
|
||||
@@ -249,21 +397,71 @@
|
||||
.fbox { background: rgba(10, 12, 16, .78); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
|
||||
.fbox .fn { font: 16px var(--head); letter-spacing: .04em; display: flex; justify-content: space-between; }
|
||||
.fbox .fn small { font: 12px "Segoe UI", sans-serif; color: var(--dim); }
|
||||
.hp { height: 12px; background: #0b0e14; border-radius: 6px; overflow: hidden; margin-top: 4px; border: 1px solid #000; }
|
||||
.hp i { display: block; height: 100%; transition: width .15s; }
|
||||
.fsub { display: flex; gap: 8px; align-items: center; margin-top: 4px; font-size: 11.5px; color: var(--dim);
|
||||
font-variant-numeric: tabular-nums; min-height: 15px; }
|
||||
#fRight .fsub { flex-direction: row-reverse; }
|
||||
.fsub .lost { color: var(--warn); font-weight: 700; }
|
||||
.fsub .hpn { font-weight: 700; color: var(--text); }
|
||||
.fsub .pts { display: flex; gap: 5px; }
|
||||
.fsub .pt { position: relative; line-height: 0; }
|
||||
.fsub .pt .pic { width: 17px; height: 17px; font-size: 13px; }
|
||||
.fsub .pt.gone { opacity: .45; }
|
||||
.fsub .pt.gone::after { content: '✕'; position: absolute; inset: 0; display: flex; align-items: center;
|
||||
justify-content: center; color: var(--warn); font-size: 15px; font-weight: 700; line-height: 1; }
|
||||
.hp { position: relative; height: 16px; background: #0b0e14; border-radius: 3px; overflow: hidden;
|
||||
margin-top: 5px; border: 1px solid #000; transform: skewX(-12deg); }
|
||||
.hp i { position: absolute; left: 0; top: 0; bottom: 0; transition: width .15s; }
|
||||
.hp i.g { background: #8d2018; transition: width .55s ease .2s; } /* damage trail */
|
||||
.hp::after { content: ''; position: absolute; inset: 0; pointer-events: none;
|
||||
background: repeating-linear-gradient(90deg, transparent 0 17px, rgba(0,0,0,.55) 17px 19px); }
|
||||
.fbox.hurt { border-color: var(--warn); animation: lowhp 1s infinite; }
|
||||
@keyframes lowhp { 50% { border-color: var(--line); } }
|
||||
.fbox.hit { background-color: rgba(255,90,74,.3); }
|
||||
#fRight { text-align: right; } #fRight .fn { flex-direction: row-reverse; }
|
||||
#fMid { text-align: center; }
|
||||
#fTime { font: 34px var(--head); line-height: 1; letter-spacing: .04em; }
|
||||
#fTime.low { color: var(--warn); }
|
||||
#fTime.low { color: var(--warn); animation: tick 1s steps(2) infinite; }
|
||||
@keyframes tick { 50% { opacity: .45; } }
|
||||
#fState { font-size: 12px; color: var(--accent); min-height: 16px; font-weight: 700; letter-spacing: .05em; }
|
||||
|
||||
/* cooldown chips: ring empties while the part recharges */
|
||||
#fCds { position: absolute; left: 50%; transform: translateX(-50%); bottom: 58px; z-index: 4; display: none;
|
||||
gap: 14px; pointer-events: none; }
|
||||
body[data-mode="fight"] #fCds, body[data-mode="pause"] #fCds { display: flex; }
|
||||
.cdchip { --p: 0; position: relative; width: 52px; height: 52px; border-radius: 50%; padding: 3px;
|
||||
background: conic-gradient(#2b3240 calc(var(--p) * 360deg), var(--accent) 0); }
|
||||
.cdchip .in { width: 100%; height: 100%; border-radius: 50%; background: #0d1016; border: 1px solid #000;
|
||||
display: flex; align-items: center; justify-content: center; }
|
||||
.cdchip .pic { width: 32px; height: 32px; font-size: 22px; }
|
||||
.cdchip.on { box-shadow: 0 0 0 2px var(--accent); }
|
||||
.cdchip.spent { opacity: .45; }
|
||||
.cdchip.broke { background: #3a2020; opacity: .8; }
|
||||
.cdchip.broke .in { border-color: var(--warn); }
|
||||
.cdchip.broke::after { content: '✕'; position: absolute; inset: 0; display: flex; align-items: center;
|
||||
justify-content: center; color: var(--warn); font-size: 30px; font-weight: 700; text-shadow: 0 2px 4px #000; }
|
||||
.cdchip .k { position: absolute; left: 0; right: 0; bottom: -15px; text-align: center; font-size: 11px;
|
||||
color: var(--dim); font-weight: 700; }
|
||||
.cdchip .n { position: absolute; top: -3px; right: -3px; min-width: 17px; height: 17px; border-radius: 9px;
|
||||
background: var(--accent); color: #1a0c02; font-size: 11px; font-weight: 700; line-height: 17px; text-align: center; }
|
||||
/* on touch the pad owns the bottom edge, so the chips move above it */
|
||||
@media (pointer: coarse) { .cdchip .k { display: none; } #fCds { bottom: 110px; } }
|
||||
body.forcetouch #fCds { bottom: 110px; }
|
||||
|
||||
/* own damage: the screen edge glows red the closer you are to being wrecked */
|
||||
#dmgvig { position: absolute; inset: 0; z-index: 3; pointer-events: none; opacity: 0; transition: opacity .25s;
|
||||
background: radial-gradient(ellipse at 50% 50%, transparent 45%, rgba(190,20,10,.75) 100%); }
|
||||
|
||||
/* touch pad: only on touch screens */
|
||||
#pad { position: absolute; left: 14px; right: 14px; bottom: 14px; display: none; justify-content: space-between; pointer-events: none; z-index: 5; }
|
||||
#pad > div { display: grid; grid-template-columns: repeat(3, 60px); gap: 6px; pointer-events: auto; }
|
||||
#pad button { height: 60px; font-size: 20px; opacity: .7; padding: 0; }
|
||||
#pad .fire { grid-template-columns: repeat(2, 74px); }
|
||||
#pad .fire button { height: 74px; font-size: 14px; font-weight: 700; }
|
||||
#pad button { height: 60px; font-size: 20px; opacity: .75; padding: 0; border-radius: var(--r3);
|
||||
background: rgba(18,22,30,.72); }
|
||||
#pad .fire { grid-template-columns: repeat(3, 74px); }
|
||||
#pad .fire button { height: 74px; font-size: 13px; font-weight: 700; border-radius: 50%; }
|
||||
#padGadget { --p: 0; background:
|
||||
conic-gradient(rgba(18,22,30,.72) calc(var(--p) * 360deg), rgba(255,122,26,.5) 0); }
|
||||
@media (pointer: coarse) { body.fighting #pad { display: flex; } }
|
||||
body.forcetouch.fighting #pad { display: flex; } /* dev: &touch */
|
||||
|
||||
/* tablets / phones held upright: ask to rotate (the stage is 16:9) */
|
||||
#rotate { display: none; position: fixed; left: 0; right: 0; bottom: 12%; text-align: center; z-index: 20; font: 20px var(--head); color: var(--accent); padding: 0 20px; }
|
||||
@@ -272,7 +470,9 @@
|
||||
/* window buttons: only inside the exe (html.exe set by kit-host.js) */
|
||||
#winctl { position: fixed; top: 8px; right: 8px; display: none; gap: 6px; z-index: 10; }
|
||||
html.exe #winctl { display: flex; }
|
||||
#winctl button { width: 34px; height: 30px; padding: 0; opacity: .75; }
|
||||
#winctl button { width: 34px; height: 30px; min-height: 30px; padding: 0; opacity: .75; }
|
||||
html.exe #hud { padding-right: 130px; }
|
||||
html.exe #fightHud { padding: 10px 130px 0; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -284,17 +484,6 @@
|
||||
|
||||
<div id="rotate">↻ <span data-i18n="rotate_hint">Turn your device sideways</span></div>
|
||||
<div id="app">
|
||||
<div id="hud">
|
||||
<div class="logo">ROBOT CLASH</div>
|
||||
<div class="chip" data-i18n-title="hud_money"><span class="pic" data-f="🪙" id="icoMoney"></span><b id="hMoney">0</b></div>
|
||||
<div class="chip" data-i18n-title="hud_fame"><span class="pic" data-f="⭐" id="icoFame"></span><b id="hFame">0</b></div>
|
||||
<div class="chip"><span data-i18n="hud_league">League</span> <b id="hLeague">-</b></div>
|
||||
<div class="grow"></div>
|
||||
<div class="chip" id="hUser" data-i18n-title="account"></div>
|
||||
<button id="bSettings" data-i18n-title="settings">⚙</button>
|
||||
<button id="bMute" title="M">Sound</button>
|
||||
<button id="bPause" title="P / Esc" data-i18n="pause">Pause</button>
|
||||
</div>
|
||||
<div id="stage">
|
||||
<div id="bgimg"></div>
|
||||
<canvas id="gl"></canvas>
|
||||
@@ -303,17 +492,30 @@
|
||||
<div id="shop" class="hide">
|
||||
<div id="sLeft">
|
||||
<input id="rname" maxlength="18" spellcheck="false">
|
||||
<div class="mech"><span class="pic" data-f="🧔" id="mechPic"></span><div class="bubble" id="mechTip"></div></div>
|
||||
<div class="zoombar"><button id="zOut" title="Zoom -">-</button><span data-i18n="zoom">Zoom</span><button id="zIn" title="Zoom +">+</button></div>
|
||||
<div class="spacer"></div>
|
||||
<div class="stats" id="meters"></div>
|
||||
<div class="paint" id="paintBody"></div>
|
||||
<div class="paint" id="paintAccent"></div>
|
||||
<button id="bPaint" data-i18n="pt_open">🎨 Paint it yourself</button>
|
||||
<div class="mech"><span class="pic" data-f="🧔" id="mechPic"></span><div class="bubble" id="mechTip"></div></div>
|
||||
</div>
|
||||
<div id="sRight">
|
||||
<div class="shoptabs" id="shopTabs"></div>
|
||||
<div id="buildView">
|
||||
<div class="tabs" id="tabs"></div>
|
||||
<div id="cards"></div>
|
||||
<div id="detail"></div>
|
||||
<div class="fittedwrap"><div class="flabel" data-i18n="fitted_parts">Fitted</div><div id="fitted" class="fitted"></div></div>
|
||||
</div>
|
||||
<div id="paintView" class="hide">
|
||||
<div class="psec"><h4 data-i18n="paint_body">Body</h4><div class="pgrid" id="paintBody"></div></div>
|
||||
<div class="psec"><h4 data-i18n="paint_accent">Accent</h4><div class="pgrid" id="paintAccent"></div></div>
|
||||
<div class="psec"><h4 data-i18n="paint_schemes">Schemes</h4><div class="pgrid wide" id="paintSchemes"></div></div>
|
||||
<div class="spacer"></div>
|
||||
<div class="pcustom">
|
||||
<div class="pct"><b data-i18n="pt_open">Paint it yourself</b><span class="muted" data-i18n="paint_hint">Pick quick colours above, or paint your own design.</span></div>
|
||||
<button id="bPaint" class="primary">🎨</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="hangarView" class="hide"></div>
|
||||
<div class="gbar">
|
||||
<div class="err" id="gErr"></div>
|
||||
<button id="bGMenu" data-i18n="menu">Menu</button>
|
||||
@@ -325,20 +527,34 @@
|
||||
</div>
|
||||
|
||||
<div id="fightHud" class="hide">
|
||||
<div class="fbox" id="fLeft"><div class="fn"><span id="fN0"></span><small id="fW0"></small></div><div class="hp"><i id="fH0"></i></div></div>
|
||||
<div class="fbox" id="fLeft"><div class="fn"><span id="fN0"></span><small id="fW0"></small></div><div class="hp"><i class="g" id="fG0"></i><i id="fH0"></i></div><div class="fsub" id="fD0"></div></div>
|
||||
<div class="fbox" id="fMid"><div id="fTime">2:00</div><div id="fState"></div></div>
|
||||
<div class="fbox" id="fRight"><div class="fn"><span id="fN1"></span><small id="fW1"></small></div><div class="hp"><i id="fH1"></i></div></div>
|
||||
<div class="fbox" id="fRight"><div class="fn"><span id="fN1"></span><small id="fW1"></small></div><div class="hp"><i class="g" id="fG1"></i><i id="fH1"></i></div><div class="fsub" id="fD1"></div></div>
|
||||
</div>
|
||||
|
||||
<div id="dmgvig"></div>
|
||||
<div id="fCds"></div>
|
||||
|
||||
<div id="pad">
|
||||
<div>
|
||||
<span></span><button data-action="up">▲</button><span></span>
|
||||
<button data-action="left">◀</button><button data-action="down">▼</button><button data-action="right">▶</button>
|
||||
</div>
|
||||
<div class="fire">
|
||||
<button data-action="fire2" data-i18n="pad_tower">Tower</button><button data-action="fire" data-i18n="pad_weapon">Weapon</button>
|
||||
<button data-action="fire3" data-i18n="pad_gadget" id="padGadget">Gadget</button><button data-action="fire2" data-i18n="pad_tower">Tower</button><button data-action="fire" data-i18n="pad_weapon">Weapon</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="hud">
|
||||
<div class="logo">ROBOT CLASH</div>
|
||||
<div class="chip" data-i18n-title="hud_money"><span class="pic" data-f="🪙" id="icoMoney"></span><b id="hMoney">0</b></div>
|
||||
<div class="chip" data-i18n-title="hud_fame"><span class="pic" data-f="⭐" id="icoFame"></span><b id="hFame">0</b></div>
|
||||
<div class="chip"><span data-i18n="hud_league">League</span> <b id="hLeague">-</b></div>
|
||||
<div class="grow"></div>
|
||||
<div class="chip" id="hUser" data-i18n-title="account"></div>
|
||||
<button id="bSettings" class="icobtn" data-i18n-title="settings">⚙</button>
|
||||
<button id="bMute" class="icobtn" title="M">🔊</button>
|
||||
<button id="bPause" class="icobtn" title="P / Esc" data-i18n-title="pause">⏸</button>
|
||||
</div>
|
||||
<div id="overlay" class="hide"></div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -365,6 +581,7 @@
|
||||
<script src="netfight.js"></script>
|
||||
<script src="shop.js"></script>
|
||||
<script src="painter.js"></script>
|
||||
<script src="uicheck.js"></script>
|
||||
<script src="game.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
const scores = Kit.scores({ url: 'https://<project>-default-rtdb.europe-west1.firebasedatabase.app' });
|
||||
if (scores.enabled) {
|
||||
const rows = await scores.top(10); // [{ key, name, score, level, time }] best first
|
||||
const rows = await scores.top(10); // [{ key, name, score, level, time }] best first,
|
||||
// one row per player (their best run)
|
||||
const key = await scores.submit({ name, score, level }); // key of the new entry or null
|
||||
}
|
||||
Kit.cleanName(s) -> trimmed, max 20 chars, no control chars / angle brackets
|
||||
@@ -36,16 +37,22 @@
|
||||
enabled,
|
||||
async top(n = 10) {
|
||||
if (!enabled) return [];
|
||||
// fetch spare rows: filtered names must not leave the list short
|
||||
const q = new URLSearchParams({ orderBy: '"score"', limitToLast: String(n + 15) });
|
||||
// fetch spare rows: filtered names and repeat entries by the same player must not leave the list short
|
||||
const q = new URLSearchParams({ orderBy: '"score"', limitToLast: String(n * 4 + 25) });
|
||||
const res = await fetch(`${url}/${path}.json?${q}`, { cache: 'no-store' });
|
||||
if (!res.ok) throw new Error('scores ' + res.status);
|
||||
const data = (await res.json()) || {};
|
||||
return Object.entries(data)
|
||||
const rows = Object.entries(data)
|
||||
.map(([key, v]) => Object.assign({ key }, v))
|
||||
.filter(v => typeof v.name === 'string' && typeof v.score === 'number' && !Kit.badName(v.name))
|
||||
.sort((a, b) => b.score - a.score || (a.time || 0) - (b.time || 0))
|
||||
.slice(0, n);
|
||||
.sort((a, b) => b.score - a.score || (a.time || 0) - (b.time || 0));
|
||||
// every player appears once, with their best run (each submit writes its own row)
|
||||
const best = new Map();
|
||||
for (const r of rows) {
|
||||
const who = r.name.trim().toLowerCase();
|
||||
if (!best.has(who)) best.set(who, r);
|
||||
}
|
||||
return Array.from(best.values()).slice(0, n);
|
||||
},
|
||||
async submit({ name, score, level = 1 }) {
|
||||
name = Kit.cleanName(name);
|
||||
|
||||
86
game/lang.js
@@ -25,8 +25,8 @@ window.LANG = {
|
||||
// workshop
|
||||
to_league: 'League', training: 'Training', unarmed: 'unarmed',
|
||||
slot_chassis: 'Chassis', slot_motor: 'Motor', slot_wheels: 'Wheels', slot_battery: 'Battery',
|
||||
slot_armour: 'Armour', slot_weapon: 'Weapon', slot_tower: 'Tower',
|
||||
none: 'None', none_armour: 'Bare chassis - light but fragile.', none_weapon: 'No weapon - only ramming.', none_tower: 'No tower weapon.',
|
||||
slot_armour: 'Armour', slot_weapon: 'Weapon', slot_tower: 'Tower', slot_gadget: 'Gadget',
|
||||
none: 'None', none_armour: 'Bare chassis - light but fragile.', none_weapon: 'No weapon - only ramming.', none_tower: 'No tower weapon.', none_gadget: 'No gadget.',
|
||||
equipped: 'fitted', equip: 'Fit', sell: 'Sell {n}', buy: 'Buy {n}',
|
||||
st_hp: '{n} HP', st_speed: '{n} m/s', st_force: '{n} N', st_grip: 'grip {n}', st_turn: 'turn {n}', st_invert: 'drives upside down',
|
||||
st_reduce: '-{n}% damage', st_dmg: '{n} dmg', st_dps: '{n} dmg/s', st_range: 'range {n} m', st_weight: '{n} kg',
|
||||
@@ -43,11 +43,25 @@ window.LANG = {
|
||||
pd_bulldog: 'Huge torque for pushing.',
|
||||
pd_comet: 'Top speed for hit and run.',
|
||||
pd_rubber: 'Four small wheels, nimble.',
|
||||
pd_cage: 'Open scrap frame: dirt cheap and light, but it dents fast.',
|
||||
pd_hexpod: 'Six-sided shell, angled all round so hits glance off.',
|
||||
pd_boiler: 'Rolled steel drum, tough and tall.',
|
||||
pd_fang: 'Long pointed prow, low and quick - hard to flip.',
|
||||
pd_plough: 'Heavy plough blade bolted to the nose, shrugs off front hits.',
|
||||
pd_discus: 'Wide flat disc, sits low and takes a beating.',
|
||||
pd_omni: 'Caster wheels: spins on the spot, great steering.',
|
||||
pd_bigtyre: 'Taller than the robot: keeps driving when flipped.',
|
||||
pd_studs: 'Studded grip, drives upside down, strong shove.',
|
||||
pd_drumwh: 'Single roller drum: fast and heavy-pushing.',
|
||||
pd_tracks: 'Massive grip, wins every shoving match.',
|
||||
pd_hover: 'Air skirt: very fast but slippery, draws power.',
|
||||
pd_lead: 'Heavy, but it works.',
|
||||
pd_nicd: 'More power, less weight.',
|
||||
pd_lipo: 'Light and powerful.',
|
||||
pd_mesh: 'Thin wire grille - barely any weight, barely any protection.',
|
||||
pd_buffer: 'Fat rubber buffers that soak up rams.',
|
||||
pd_spiked: 'Plates with spikes, and they look the part.',
|
||||
pd_ceramic: 'Ceramic tiles, light and very tough.',
|
||||
pd_steel: 'Basic plates, absorb some damage.',
|
||||
pd_titan: 'Light and tough.',
|
||||
pd_hardox: 'Wear plate - the toughest skin money can buy.',
|
||||
@@ -57,9 +71,24 @@ window.LANG = {
|
||||
pd_saw: 'Hold Space to cut through anything in front.',
|
||||
pd_crusher: 'Grabs and crushes - drag them into the hazards!',
|
||||
pd_spinner: 'Hold Space to spin up, release the energy on contact.',
|
||||
pd_lance: 'Long spike: big ramming damage, cheap and light.',
|
||||
pd_drill: 'Grinding auger, chews through armour up close.',
|
||||
pd_mace: 'Heavy spiked ball on an arm, slow but brutal.',
|
||||
pd_launcher: 'Big scoop that launches the enemy high into the air.',
|
||||
pd_drum: 'Drum spinner: fast spin-up, reliable hits.',
|
||||
pd_lifter: 'Scoop that tips them up over and over - shove them into the pit.',
|
||||
pd_vdisc: 'Vertical disc: throws the enemy straight up into the air.',
|
||||
pd_flamer: 'Short-range fire, burns through armour.',
|
||||
pd_minigun: 'Steady rivet fire from range.',
|
||||
pd_rockets: 'Homing rockets every few seconds.',
|
||||
pd_zapper: 'Electric arc up close, eats through armour and jolts them.',
|
||||
pd_mortar: 'Lobs a shell in an arc that bursts where it lands.',
|
||||
pd_swarm: 'Three small rockets that chase them right across the arena.',
|
||||
pd_righter: 'Flips you back upright when on your roof (G).',
|
||||
pd_turbo: 'Short burst of speed and push (G).',
|
||||
pd_shield: 'Field that cuts damage for a few seconds (G).',
|
||||
pd_repair: 'Patches hull - two charges (G).',
|
||||
pd_emp: 'Stuns a nearby enemy for a moment (G).',
|
||||
// league
|
||||
league_title: 'League - season {s}',
|
||||
league_text: 'Beat the opponents one after another. Each season they get tougher and pay more.',
|
||||
@@ -67,7 +96,10 @@ window.LANG = {
|
||||
style_brawler: 'Brawler - straight at you', style_flanker: 'Flanker - goes for your back', style_pusher: 'Pusher - loves the pit',
|
||||
style_gunner: 'Gunner - keeps its distance', style_dummy: 'Training dummy',
|
||||
// fight
|
||||
pad_weapon: 'Weapon', pad_tower: 'Tower',
|
||||
pad_weapon: 'Weapon', pad_tower: 'Tower', pad_gadget: 'Gadget', fitted_parts: 'Fitted',
|
||||
paint_schemes: 'Schemes',
|
||||
hk_weapon: 'Space', hk_tower: 'Shift / E', hk_gadget: 'G',
|
||||
broke_you: 'Your {p} broke off!', broke_enemy: "Enemy's {p} broke off!",
|
||||
fight_go: 'ACTIVATE!', pit_open: 'PIT OPEN!', into_pit: 'INTO THE PIT!', knockout: 'KNOCKOUT!',
|
||||
fight_hint: 'W/S drive · A/D turn · Space weapon · Shift / E tower · C camera · P pause',
|
||||
st_lifted: 'MAGNET!', st_grabbed: 'GRABBED!', st_flipped: 'UPSIDE DOWN!', st_stunned: 'STUNNED', pit_is_open: 'PIT IS OPEN', pit_soon: 'pit opens soon',
|
||||
@@ -105,7 +137,12 @@ window.LANG = {
|
||||
// online lobby + live PvP
|
||||
rotate_hint: 'Turn your device sideways for a bigger picture',
|
||||
s_account: 'Account',
|
||||
tab_build: 'Parts', tab_paint: 'Paint', tab_hangar: 'Hangar', zoom: 'Zoom',
|
||||
active_robot: 'active', use: 'Use', delete: 'Delete', hangar_full: 'Hangar full (max 6).', paint_hint: 'Pick quick colours above, or paint your own design.',
|
||||
robot_n: 'Robot {n}', new_robot: 'New robot',
|
||||
all_countries: 'All countries', filter_country: 'Show:',
|
||||
s_arena: 'Arena', arena_random: 'Random', arena_workshop: 'Workshop Pit', arena_foundry: 'The Foundry', arena_arena64: 'Mega Dome',
|
||||
arena_scrapyard: 'Scrapyard', arena_crucible: 'The Crucible', arena_colosseum: 'Grand Colosseum',
|
||||
peer_back: 'Opponent is back', no_pause_online: 'No pause in live fights',
|
||||
r_draw_prize: 'Draw prize',
|
||||
online_guest: 'Join as guest (no e-mail)', online_short: '🌍 Online',
|
||||
@@ -192,8 +229,8 @@ window.LANG = {
|
||||
// workshop
|
||||
to_league: 'Liga', training: 'Training', unarmed: 'unbewaffnet',
|
||||
slot_chassis: 'Chassis', slot_motor: 'Motor', slot_wheels: 'Räder', slot_battery: 'Batterie',
|
||||
slot_armour: 'Panzer', slot_weapon: 'Waffe', slot_tower: 'Turm',
|
||||
none: 'Keine', none_armour: 'Nacktes Chassis – leicht, aber empfindlich.', none_weapon: 'Keine Waffe – nur rammen.', none_tower: 'Keine Turmwaffe.',
|
||||
slot_armour: 'Panzer', slot_weapon: 'Waffe', slot_tower: 'Turm', slot_gadget: 'Gadget',
|
||||
none: 'Keine', none_armour: 'Nacktes Chassis – leicht, aber empfindlich.', none_weapon: 'Keine Waffe – nur rammen.', none_tower: 'Keine Turmwaffe.', none_gadget: 'Kein Gadget.',
|
||||
equipped: 'eingebaut', equip: 'Einbauen', sell: 'Verkaufen {n}', buy: 'Kaufen {n}',
|
||||
st_hp: '{n} LP', st_speed: '{n} m/s', st_force: '{n} N', st_grip: 'Grip {n}', st_turn: 'Wendig {n}', st_invert: 'fährt auch auf dem Kopf',
|
||||
st_reduce: '-{n}% Schaden', st_dmg: '{n} Schaden', st_dps: '{n} Schaden/s', st_range: 'Reichweite {n} m', st_weight: '{n} kg',
|
||||
@@ -210,11 +247,25 @@ window.LANG = {
|
||||
pd_bulldog: 'Riesiges Drehmoment zum Schieben.',
|
||||
pd_comet: 'Höchsttempo für Angriff und Rückzug.',
|
||||
pd_rubber: 'Vier kleine Räder, wendig.',
|
||||
pd_cage: 'Offener Schrottrahmen: spottbillig und leicht, aber schnell verbeult.',
|
||||
pd_hexpod: 'Sechseckige Schale, rundum abgeschrägt – Treffer rutschen ab.',
|
||||
pd_boiler: 'Gewalzte Stahltonne, zäh und hoch.',
|
||||
pd_fang: 'Lange Spitze vorn, flach und flink – schwer umzuwerfen.',
|
||||
pd_plough: 'Schweres Räumschild an der Nase, steckt Fronttreffer weg.',
|
||||
pd_discus: 'Breite flache Scheibe, liegt tief und hält viel aus.',
|
||||
pd_omni: 'Lenkrollen: dreht auf der Stelle, top Lenkung.',
|
||||
pd_bigtyre: 'Höher als der Roboter: fährt auch umgedreht weiter.',
|
||||
pd_studs: 'Spike-Grip, fährt auch umgedreht, starkes Schieben.',
|
||||
pd_drumwh: 'Eine Walze: schnell und schiebt schwer.',
|
||||
pd_tracks: 'Enormer Grip, gewinnt jedes Schiebeduell.',
|
||||
pd_hover: 'Luftkissen: sehr schnell, aber rutschig, braucht Strom.',
|
||||
pd_lead: 'Schwer, aber sie tut es.',
|
||||
pd_nicd: 'Mehr Strom, weniger Gewicht.',
|
||||
pd_lipo: 'Leicht und stark.',
|
||||
pd_mesh: 'Dünnes Drahtgitter – kaum Gewicht, kaum Schutz.',
|
||||
pd_buffer: 'Dicke Gummipuffer, die Rammstöße schlucken.',
|
||||
pd_spiked: 'Platten mit Stacheln, sehen auch so aus.',
|
||||
pd_ceramic: 'Keramikkacheln, leicht und sehr zäh.',
|
||||
pd_steel: 'Einfache Platten, schlucken etwas Schaden.',
|
||||
pd_titan: 'Leicht und zäh.',
|
||||
pd_hardox: 'Verschleißblech – die härteste Haut, die es zu kaufen gibt.',
|
||||
@@ -224,9 +275,24 @@ window.LANG = {
|
||||
pd_saw: 'Leertaste halten und alles vor dir zersägen.',
|
||||
pd_crusher: 'Packt zu und quetscht – zieh sie in die Fallen!',
|
||||
pd_spinner: 'Leertaste halten zum Hochdrehen, die Energie entlädt sich beim Treffer.',
|
||||
pd_lance: 'Lange Spitze: viel Rammschaden, billig und leicht.',
|
||||
pd_drill: 'Mahlende Bohrschnecke, frisst sich nah durch Panzerung.',
|
||||
pd_mace: 'Schwere Stachelkugel am Arm, langsam aber brutal.',
|
||||
pd_launcher: 'Große Schaufel, die den Gegner hoch in die Luft wirft.',
|
||||
pd_drum: 'Walzen-Spinner: schnelles Hochdrehen, sichere Treffer.',
|
||||
pd_lifter: 'Schaufel, die den Gegner immer wieder anhebt – ab in die Grube.',
|
||||
pd_vdisc: 'Vertikale Scheibe: wirft den Gegner senkrecht in die Luft.',
|
||||
pd_flamer: 'Feuer auf kurze Distanz, brennt durch Panzerung.',
|
||||
pd_minigun: 'Stetiges Nietenfeuer aus der Ferne.',
|
||||
pd_rockets: 'Zielsuchende Raketen alle paar Sekunden.',
|
||||
pd_zapper: 'Lichtbogen auf kurze Distanz, frisst Panzerung und lähmt kurz.',
|
||||
pd_mortar: 'Wirft eine Granate im Bogen, die beim Aufschlag explodiert.',
|
||||
pd_swarm: 'Drei kleine Raketen, die quer durch die Arena hinterherjagen.',
|
||||
pd_righter: 'Dreht dich wieder auf die Räder, wenn du auf dem Rücken liegst (G).',
|
||||
pd_turbo: 'Kurzer Schub aus Tempo und Wucht (G).',
|
||||
pd_shield: 'Feld, das ein paar Sekunden Schaden abfängt (G).',
|
||||
pd_repair: 'Flickt die Hülle – zwei Ladungen (G).',
|
||||
pd_emp: 'Legt einen nahen Gegner kurz lahm (G).',
|
||||
// league
|
||||
league_title: 'Liga – Saison {s}',
|
||||
league_text: 'Besiege die Gegner nacheinander. Jede Saison werden sie härter und zahlen mehr.',
|
||||
@@ -234,7 +300,10 @@ window.LANG = {
|
||||
style_brawler: 'Raufbold – kommt direkt auf dich zu', style_flanker: 'Flankierer – will an dein Heck', style_pusher: 'Schieber – liebt die Grube',
|
||||
style_gunner: 'Schütze – hält Abstand', style_dummy: 'Trainingsroboter',
|
||||
// fight
|
||||
pad_weapon: 'Waffe', pad_tower: 'Turm',
|
||||
pad_weapon: 'Waffe', pad_tower: 'Turm', pad_gadget: 'Gadget', fitted_parts: 'Verbaut',
|
||||
paint_schemes: 'Vorlagen',
|
||||
hk_weapon: 'Leertaste', hk_tower: 'Shift / E', hk_gadget: 'G',
|
||||
broke_you: '{p} abgerissen!', broke_enemy: '{p} des Gegners abgerissen!',
|
||||
fight_go: 'AKTIVIEREN!', pit_open: 'GRUBE OFFEN!', into_pit: 'IN DIE GRUBE!', knockout: 'K.O.!',
|
||||
fight_hint: 'W/S fahren · A/D drehen · Leertaste Waffe · Shift / E Turm · C Kamera · P Pause',
|
||||
st_lifted: 'MAGNET!', st_grabbed: 'GEPACKT!', st_flipped: 'AUF DEM KOPF!', st_stunned: 'BETÄUBT', pit_is_open: 'GRUBE IST OFFEN', pit_soon: 'Grube öffnet gleich',
|
||||
@@ -272,7 +341,12 @@ window.LANG = {
|
||||
// online lobby + live PvP
|
||||
rotate_hint: 'Dreh dein Gerät quer für ein größeres Bild',
|
||||
s_account: 'Konto',
|
||||
tab_build: 'Teile', tab_paint: 'Lackieren', tab_hangar: 'Hangar', zoom: 'Zoom',
|
||||
active_robot: 'aktiv', use: 'Nutzen', delete: 'Löschen', hangar_full: 'Hangar voll (max. 6).', paint_hint: 'Oben schnelle Farben, oder male dein eigenes Design.',
|
||||
robot_n: 'Roboter {n}', new_robot: 'Neuer Roboter',
|
||||
all_countries: 'Alle Länder', filter_country: 'Zeigen:',
|
||||
s_arena: 'Arena', arena_random: 'Zufällig', arena_workshop: 'Werkstatt-Grube', arena_foundry: 'Die Gießerei', arena_arena64: 'Mega-Dome',
|
||||
arena_scrapyard: 'Schrottplatz', arena_crucible: 'Der Schmelztiegel', arena_colosseum: 'Große Arena',
|
||||
peer_back: 'Gegner ist wieder da', no_pause_online: 'Keine Pause im Live-Kampf',
|
||||
r_draw_prize: 'Unentschieden-Preis',
|
||||
online_guest: 'Als Gast beitreten (ohne E-Mail)', online_short: '🌍 Online',
|
||||
|
||||
@@ -19,15 +19,17 @@
|
||||
const RC = (root.RC = root.RC || {});
|
||||
const PUB = 1 / 15, GRACE = 4000; // ms without news before the AI covers for the peer
|
||||
// robot fields the view / HUD / sound read - kept small for the wire
|
||||
const RF = ['x', 'z', 'a', 'y', 'hp', 'maxHp', 'flipped', 'stun', 'lifted', 'grabbedBy', 'grab', 'turretA', 'spin', 'sawOn', 'flameOn', 'gunOn', 'swing', 'cd', 'boost', 'dead', 'out'];
|
||||
const packRobot = r => { const o = {}; for (const k of RF) o[k] = r[k]; return o; };
|
||||
const RF = ['x', 'z', 'a', 'y', 'hp', 'maxHp', 'flipped', 'stun', 'lifted', 'grabbedBy', 'grab', 'turretA', 'spin', 'sawOn', 'flameOn', 'gunOn', 'swing', 'cd', 'cd2', 'boost', 'gcd', 'gUses', 'shield', 'lost', 'dead', 'out'];
|
||||
const rnd = v => (typeof v === 'number' ? Math.round(v * 1000) / 1000 : v);
|
||||
const packRobot = r => { const o = {}; for (const k of RF) o[k] = rnd(r[k]); return o; };
|
||||
const wrap = a => { while (a > Math.PI) a -= 2 * Math.PI; while (a < -Math.PI) a += 2 * Math.PI; return a; };
|
||||
|
||||
RC.NetFight = (opt) => {
|
||||
const net = opt.net, db = net.db, id = opt.id, host = opt.host;
|
||||
const base = `matches/${id}`;
|
||||
let pubT = 0, seq = 0, sendT = 0, beatT = 0, lastInSeq = -1, evBuf = [];
|
||||
let remoteInput = { throttle: 0, turn: 0, fire: false, fire2: false };
|
||||
let sending = false, slow = 0; // one write at a time; back off while the line is slow
|
||||
let remoteInput = { throttle: 0, turn: 0, fire: false, fire2: false, fire3: false };
|
||||
let started = false, lastPeer = Date.now(), peerAlive = true, ai = null, subIn = null, subState = null, subPing = null, lastState = null, stateApplied = -1;
|
||||
|
||||
function start() {
|
||||
@@ -59,16 +61,25 @@
|
||||
RC.Combat.step(s, dt, [localInput, guestInput]);
|
||||
if (s.events.length) evBuf.push.apply(evBuf, s.events); // batch events between publishes for the guest
|
||||
pubT -= dt;
|
||||
if (pubT <= 0) {
|
||||
pubT = PUB;
|
||||
db.put(`${base}/state`, {
|
||||
seq: ++seq, t: s.t, left: s.left, pitOpen: s.pitOpen, pitAlarm: s.pitAlarm,
|
||||
press: { st: s.press.st, y: s.press.y }, crane: { st: s.crane.st, x: s.crane.x, z: s.crane.z, who: s.crane.who },
|
||||
rockets: s.rockets.map(k => ({ x: k.x, z: k.z, y: k.y, a: k.a })),
|
||||
// publish only when the previous write came back - otherwise slow uploads queue up and the host stutters
|
||||
if (pubT <= 0 && !sending) {
|
||||
pubT = PUB + slow;
|
||||
sending = true;
|
||||
const t0 = Date.now();
|
||||
const payload = {
|
||||
seq: ++seq, t: rnd(s.t), left: rnd(s.left), pitOpen: rnd(s.pitOpen), pitAlarm: s.pitAlarm,
|
||||
press: { st: s.press.st, y: rnd(s.press.y) }, crane: { st: s.crane.st, x: rnd(s.crane.x), z: rnd(s.crane.z), who: s.crane.who },
|
||||
rockets: s.rockets.map(k => ({ x: rnd(k.x), z: rnd(k.z), y: rnd(k.y), a: rnd(k.a) })),
|
||||
r: [packRobot(s.robots[0]), packRobot(s.robots[1])],
|
||||
ev: evBuf.slice(-24), result: s.result, endIn: s.endIn,
|
||||
});
|
||||
ev: evBuf.slice(-24), result: s.result, endIn: rnd(s.endIn),
|
||||
};
|
||||
evBuf.length = 0;
|
||||
const done = () => {
|
||||
sending = false;
|
||||
const ms = Date.now() - t0; // slow line: send less often instead of piling up
|
||||
slow = ms > 400 ? 0.2 : ms > 180 ? 0.08 : 0;
|
||||
};
|
||||
try { Promise.resolve(db.put(`${base}/state`, payload)).then(done, done); } catch (e) { done(); }
|
||||
}
|
||||
return s.events;
|
||||
}
|
||||
@@ -80,9 +91,14 @@
|
||||
sendT -= dt;
|
||||
beatT -= dt;
|
||||
// send on change, and at least every 0.5 s as a heartbeat (otherwise the host thinks I am gone)
|
||||
if (sendT <= 0 && (changed(localInput) || beatT <= 0)) {
|
||||
if (sendT <= 0 && !sending && (changed(localInput) || beatT <= 0)) {
|
||||
sendT = PUB; beatT = 0.5; lastInSeq++;
|
||||
db.put(`${base}/in`, { seq: lastInSeq, throttle: localInput.throttle || 0, turn: localInput.turn || 0, fire: !!localInput.fire, fire2: !!localInput.fire2 });
|
||||
sending = true;
|
||||
const fin = () => { sending = false; };
|
||||
try {
|
||||
Promise.resolve(db.put(`${base}/in`, { seq: lastInSeq, throttle: rnd(localInput.throttle || 0), turn: rnd(localInput.turn || 0),
|
||||
fire: !!localInput.fire, fire2: !!localInput.fire2, fire3: !!localInput.fire3 })).then(fin, fin);
|
||||
} catch (e) { fin(); }
|
||||
prevInput = localInput;
|
||||
}
|
||||
const ev = [];
|
||||
@@ -110,7 +126,7 @@
|
||||
r.x += (d.x - r.x) * k; r.z += (d.z - r.z) * k; r.y += (d.y - r.y) * k;
|
||||
r.a += wrap(d.a - r.a) * k;
|
||||
r.turretA += wrap(d.turretA - r.turretA) * k;
|
||||
for (const f of ['hp', 'maxHp', 'flipped', 'stun', 'lifted', 'grabbedBy', 'grab', 'spin', 'sawOn', 'flameOn', 'gunOn', 'swing', 'cd', 'boost', 'dead', 'out']) r[f] = d[f];
|
||||
for (const f of ['hp', 'maxHp', 'flipped', 'stun', 'lifted', 'grabbedBy', 'grab', 'spin', 'sawOn', 'flameOn', 'gunOn', 'swing', 'cd', 'cd2', 'boost', 'gcd', 'gUses', 'shield', 'lost', 'dead', 'out']) if (d[f] !== undefined) r[f] = d[f];
|
||||
}
|
||||
function syncRockets(s, list) {
|
||||
list = list || [];
|
||||
@@ -119,7 +135,7 @@
|
||||
}
|
||||
|
||||
let prevInput = null;
|
||||
function changed(inp) { return !prevInput || inp.throttle !== prevInput.throttle || inp.turn !== prevInput.turn || inp.fire !== prevInput.fire || inp.fire2 !== prevInput.fire2; }
|
||||
function changed(inp) { return !prevInput || inp.throttle !== prevInput.throttle || inp.turn !== prevInput.turn || inp.fire !== prevInput.fire || inp.fire2 !== prevInput.fire2 || inp.fire3 !== prevInput.fire3; }
|
||||
|
||||
return {
|
||||
start, hostStep, guestFrame,
|
||||
@@ -129,7 +145,7 @@
|
||||
if (sendT > 0) return;
|
||||
sendT = 0.5;
|
||||
if (host) db.patch(`${base}/ping`, { h: Date.now() });
|
||||
else { lastInSeq++; db.put(`${base}/in`, { seq: lastInSeq, throttle: 0, turn: 0, fire: false, fire2: false }); }
|
||||
else { lastInSeq++; db.put(`${base}/in`, { seq: lastInSeq, throttle: 0, turn: 0, fire: false, fire2: false, fire3: false }); }
|
||||
},
|
||||
get peerAlive() { return peerAlive; },
|
||||
stop() { if (subIn) subIn.close(); if (subState) subState.close(); if (subPing) subPing.close(); },
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
const RC = (root.RC = root.RC || {});
|
||||
|
||||
RC.WEIGHT_LIMIT = 100; // kg, single weight class in v1
|
||||
RC.SLOTS = ['chassis', 'motor', 'wheels', 'battery', 'armour', 'weapon', 'tower'];
|
||||
RC.SLOTS = ['chassis', 'motor', 'wheels', 'battery', 'armour', 'weapon', 'tower', 'gadget'];
|
||||
RC.REQUIRED = { chassis: true, motor: true, wheels: true, battery: true };
|
||||
|
||||
const P = [
|
||||
@@ -18,6 +18,12 @@
|
||||
{ id: 'doorstop', slot: 'chassis', name: 'Doorstop', cost: 380, weight: 25, hp: 105, len: 1.45, wid: 1.05, h: 0.34, shape: 'wedge', lowProfile: true },
|
||||
{ id: 'bulwark', slot: 'chassis', name: 'Bulwark', cost: 720, weight: 34, hp: 150, len: 1.5, wid: 1.2, h: 0.5, shape: 'box' },
|
||||
{ id: 'scarab', slot: 'chassis', name: 'Scarab', cost: 1150, weight: 30, hp: 135, len: 1.4, wid: 1.15, h: 0.46, shape: 'dome', frontArmour: 0.15 },
|
||||
{ id: 'cage', slot: 'chassis', name: 'Scrap Cage', cost: 260, weight: 17, hp: 85, len: 1.35, wid: 1.1, h: 0.46, shape: 'frame' },
|
||||
{ id: 'hexpod', slot: 'chassis', name: 'Hexpod', cost: 520, weight: 24, hp: 115, len: 1.35, wid: 1.15, h: 0.44, shape: 'hex' },
|
||||
{ id: 'boiler', slot: 'chassis', name: 'Boiler', cost: 640, weight: 29, hp: 130, len: 1.3, wid: 1.1, h: 0.52, shape: 'barrel' },
|
||||
{ id: 'fang', slot: 'chassis', name: 'Fang', cost: 860, weight: 26, hp: 120, len: 1.55, wid: 1.0, h: 0.36, shape: 'arrow', lowProfile: true, frontArmour: 0.12 },
|
||||
{ id: 'plough', slot: 'chassis', name: 'Snowplough', cost: 980, weight: 36, hp: 150, len: 1.45, wid: 1.2, h: 0.42, shape: 'plow', frontArmour: 0.22 },
|
||||
{ id: 'discus', slot: 'chassis', name: 'Discus', cost: 1350, weight: 32, hp: 155, len: 1.5, wid: 1.35, h: 0.3, shape: 'saucer', lowProfile: true },
|
||||
|
||||
// motor: force (N), top speed (m/s)
|
||||
{ id: 'sparky', slot: 'motor', name: 'Sparky 2kW', cost: 100, weight: 8, power: 3, force: 650, speed: 4.0 },
|
||||
@@ -27,8 +33,12 @@
|
||||
|
||||
// wheels: speed factor, lateral grip, turn rate (rad/s), push factor; invertible = drives upside down
|
||||
{ id: 'rubber', slot: 'wheels', name: 'Rubber 4x', cost: 60, weight: 4, speedMul: 1.0, grip: 7, turn: 2.8, push: 1.0, kind: 'small' },
|
||||
{ id: 'omni', slot: 'wheels', name: 'Omni Casters', cost: 360, weight: 6, speedMul: 1.05, grip: 9, turn: 3.4, push: 0.95, kind: 'omni' },
|
||||
{ id: 'bigtyre', slot: 'wheels', name: 'Big Tyres', cost: 280, weight: 7, speedMul: 1.1, grip: 7.5, turn: 2.5, push: 1.05, kind: 'big', invertible: true },
|
||||
{ id: 'studs', slot: 'wheels', name: 'Studded Tyres', cost: 460, weight: 9, speedMul: 1.0, grip: 10, turn: 2.6, push: 1.2, kind: 'stud', invertible: true },
|
||||
{ id: 'drumwh', slot: 'wheels', name: 'Roller Drum', cost: 600, weight: 10, speedMul: 1.15, grip: 8, turn: 2.0, push: 1.3, kind: 'drum' },
|
||||
{ id: 'tracks', slot: 'wheels', name: 'Crawler Tracks', cost: 540, weight: 11, speedMul: 0.86, grip: 12, turn: 2.2, push: 1.45, kind: 'tracks' },
|
||||
{ id: 'hover', slot: 'wheels', name: 'Hover Skirt', cost: 900, weight: 8, power: 4, speedMul: 1.25, grip: 5, turn: 3.0, push: 0.8, kind: 'hover', invertible: true },
|
||||
|
||||
// battery: power = supply
|
||||
{ id: 'lead', slot: 'battery', name: 'Lead 12V', cost: 80, weight: 10, power: 9 },
|
||||
@@ -36,9 +46,13 @@
|
||||
{ id: 'lipo', slot: 'battery', name: 'LiPo Stack', cost: 760, weight: 5, power: 19 },
|
||||
|
||||
// armour: reduce = share of damage absorbed, hp bonus
|
||||
{ id: 'steel', slot: 'armour', name: 'Steel Plates', cost: 220, weight: 12, reduce: 0.15, hp: 10, tint: 0x8a9099 },
|
||||
{ id: 'titan', slot: 'armour', name: 'Titanium Skin', cost: 680, weight: 9, reduce: 0.25, hp: 15, tint: 0xa9b8c9 },
|
||||
{ id: 'hardox', slot: 'armour', name: 'Hardox Shell', cost: 1150, weight: 18, reduce: 0.38, hp: 25, tint: 0xc9a845 },
|
||||
{ id: 'mesh', slot: 'armour', name: 'Wire Mesh', cost: 120, weight: 5, reduce: 0.08, hp: 4, tint: 0x9aa3ad, style: 'mesh' },
|
||||
{ id: 'steel', slot: 'armour', name: 'Steel Plates', cost: 220, weight: 12, reduce: 0.15, hp: 10, tint: 0x8a9099, style: 'plates' },
|
||||
{ id: 'buffer', slot: 'armour', name: 'Rubber Buffers', cost: 300, weight: 8, reduce: 0.18, hp: 8, tint: 0x33343a, style: 'bumper' },
|
||||
{ id: 'spiked', slot: 'armour', name: 'Spiked Plates', cost: 520, weight: 14, reduce: 0.22, hp: 12, tint: 0x7d868f, style: 'spike' },
|
||||
{ id: 'titan', slot: 'armour', name: 'Titanium Skin', cost: 680, weight: 9, reduce: 0.25, hp: 15, tint: 0xa9b8c9, style: 'plates' },
|
||||
{ id: 'ceramic', slot: 'armour', name: 'Ceramic Tiles', cost: 900, weight: 11, reduce: 0.32, hp: 14, tint: 0xd8d2c4, style: 'tiles' },
|
||||
{ id: 'hardox', slot: 'armour', name: 'Hardox Shell', cost: 1150, weight: 18, reduce: 0.38, hp: 25, tint: 0xc9a845, style: 'plates' },
|
||||
|
||||
// weapons (Space): type decides the behaviour in combat.js
|
||||
{ id: 'wedge', slot: 'weapon', name: 'Steel Wedge', cost: 80, weight: 6, power: 0, type: 'wedge', reach: 0.35, ram: 1.7, cd: 4 },
|
||||
@@ -47,11 +61,28 @@
|
||||
{ id: 'saw', slot: 'weapon', name: 'Circular Saw', cost: 420, weight: 9, power: 5, type: 'saw', reach: 0.4, dps: 24 },
|
||||
{ id: 'crusher', slot: 'weapon', name: 'Hydraulic Jaws', cost: 780, weight: 15, power: 7, type: 'crusher', reach: 0.5, dps: 20, hold: 2.2, cd: 3.5 },
|
||||
{ id: 'spinner', slot: 'weapon', name: 'Bar Spinner', cost: 950, weight: 18, power: 9, type: 'spinner', reach: 0.6, dmg: 34, spinup: 1.4 },
|
||||
{ id: 'lance', slot: 'weapon', name: 'Ram Lance', cost: 300, weight: 8, power: 0, type: 'wedge', reach: 0.5, ram: 2.3, cd: 4 },
|
||||
{ id: 'drill', slot: 'weapon', name: 'Auger Drill', cost: 560, weight: 11, power: 6, type: 'saw', reach: 0.45, dps: 28 },
|
||||
{ id: 'mace', slot: 'weapon', name: 'Spiked Mace', cost: 640, weight: 13, power: 5, type: 'hammer', reach: 0.9, dmg: 26, cd: 1.7 },
|
||||
{ id: 'launcher', slot: 'weapon', name: 'Scoop Launcher', cost: 700, weight: 15, power: 7, type: 'flipper', reach: 0.6, dmg: 6, launch: 9.5, cd: 2.6 },
|
||||
{ id: 'drum', slot: 'weapon', name: 'Drum Spinner', cost: 820, weight: 16, power: 8, type: 'spinner', reach: 0.5, dmg: 26, spinup: 1.0 },
|
||||
{ id: 'lifter', slot: 'weapon', name: 'Scoop Lifter', cost: 340, weight: 10, power: 4, type: 'lifter', reach: 0.5, dmg: 4, launch: 3.2, cd: 1.2 },
|
||||
{ id: 'vdisc', slot: 'weapon', name: 'Vertical Disc', cost: 1100, weight: 17, power: 9, type: 'vspinner', reach: 0.5, dmg: 30, spinup: 1.5 },
|
||||
|
||||
// towers (Shift / E): auto-aiming turret on top
|
||||
{ id: 'flamer', slot: 'tower', name: 'Flame Nozzle', cost: 360, weight: 6, power: 3, type: 'flamer', range: 2.8, dps: 10, cone: 0.4 },
|
||||
{ id: 'minigun', slot: 'tower', name: 'Rivet Minigun', cost: 520, weight: 7, power: 4, type: 'minigun', range: 9, dps: 8 },
|
||||
{ id: 'rockets', slot: 'tower', name: 'Seeker Pod', cost: 840, weight: 10, power: 5, type: 'rockets', range: 14, dmg: 17, cd: 2.4 },
|
||||
{ id: 'zapper', slot: 'tower', name: 'Arc Zapper', cost: 600, weight: 8, power: 6, type: 'zapper', range: 3.4, dps: 15 },
|
||||
{ id: 'mortar', slot: 'tower', name: 'Mortar Tube', cost: 760, weight: 11, power: 5, type: 'mortar', range: 11, dmg: 26, cd: 3.0, splash: 1.7 },
|
||||
{ id: 'swarm', slot: 'tower', name: 'Swarm Pod', cost: 1150, weight: 12, power: 6, type: 'swarm', range: 22, dmg: 9, cd: 3.6, shots: 3 },
|
||||
|
||||
// gadgets (G): one-shot abilities on a cooldown; optional slot
|
||||
{ id: 'righter', slot: 'gadget', name: 'Self-Righter', cost: 180, weight: 5, power: 2, type: 'righter', cd: 4 },
|
||||
{ id: 'turbo', slot: 'gadget', name: 'Nitro Boost', cost: 300, weight: 6, power: 3, type: 'turbo', cd: 7, dur: 1.2 },
|
||||
{ id: 'shield', slot: 'gadget', name: 'Deflector Field', cost: 420, weight: 7, power: 4, type: 'shield', cd: 9, dur: 2.5, reduce: 0.6 },
|
||||
{ id: 'repair', slot: 'gadget', name: 'Repair Kit', cost: 500, weight: 8, power: 3, type: 'repair', cd: 8, charges: 2, heal: 0.26 },
|
||||
{ id: 'emp', slot: 'gadget', name: 'EMP Burst', cost: 640, weight: 7, power: 5, type: 'emp', cd: 8, range: 3.2, stun: 1.5 },
|
||||
];
|
||||
|
||||
RC.PARTS = {};
|
||||
|
||||
444
game/render3d.js
@@ -173,12 +173,18 @@
|
||||
M.lamp = new T.MeshStandardMaterial({ color: 0xffffff, emissive: 0xfff2c0, emissiveIntensity: 1.5 }); // floodlights (intro switches them on)
|
||||
M.stripe = new T.MeshStandardMaterial({ map: stripeTex(), metalness: 0.3, roughness: 0.6 });
|
||||
M.flame = new T.MeshBasicMaterial({ color: 0xff3a08, transparent: true, opacity: 0.42, blending: T.AdditiveBlending, depthWrite: false, side: T.DoubleSide });
|
||||
M.flameCore = new T.MeshBasicMaterial({ color: 0xffd060, transparent: true, opacity: 0.55, blending: T.AdditiveBlending, depthWrite: false, side: T.DoubleSide });
|
||||
M.arc = new T.MeshBasicMaterial({ color: 0x6ec8ff, transparent: true, opacity: 0.5, blending: T.AdditiveBlending, depthWrite: false, side: T.DoubleSide });
|
||||
M.trackTex = canvasTex(64, 16, (c, w, h) => { c.fillStyle = '#17181b'; c.fillRect(0, 0, w, h); c.fillStyle = '#2c2e33'; for (let x = 0; x < w; x += 8) c.fillRect(x, 0, 4, h); }, [6, 1]);
|
||||
M.track = new T.MeshStandardMaterial({ map: M.trackTex, roughness: 0.85, metalness: 0.2 });
|
||||
M.wsteel = new T.MeshStandardMaterial({ color: 0xd2d7de, metalness: 0.95, roughness: 0.22 }); // bright weapon steel
|
||||
M.wedge = new T.MeshStandardMaterial({ color: 0x9aa0a8, metalness: 0.85, roughness: 0.35 });
|
||||
return M;
|
||||
}
|
||||
// shop: the robot is framed in the left column, not in the middle of the stage
|
||||
const GARAGE_OFF_X = 455, GARAGE_OFF_Y = 16;
|
||||
// shop zoom: 0.6 = furthest out (the default, whole robot in frame), 1.9 = closest
|
||||
const GZ_MIN = 0.6, GZ_MAX = 1.9, GZ_DEF = GZ_MIN;
|
||||
const box = (w, h, d, m) => { const o = new T.Mesh(new T.BoxGeometry(w, h, d), m); o.castShadow = true; o.receiveShadow = true; return o; };
|
||||
const cyl = (r1, r2, h, m, seg = 20) => { const o = new T.Mesh(new T.CylinderGeometry(r1, r2, h, seg), m); o.castShadow = true; return o; };
|
||||
|
||||
@@ -220,6 +226,17 @@
|
||||
return geo;
|
||||
}
|
||||
|
||||
// body from a top-view outline, extruded upwards (shape plane XY -> XZ, extrusion -> +Y)
|
||||
function prism(pts, h) {
|
||||
const sh = new T.Shape();
|
||||
sh.moveTo(pts[0][0], pts[0][1]);
|
||||
for (let i = 1; i < pts.length; i++) sh.lineTo(pts[i][0], pts[i][1]);
|
||||
sh.closePath();
|
||||
const g = new T.ExtrudeGeometry(sh, { depth: h, bevelEnabled: true, bevelSize: 0.015, bevelThickness: 0.015, bevelSegments: 1 });
|
||||
g.rotateX(-Math.PI / 2);
|
||||
return g;
|
||||
}
|
||||
|
||||
function buildRobot(build, paint) {
|
||||
const m = mats(), st = RC.stats(build), P = RC.PARTS;
|
||||
const ch = P[build.chassis], wh = P[build.wheels], ar = build.armour ? P[build.armour] : null;
|
||||
@@ -233,7 +250,7 @@
|
||||
const out = { root, tilt, body, skin, st, build, roll: 0, flash: 0, spinA: 0, sawA: 0, gunA: 0, smokeT: 0 };
|
||||
const sk = (geo, w, h, d, y0) => { const o = new T.Mesh(skinUV(geo, w, d, h, y0), body); o.castShadow = o.receiveShadow = true; return o; };
|
||||
const look = paint.look || {}; // opponent look (looks.js), cosmetic only
|
||||
const big = wh && wh.kind === 'big';
|
||||
const big = wh && (wh.kind === 'big' || wh.kind === 'stud');
|
||||
const ws = look.wheelScale || 1;
|
||||
const c = big ? 0.12 : 0.1 * ws; // ground clearance
|
||||
out.c = c;
|
||||
@@ -258,6 +275,44 @@
|
||||
const ring = new T.Mesh(new T.TorusGeometry(1, 0.035, 8, 32), accent);
|
||||
ring.rotation.x = Math.PI / 2; ring.scale.set(L * 0.5, Wd * 0.5, 1); ring.position.y = c + H * 0.5; tilt.add(ring);
|
||||
top = c + H * 1.2;
|
||||
} else if (ch.shape === 'hex' || ch.shape === 'arrow') {
|
||||
const hx = L / 2, hz = Wd / 2;
|
||||
const pts = ch.shape === 'hex'
|
||||
? [[-hx * 0.55, -hz], [hx * 0.55, -hz], [hx, 0], [hx * 0.55, hz], [-hx * 0.55, hz], [-hx, 0]]
|
||||
: [[hx, 0], [hx * 0.2, -hz], [-hx, -hz * 0.78], [-hx, hz * 0.78], [hx * 0.2, hz]];
|
||||
const o = sk(prism(pts, H), L, H, Wd, 0); o.position.y = c; tilt.add(o);
|
||||
if (!drawn) { const st1 = box(L * 0.28, 0.02, Wd * 0.5, m.stripe); st1.position.set(-L * 0.22, top + 0.012, 0); tilt.add(st1); }
|
||||
} else if (ch.shape === 'barrel') {
|
||||
const rr = Math.min(Wd, H * 1.9) / 2;
|
||||
const g = new T.CylinderGeometry(rr, rr, L, 18); g.rotateZ(Math.PI / 2);
|
||||
const o = sk(g, L, H, Wd, 0); o.position.y = c + rr; tilt.add(o);
|
||||
for (const sx of [-1, 1]) { const cap = cyl(rr * 0.5, rr * 0.5, 0.07, m.hub, 14); cap.rotation.z = Math.PI / 2; cap.position.set(sx * L / 2, c + rr, 0); tilt.add(cap); }
|
||||
for (const bx of [-0.22, 0.22]) { const band = cyl(rr * 1.03, rr * 1.03, 0.05, m.dark, 18); band.rotation.z = Math.PI / 2; band.position.set(bx * L, c + rr, 0); tilt.add(band); }
|
||||
top = c + rr * 2;
|
||||
} else if (ch.shape === 'saucer') {
|
||||
const o = sk(new T.CylinderGeometry(1, 1, 1, 22), L, H, Wd, 0);
|
||||
o.scale.set(L / 2, H, Wd / 2); o.position.y = c + H / 2; tilt.add(o);
|
||||
const ring = new T.Mesh(new T.TorusGeometry(1, 0.035, 8, 30), accent);
|
||||
ring.rotation.x = Math.PI / 2; ring.scale.set(L / 2 * 1.02, Wd / 2 * 1.02, 1); ring.position.y = c + H * 0.72; tilt.add(ring);
|
||||
top = c + H;
|
||||
} else if (ch.shape === 'plow') {
|
||||
const bl = L * 0.84, bw = Wd * 0.9;
|
||||
const o = sk(new T.BoxGeometry(bl, H, bw), bl, H, bw, -H / 2); o.position.set(-L * 0.08, c + H / 2, 0); tilt.add(o);
|
||||
const plate = box(0.09, H * 1.35, Wd * 1.1, m.steel); plate.position.set(L / 2 - 0.04, c + H * 0.62, 0); plate.rotation.z = -0.32; tilt.add(plate);
|
||||
const edge = box(0.12, 0.1, Wd * 1.12, m.stripe); edge.position.set(L / 2 + 0.16, c * 0.4, 0); tilt.add(edge);
|
||||
top = c + H;
|
||||
} else if (ch.shape === 'frame') {
|
||||
const bm = 0.07;
|
||||
for (const sx of [-1, 1]) for (const sz of [-1, 1]) {
|
||||
const post = box(bm, H, bm, m.dark); post.position.set(sx * (L / 2 - bm / 2), c + H / 2, sz * (Wd / 2 - bm / 2)); tilt.add(post);
|
||||
}
|
||||
for (const y of [c + bm / 2, c + H - bm / 2]) {
|
||||
for (const sz of [-1, 1]) { const rail = box(L, bm, bm, m.dark); rail.position.set(0, y, sz * (Wd / 2 - bm / 2)); tilt.add(rail); }
|
||||
for (const sx of [-1, 1]) { const rail = box(bm, bm, Wd, m.dark); rail.position.set(sx * (L / 2 - bm / 2), y, 0); tilt.add(rail); }
|
||||
}
|
||||
const pan = sk(new T.BoxGeometry(L * 0.9, 0.09, Wd * 0.86), L * 0.9, 0.09, Wd * 0.86, -0.045);
|
||||
pan.position.y = c + 0.07; tilt.add(pan);
|
||||
top = c + H;
|
||||
} else {
|
||||
const o = sk(new T.BoxGeometry(L, H, Wd), L, H, Wd, -H / 2); o.position.y = c + H / 2; tilt.add(o);
|
||||
if (!drawn) {
|
||||
@@ -281,22 +336,65 @@
|
||||
out.top = top;
|
||||
mark('chassis');
|
||||
|
||||
// armour plates (sides + rear), bolts
|
||||
// armour: every kind looks clearly different, so swapping it shows in the workshop preview
|
||||
if (armour) {
|
||||
const asty = (ar && ar.style) || 'plates';
|
||||
const sideX = Wd / 2 + 0.028;
|
||||
if (asty === 'mesh') { // open wire grille
|
||||
for (const sz of [-1, 1]) {
|
||||
for (const y of [c + H * 0.1, c + H * 0.74]) { const rail = box(L * 0.9, 0.05, 0.04, armour); rail.position.set(0, y, sz * sideX); tilt.add(rail); }
|
||||
for (let k = 0; k < 6; k++) { const bar = box(0.045, H * 0.64, 0.04, armour); bar.position.set((k / 5 - 0.5) * L * 0.86, c + H * 0.42, sz * sideX); tilt.add(bar); }
|
||||
}
|
||||
} else if (asty === 'bumper') { // fat rubber buffers around the body
|
||||
for (const sx of [-1, 1]) for (const sz of [-1, 1]) {
|
||||
const b = new T.Mesh(new T.SphereGeometry(0.14, 12, 9), armour);
|
||||
b.scale.set(1, 0.78, 1); b.castShadow = true;
|
||||
b.position.set(sx * L * 0.4, c + H * 0.42, sz * (Wd / 2 + 0.055)); tilt.add(b);
|
||||
}
|
||||
for (const sx of [-1, 1]) { const b = box(0.11, H * 0.52, Wd * 0.78, armour); b.position.set(sx * (L / 2 + 0.055), c + H * 0.42, 0); tilt.add(b); }
|
||||
} else if (asty === 'tiles') { // ceramic tiles with gaps
|
||||
for (const sz of [-1, 1]) for (let kx = 0; kx < 4; kx++) for (let ky = 0; ky < 2; ky++) {
|
||||
const tl = box(L * 0.19, H * 0.32, 0.05, armour);
|
||||
tl.position.set((kx / 3 - 0.5) * L * 0.74, c + H * (0.26 + ky * 0.36), sz * sideX); tilt.add(tl);
|
||||
}
|
||||
const rr = box(0.05, H * 0.72, Wd * 0.9, armour); rr.position.set(-L / 2 - 0.028, c + H * 0.42, 0); tilt.add(rr);
|
||||
} else { // solid plates (steel / titanium / hardox / spiked)
|
||||
for (const sz of [-1, 1]) {
|
||||
const p = drawn ? sk(new T.BoxGeometry(L * 0.9, H * 0.78, 0.05), L * 0.9, H * 0.78, 0.05, -H * 0.39) : box(L * 0.9, H * 0.78, 0.05, armour);
|
||||
p.position.set(0, c + H * 0.42, sz * (Wd / 2 + 0.028)); tilt.add(p);
|
||||
for (const bx of [-0.36, 0, 0.36]) { const b = cyl(0.025, 0.025, 0.03, m.dark, 8); b.rotation.x = Math.PI / 2; b.position.set(bx * L, c + H * 0.55, sz * (Wd / 2 + 0.06)); tilt.add(b); }
|
||||
if (asty === 'spike') for (let k = 0; k < 4; k++) {
|
||||
const sp = cyl(0.001, 0.055, 0.18, m.stripe, 8);
|
||||
sp.rotation.x = sz * Math.PI / 2;
|
||||
sp.position.set((k / 3 - 0.5) * L * 0.62, c + H * 0.5, sz * (Wd / 2 + 0.12)); tilt.add(sp);
|
||||
}
|
||||
}
|
||||
const r = box(0.05, H * 0.78, Wd * 0.95, armour); r.position.set(-L / 2 - 0.028, c + H * 0.42, 0); tilt.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
mark('armour');
|
||||
|
||||
// wheels
|
||||
out.wheels = [];
|
||||
const side = Wd / 2 + (armour ? 0.13 : 0.08);
|
||||
if (wh.kind === 'tracks' || look.tracksLook) {
|
||||
if (wh.kind === 'hover') {
|
||||
// air skirt: glowing ring, no wheels
|
||||
const skirt = new T.Mesh(new T.CylinderGeometry(Wd * 0.6, Wd * 0.72, 0.14, 22),
|
||||
new T.MeshStandardMaterial({ color: 0x223040, metalness: 0.5, roughness: 0.5, emissive: paint.accent, emissiveIntensity: 0.3 }));
|
||||
skirt.scale.x = L / Wd * 0.92; skirt.position.set(-L * 0.04, 0.09, 0); skirt.castShadow = true; tilt.add(skirt);
|
||||
const glow = new T.Mesh(new T.CylinderGeometry(Wd * 0.5, Wd * 0.5, 0.04, 22),
|
||||
new T.MeshBasicMaterial({ color: paint.accent, transparent: true, opacity: 0.5, blending: T.AdditiveBlending, depthWrite: false }));
|
||||
glow.scale.x = L / Wd * 0.92; glow.position.set(-L * 0.04, 0.02, 0); tilt.add(glow);
|
||||
out.wheelR = 0.16;
|
||||
} else if (wh.kind === 'drum') {
|
||||
// one wide roller drum + two small rear casters
|
||||
const R = (c + H) / 2 + 0.08;
|
||||
const dr = cyl(R, R, Wd * 0.92, m.rubber, 20); dr.rotation.x = Math.PI / 2; dr.position.set(-L * 0.04, R, 0); tilt.add(dr); out.wheels.push(dr);
|
||||
const hub = cyl(R * 0.4, R * 0.4, Wd * 0.94, m.hub, 12); hub.rotation.x = Math.PI / 2; hub.position.set(-L * 0.04, R, 0); tilt.add(hub);
|
||||
for (const sz of [-1, 1]) { const w = new T.Group(); w.position.set(-L * 0.42, 0.13, sz * side); const t = cyl(0.13, 0.13, 0.14, m.hub, 10); t.rotation.x = Math.PI / 2; w.add(t); tilt.add(w); out.wheels.push(w); }
|
||||
out.wheelR = R;
|
||||
} else if (wh.kind === 'tracks' || look.tracksLook) {
|
||||
for (const sz of [-1, 1]) {
|
||||
const t = box(L * 1.02, 0.3, 0.2, m.track); t.position.set(0, 0.15, sz * side); tilt.add(t);
|
||||
for (const bx of [-0.42, 0.42]) { const w = cyl(0.15, 0.15, 0.21, m.hub, 14); w.rotation.x = Math.PI / 2; w.position.set(bx * L, 0.15, sz * side); tilt.add(w); }
|
||||
@@ -342,26 +440,45 @@
|
||||
if (w) {
|
||||
const WS = m.wsteel, ED = m.wedge, HZ = m.stripe; // weapon steel, edge, hazard stripe
|
||||
if (w.type === 'wedge') {
|
||||
if (w.id === 'lance') {
|
||||
// long spike lance
|
||||
const shaft = cyl(0.05, 0.05, 0.85, m.dark, 8); shaft.rotation.z = Math.PI / 2; shaft.position.set(L / 2 + 0.42, c + H * 0.4, 0); tilt.add(shaft);
|
||||
const tip = cyl(0.001, 0.13, 0.42, HZ, 12); tip.rotation.z = -Math.PI / 2; tip.position.set(L / 2 + 0.95, c + H * 0.4, 0); tilt.add(tip);
|
||||
} else {
|
||||
// short ramp plate at the front (as before - stays close to the body so it does not poke through)
|
||||
const p = box(0.5, 0.05, Wd * 1.05, ED); p.position.set(L / 2 + 0.18, c * 0.5 + 0.08, 0); p.rotation.z = -0.42; tilt.add(p);
|
||||
const edge = box(0.12, 0.16, Wd * 1.06, HZ); edge.position.set(L / 2 + 0.34, 0.02, 0); tilt.add(edge);
|
||||
}
|
||||
} else if (w.type === 'flipper') {
|
||||
const lf = w.id === 'launcher' ? 1.3 : 1, wf = w.id === 'launcher' ? 1.12 : 1;
|
||||
const piv = new T.Group(); piv.position.set(L / 2 - 0.1, c + H * 0.22, 0); tilt.add(piv);
|
||||
const p = box(0.78, 0.09, Wd * 0.95, WS); p.position.x = 0.39; piv.add(p);
|
||||
const s = box(0.78, 0.03, Wd * 0.4, accent); s.position.set(0.39, 0.06, 0); piv.add(s);
|
||||
const edge = box(0.12, 0.14, Wd * 0.98, HZ); edge.position.set(0.78, 0, 0); piv.add(edge);
|
||||
const p = box(0.78 * lf, 0.09, Wd * 0.95 * wf, WS); p.position.x = 0.39 * lf; piv.add(p);
|
||||
const s = box(0.78 * lf, 0.03, Wd * 0.4, accent); s.position.set(0.39 * lf, 0.06, 0); piv.add(s);
|
||||
const edge = box(0.12, 0.14, Wd * 0.98 * wf, HZ); edge.position.set(0.78 * lf, 0, 0); piv.add(edge);
|
||||
const pist = cyl(0.05, 0.05, 0.4, m.hub, 8); pist.rotation.z = 1.0; pist.position.set(0.2, -0.16, 0); tilt.add(pist); // ram
|
||||
out.flipper = piv;
|
||||
} else if (w.type === 'hammer') {
|
||||
const post = box(0.16, 0.26, 0.24, m.dark); post.position.set(-L * 0.1, top + 0.11, 0); tilt.add(post);
|
||||
const piv = new T.Group(); piv.position.set(-L * 0.1, top + 0.16, 0); tilt.add(piv);
|
||||
const arm = box(L * 0.82, 0.1, 0.1, m.dark); arm.position.x = L * 0.41; piv.add(arm);
|
||||
if (w.id === 'mace') {
|
||||
const ball = new T.Mesh(new T.SphereGeometry(0.24, 14, 10), WS); ball.castShadow = true; ball.position.set(L * 0.82, -0.05, 0); piv.add(ball);
|
||||
for (let k = 0; k < 6; k++) { const a = k / 6 * Math.PI * 2; const sp = box(0.16, 0.07, 0.07, HZ); sp.position.set(L * 0.82 + Math.cos(a) * 0.26, -0.05, Math.sin(a) * 0.26); sp.rotation.y = -a; piv.add(sp); }
|
||||
} else {
|
||||
const head = box(0.26, 0.42, 0.26, WS); head.position.set(L * 0.82, -0.12, 0); piv.add(head); // big mallet head
|
||||
const face = box(0.1, 0.44, 0.28, HZ); face.position.set(L * 0.82 + 0.17, -0.12, 0); piv.add(face);
|
||||
const spike = box(0.18, 0.12, 0.12, accent); spike.position.set(L * 0.82, 0.12, 0); piv.add(spike);
|
||||
}
|
||||
out.hammer = piv;
|
||||
} else if (w.type === 'saw') {
|
||||
const arm = box(0.4, 0.12, 0.12, m.dark); arm.position.set(L / 2 + 0.06, c + H * 0.5, 0); tilt.add(arm);
|
||||
if (w.id === 'drill') {
|
||||
// conical auger drill, spins on its forward (x) axis
|
||||
const g = new T.Group(); g.position.set(L / 2 + 0.42, c + H * 0.5, 0); tilt.add(g);
|
||||
const cone = cyl(0.001, 0.2, 0.72, WS, 14); cone.rotation.z = -Math.PI / 2; cone.castShadow = true; g.add(cone);
|
||||
for (let k = 0; k < 3; k++) { const fl = box(0.6, 0.03, 0.06, HZ); fl.position.x = -0.1; fl.rotation.x = k / 3 * Math.PI * 2; g.add(fl); }
|
||||
out.saw = g; out.sawAxis = 'x';
|
||||
} else {
|
||||
const guard = new T.Mesh(new T.TorusGeometry(0.42, 0.05, 8, 20, Math.PI), accent); // orange guard over the top
|
||||
guard.position.set(L / 2 + 0.28, c + H * 0.5, 0); tilt.add(guard);
|
||||
const g = new T.Group(); g.position.set(L / 2 + 0.28, c + H * 0.5, 0); tilt.add(g);
|
||||
@@ -369,13 +486,40 @@
|
||||
for (let k = 0; k < 16; k++) { const t = box(0.11, 0.06, 0.05, WS); const a = k / 16 * Math.PI * 2; t.position.set(Math.cos(a) * 0.4, Math.sin(a) * 0.4, 0); t.rotation.z = a + 0.6; g.add(t); }
|
||||
const hub = cyl(0.09, 0.09, 0.07, accent, 12); hub.rotation.x = Math.PI / 2; g.add(hub);
|
||||
out.saw = g;
|
||||
}
|
||||
} else if (w.type === 'spinner') {
|
||||
if (w.id === 'drum') {
|
||||
const post = cyl(0.1, 0.12, 0.3, m.dark, 12); post.position.set(L / 2 + 0.02, c + H * 0.32, 0); tilt.add(post);
|
||||
const g = new T.Group(); g.position.set(L / 2 + 0.12, c + H * 0.34, 0); tilt.add(g);
|
||||
const drum = cyl(0.3, 0.3, 0.52, WS, 20); drum.castShadow = true; g.add(drum);
|
||||
for (const sx of [-1, 1]) { const tb = box(0.14, 0.54, 0.12, HZ); tb.position.set(sx * 0.3, 0, 0); g.add(tb); }
|
||||
out.spinner = g;
|
||||
} else {
|
||||
const post = cyl(0.1, 0.12, 0.3, m.dark, 12); post.position.set(L / 2 + 0.04, c + H * 0.32, 0); tilt.add(post);
|
||||
const g = new T.Group(); g.position.set(L / 2 + 0.04, c + H * 0.3, 0); tilt.add(g);
|
||||
const bar = box(1.5, 0.12, 0.22, WS); g.add(bar);
|
||||
const stripe = box(1.5, 0.13, 0.08, HZ); g.add(stripe);
|
||||
for (const sx of [-1, 1]) { const t = box(0.18, 0.16, 0.32, accent); t.position.x = sx * 0.72; g.add(t); }
|
||||
out.spinner = g;
|
||||
}
|
||||
} else if (w.type === 'lifter') {
|
||||
const piv = new T.Group(); piv.position.set(L / 2 - 0.08, c + H * 0.16, 0); tilt.add(piv);
|
||||
const bar = box(0.12, 0.09, Wd * 0.95, m.dark); bar.position.set(0.06, 0, 0); piv.add(bar);
|
||||
for (const sz of [-1, 1]) {
|
||||
const prong = box(0.85, 0.07, Wd * 0.26, WS); prong.position.set(0.46, 0, sz * Wd * 0.3); piv.add(prong);
|
||||
const tip = box(0.16, 0.1, Wd * 0.28, HZ); tip.position.set(0.9, 0.015, sz * Wd * 0.3); piv.add(tip);
|
||||
}
|
||||
out.flipper = piv;
|
||||
} else if (w.type === 'vspinner') {
|
||||
const arm = box(0.3, 0.14, 0.14, m.dark); arm.position.set(L / 2 + 0.02, c + H * 0.45, 0); tilt.add(arm);
|
||||
const g = new T.Group(); g.position.set(L / 2 + 0.32, c + H * 0.42, 0); tilt.add(g);
|
||||
const d = cyl(0.45, 0.45, 0.11, WS, 26); d.rotation.x = Math.PI / 2; g.add(d);
|
||||
for (let k = 0; k < 4; k++) {
|
||||
const tth = box(0.22, 0.17, 0.14, HZ); const a = k / 4 * Math.PI * 2;
|
||||
tth.position.set(Math.cos(a) * 0.45, Math.sin(a) * 0.45, 0); tth.rotation.z = a; g.add(tth);
|
||||
}
|
||||
const hub = cyl(0.1, 0.1, 0.14, accent, 12); hub.rotation.x = Math.PI / 2; g.add(hub);
|
||||
out.vspin = g;
|
||||
} else if (w.type === 'crusher') {
|
||||
out.jaws = [];
|
||||
for (const sz of [-1, 1]) {
|
||||
@@ -397,9 +541,12 @@
|
||||
if (tw.type === 'flamer') {
|
||||
const tank = cyl(0.08, 0.08, 0.26, new T.MeshStandardMaterial({ color: 0xc0392b, metalness: 0.4, roughness: 0.4 }), 12); tank.position.set(-0.08, 0.25, 0); g.add(tank);
|
||||
const n = cyl(0.045, 0.06, 0.42, m.steel, 10); n.rotation.z = -Math.PI / 2; n.position.set(0.24, 0.18, 0); g.add(n);
|
||||
const f = new T.Mesh(new T.ConeGeometry(0.42, 2.6, 14, 1, true), M.flame);
|
||||
f.rotation.z = Math.PI / 2; f.position.set(0.45 + 1.3, 0.18, 0); f.visible = false; g.add(f);
|
||||
out.flame = f;
|
||||
const f = new T.Group(); f.visible = false; g.add(f);
|
||||
const outer = new T.Mesh(new T.ConeGeometry(0.44, 2.7, 16, 1, true), M.flame);
|
||||
outer.rotation.z = Math.PI / 2; outer.position.set(0.45 + 1.35, 0.18, 0); f.add(outer);
|
||||
const core = new T.Mesh(new T.ConeGeometry(0.2, 1.5, 12, 1, true), M.flameCore);
|
||||
core.rotation.z = Math.PI / 2; core.position.set(0.45 + 0.75, 0.18, 0); f.add(core);
|
||||
out.flame = f; out.flameParts = [outer, core];
|
||||
} else if (tw.type === 'minigun') {
|
||||
const hous = box(0.22, 0.16, 0.2, accent); hous.position.y = 0.2; g.add(hous);
|
||||
const brl = new T.Group(); brl.position.set(0.1, 0.2, 0); g.add(brl);
|
||||
@@ -407,6 +554,25 @@
|
||||
out.gun = brl;
|
||||
const fl = new T.Mesh(new T.SphereGeometry(0.09, 8, 6), new T.MeshBasicMaterial({ color: 0xffd060, transparent: true, blending: T.AdditiveBlending, depthWrite: false }));
|
||||
fl.position.set(0.62, 0.2, 0); fl.visible = false; g.add(fl); out.muzzle = fl;
|
||||
} else if (tw.type === 'zapper') {
|
||||
const coil = cyl(0.1, 0.13, 0.22, m.dark, 12); coil.position.y = 0.2; g.add(coil);
|
||||
for (let k = 0; k < 3; k++) { const ring = new T.Mesh(new T.TorusGeometry(0.1, 0.018, 6, 14), accent); ring.rotation.x = Math.PI / 2; ring.position.y = 0.14 + k * 0.07; g.add(ring); }
|
||||
const rod = cyl(0.022, 0.022, 0.34, m.steel, 8); rod.rotation.z = -Math.PI / 2; rod.position.set(0.2, 0.3, 0); g.add(rod);
|
||||
const ball = new T.Mesh(new T.SphereGeometry(0.06, 10, 8), new T.MeshStandardMaterial({ color: 0x9fd8ff, emissive: 0x3aa0ff, emissiveIntensity: 1.6 }));
|
||||
ball.position.set(0.38, 0.3, 0); g.add(ball);
|
||||
const arc = new T.Mesh(new T.ConeGeometry(0.13, 1.5, 8, 1, true), M.arc);
|
||||
arc.rotation.z = -Math.PI / 2; arc.position.set(1.1, 0.3, 0); arc.visible = false; g.add(arc);
|
||||
out.gun = coil; out.muzzle = ball; out.flame = arc; // reuse the beam slots
|
||||
} else if (tw.type === 'mortar') {
|
||||
const base2 = cyl(0.14, 0.16, 0.1, m.dark, 12); base2.position.y = 0.14; g.add(base2);
|
||||
const tube = cyl(0.11, 0.13, 0.52, m.steel, 14); tube.position.set(-0.05, 0.36, 0); tube.rotation.z = 0.5; g.add(tube);
|
||||
const mouth = cyl(0.13, 0.13, 0.05, accent, 14); mouth.position.set(0.1, 0.58, 0); mouth.rotation.z = 0.5; g.add(mouth);
|
||||
for (const sz of [-1, 1]) { const leg = cyl(0.02, 0.02, 0.3, m.dark, 6); leg.position.set(0.12, 0.17, sz * 0.1); leg.rotation.z = -0.5; g.add(leg); }
|
||||
} else if (tw.type === 'swarm') {
|
||||
const pod = box(0.42, 0.3, 0.42, accent); pod.position.set(0.02, 0.28, 0); g.add(pod);
|
||||
for (const y of [0.19, 0.3, 0.41]) for (const sz of [-0.12, 0, 0.12]) {
|
||||
const tube = cyl(0.04, 0.04, 0.07, m.dark, 8); tube.rotation.z = Math.PI / 2; tube.position.set(0.23, y, sz); g.add(tube);
|
||||
}
|
||||
} else if (tw.type === 'rockets') {
|
||||
const pod = box(0.38, 0.26, 0.36, accent); pod.position.set(0.02, 0.27, 0); g.add(pod);
|
||||
for (const [y, z] of [[0.2, -0.09], [0.2, 0.09], [0.34, -0.09], [0.34, 0.09]]) { const t = cyl(0.05, 0.05, 0.06, m.dark, 10); t.rotation.z = Math.PI / 2; t.position.set(0.22, y, z); g.add(t); }
|
||||
@@ -414,6 +580,16 @@
|
||||
out.turret = g;
|
||||
}
|
||||
mark('tower');
|
||||
|
||||
// gadget: small pod on the rear deck, colour-coded by type
|
||||
const gd = st.gadget;
|
||||
if (gd) {
|
||||
const gc = { righter: 0x40c0ff, turbo: 0xff5020, shield: 0x40e0c0, repair: 0x50e060, emp: 0xc060ff }[gd.type] || 0xffffff;
|
||||
const pod = box(0.24, 0.16, 0.3, m.dark); pod.position.set(-L * 0.33, top + 0.02, 0); tilt.add(pod);
|
||||
const led = new T.Mesh(new T.SphereGeometry(0.05, 8, 6), new T.MeshStandardMaterial({ color: gc, emissive: gc, emissiveIntensity: 0.8, roughness: 0.4 }));
|
||||
led.position.set(-L * 0.33, top + 0.12, 0); tilt.add(led);
|
||||
}
|
||||
mark('gadget');
|
||||
root.traverse(o => { if (o.isMesh && !o.material.transparent) { o.castShadow = true; } });
|
||||
return out;
|
||||
}
|
||||
@@ -441,11 +617,20 @@
|
||||
else if (w && r.cd > 0) ang = lerp(-0.25, 1.9, clamp((w.cd - 0.43 - r.cd) / 0.5, 0, 1));
|
||||
R.hammer.rotation.z = ang;
|
||||
}
|
||||
if (R.saw) { if (r.sawOn) R.sawA += dt * 40; R.saw.rotation.z = -R.sawA; }
|
||||
if (R.saw) { if (r.sawOn) R.sawA += dt * 40; R.saw.rotation[R.sawAxis || 'z'] = -R.sawA; }
|
||||
if (R.spinner) { R.spinA += dt * r.spin * 38; R.spinner.rotation.y = R.spinA; }
|
||||
if (R.vspin) { R.spinA += dt * r.spin * 40; R.vspin.rotation.z = -R.spinA; }
|
||||
if (R.jaws) for (const j of R.jaws) j.rotation.y = j.userData.side * (r.grab > 0 ? -0.18 : 0.45);
|
||||
if (R.turret) R.turret.rotation.y = -(r.turretA - r.a);
|
||||
if (R.flame) { R.flame.visible = r.flameOn; if (r.flameOn) { const f = 0.85 + Math.random() * 0.3; R.flame.scale.set(f, 1, f); } }
|
||||
if (R.flame) {
|
||||
const tw2 = R.st.tower, beam = r.flameOn || (tw2 && tw2.type === 'zapper' && r.gunOn);
|
||||
R.flame.visible = !!beam;
|
||||
if (beam) {
|
||||
const f = 0.85 + Math.random() * 0.3;
|
||||
R.flame.scale.set(f, 1, f);
|
||||
if (R.flameParts) for (const fp of R.flameParts) { const n = 0.78 + Math.random() * 0.5; fp.scale.set(n, 0.9 + Math.random() * 0.35, n); }
|
||||
}
|
||||
}
|
||||
if (R.gun) { if (r.gunOn) R.gunA += dt * 30; R.gun.rotation.x = R.gunA; R.muzzle.visible = r.gunOn && Math.random() < 0.6; }
|
||||
R.flash = Math.max(0, R.flash - dt * 4);
|
||||
R.body.emissive.setRGB(R.flash * 0.9, R.flash * 0.15, 0);
|
||||
@@ -466,7 +651,7 @@
|
||||
scene.add(new T.HemisphereLight(0x8fa6c8, 0x1a140f, 0.55));
|
||||
const key = new T.DirectionalLight(0xfff1dc, 1.25);
|
||||
key.position.set(6, 16, 9); key.castShadow = true;
|
||||
key.shadow.mapSize.set(2048, 2048);
|
||||
key.shadow.mapSize.set(1024, 1024); // 2048 was a big per-frame shadow pass; 1024 is plenty at this scale
|
||||
Object.assign(key.shadow.camera, { left: -11, right: 11, top: 11, bottom: -11, near: 1, far: 50 });
|
||||
key.shadow.bias = -0.0008;
|
||||
scene.add(key);
|
||||
@@ -507,9 +692,29 @@
|
||||
{ const scene = { add: scene_add }; buildArenaBody(scene, out, A, m, half, th); }
|
||||
}
|
||||
|
||||
// arena outline (same maths as wallPush in combat.js): square, octagon or a many-sided ring
|
||||
function outline(A) {
|
||||
const h = A.half;
|
||||
if (A.shape === 'round') return Array.from({ length: 28 }, (_, i) => { const a = i / 28 * Math.PI * 2; return [Math.cos(a) * h, Math.sin(a) * h]; });
|
||||
if (A.shape === 'octagon') { const d = h * 0.67; return [[-d, -h], [d, -h], [h, -d], [h, d], [d, h], [-d, h], [-h, d], [-h, -d]]; }
|
||||
return [[-h, -h], [h, -h], [h, h], [-h, h]];
|
||||
}
|
||||
function floorGeo(A) {
|
||||
const h = A.half;
|
||||
if (A.shape === 'square') return new T.PlaneGeometry(h * 2, h * 2);
|
||||
const pts = outline(A), sh = new T.Shape();
|
||||
sh.moveTo(pts[0][0], pts[0][1]);
|
||||
for (let i = 1; i < pts.length; i++) sh.lineTo(pts[i][0], pts[i][1]);
|
||||
sh.closePath();
|
||||
const g = new T.ShapeGeometry(sh), pos = g.attributes.position, uv = new Float32Array(pos.count * 2);
|
||||
for (let i = 0; i < pos.count; i++) { uv[i * 2] = pos.getX(i) / (h * 2) + 0.5; uv[i * 2 + 1] = pos.getY(i) / (h * 2) + 0.5; }
|
||||
g.setAttribute('uv', new T.BufferAttribute(uv, 2));
|
||||
return g;
|
||||
}
|
||||
|
||||
function buildArenaBody(scene, out, A, m, half, th) {
|
||||
// floor
|
||||
const floor = new T.Mesh(new T.PlaneGeometry(half * 2, half * 2), new T.MeshStandardMaterial({ map: floorTex(A), metalness: 0.55, roughness: 0.62 }));
|
||||
const floor = new T.Mesh(floorGeo(A), new T.MeshStandardMaterial({ map: floorTex(A), metalness: 0.55, roughness: 0.62 }));
|
||||
floor.rotation.x = -Math.PI / 2; floor.receiveShadow = true; scene.add(floor);
|
||||
const outer = new T.Mesh(new T.PlaneGeometry(80, 80), new T.MeshStandardMaterial({ color: 0x0d0f13, roughness: 1 }));
|
||||
outer.rotation.x = -Math.PI / 2; outer.position.y = -0.02; outer.receiveShadow = true; scene.add(outer);
|
||||
@@ -519,22 +724,30 @@
|
||||
// ComfyGen wall panels (tex_wall.jpg) on the arena walls, if the browser lets the image into WebGL
|
||||
const panelMat = new T.MeshStandardMaterial({ color: 0x30343b, metalness: 0.6, roughness: 0.5 });
|
||||
loadTex('tex_wall.jpg', tex => { tex.wrapS = T.RepeatWrapping; tex.repeat.set(5, 1); panelMat.map = tex; panelMat.color.set(0xb0b4bc); panelMat.needsUpdate = true; });
|
||||
const n = Math.round(half * 2 / 0.5);
|
||||
const spikes = new T.InstancedMesh(new T.ConeGeometry(0.07, 0.28, 8), m.steel, n * 4);
|
||||
const pts = outline(A);
|
||||
let perim = 0;
|
||||
for (let i = 0; i < pts.length; i++) { const a2 = pts[i], b2 = pts[(i + 1) % pts.length]; perim += Math.hypot(b2[0] - a2[0], b2[1] - a2[1]); }
|
||||
const spikes = new T.InstancedMesh(new T.ConeGeometry(0.07, 0.28, 8), m.steel, Math.ceil(perim / 0.5) + pts.length + 4);
|
||||
const dm = new T.Object3D(); let si = 0;
|
||||
for (const [nx, nz] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) {
|
||||
const wall = box(nz ? half * 2 + 0.5 : 0.25, 0.55, nz ? 0.25 : half * 2 + 0.5, panelMat);
|
||||
wall.position.set(nx * (half + 0.12), 0.275, nz * (half + 0.12)); scene.add(wall);
|
||||
const strip = box(nz ? half * 2 + 0.5 : 0.26, 0.08, nz ? 0.26 : half * 2 + 0.5, m.stripe);
|
||||
strip.position.set(nx * (half + 0.12), 0.58, nz * (half + 0.12)); scene.add(strip);
|
||||
for (let k = 0; k < n; k++) {
|
||||
const t = -half + 0.25 + k * 0.5;
|
||||
dm.position.set(nx ? nx * (half - 0.02) : t, 0.3, nz ? nz * (half - 0.02) : t);
|
||||
for (let i = 0; i < pts.length; i++) {
|
||||
const [x1, z1] = pts[i], [x2, z2] = pts[(i + 1) % pts.length];
|
||||
const mx = (x1 + x2) / 2, mz = (z1 + z2) / 2, len = Math.hypot(x2 - x1, z2 - z1), ang = Math.atan2(z2 - z1, x2 - x1);
|
||||
const d = Math.hypot(mx, mz) || 1, ox = mx / d, oz = mz / d; // outwards from the middle
|
||||
const wall = box(len + 0.3, 0.55, 0.25, panelMat);
|
||||
wall.position.set(mx + ox * 0.12, 0.275, mz + oz * 0.12); wall.rotation.y = -ang; scene.add(wall);
|
||||
const strip = box(len + 0.3, 0.08, 0.26, m.stripe);
|
||||
strip.position.set(mx + ox * 0.12, 0.58, mz + oz * 0.12); strip.rotation.y = -ang; scene.add(strip);
|
||||
const steps = Math.max(1, Math.round(len / 0.5));
|
||||
for (let k = 0; k < steps; k++) {
|
||||
const f = (k + 0.5) / steps;
|
||||
dm.position.set(x1 + (x2 - x1) * f - ox * 0.02, 0.3, z1 + (z2 - z1) * f - oz * 0.02);
|
||||
dm.rotation.set(0, 0, 0);
|
||||
if (nx) dm.rotation.z = nx > 0 ? Math.PI / 2 : -Math.PI / 2; else dm.rotation.x = nz > 0 ? -Math.PI / 2 : Math.PI / 2;
|
||||
dm.updateMatrix(); spikes.setMatrixAt(si++, dm.matrix);
|
||||
dm.rotation.z = Math.PI / 2; dm.rotation.y = -Math.atan2(oz, ox); // point inwards
|
||||
dm.updateMatrix();
|
||||
if (si < spikes.count) spikes.setMatrixAt(si++, dm.matrix);
|
||||
}
|
||||
}
|
||||
spikes.count = si;
|
||||
spikes.castShadow = true; scene.add(spikes);
|
||||
|
||||
// glass + posts + floodlight rigs
|
||||
@@ -566,6 +779,60 @@
|
||||
seats.count = ci; dm.scale.set(1, 1, 1); scene.add(seats);
|
||||
|
||||
// floor saws
|
||||
// --- cover and floor traps (static, built once per arena) ---
|
||||
const BMAT = {
|
||||
pillar: new T.MeshStandardMaterial({ color: 0x4a515c, metalness: 0.5, roughness: 0.6 }),
|
||||
crate: new T.MeshStandardMaterial({ color: 0x6b5634, metalness: 0.2, roughness: 0.85 }),
|
||||
scrap: new T.MeshStandardMaterial({ color: 0x5a5048, metalness: 0.6, roughness: 0.8 }),
|
||||
barrier: new T.MeshStandardMaterial({ color: 0x9aa0a8, metalness: 0.6, roughness: 0.5 }),
|
||||
};
|
||||
let bseed = 7;
|
||||
const brnd = () => { bseed = (bseed * 16807) % 2147483647; return bseed / 2147483647; };
|
||||
for (const b of A.blocks) {
|
||||
const g = new T.Group(); g.position.set(b.x, 0, b.z); scene.add(g);
|
||||
const mat = BMAT[b.kind] || BMAT.crate;
|
||||
if (b.kind === 'pillar') {
|
||||
const rr = Math.min(b.hw, b.hd);
|
||||
const col = cyl(rr, rr * 1.12, b.h, mat, 14); col.position.y = b.h / 2; col.castShadow = true; g.add(col);
|
||||
const cap = cyl(rr * 1.18, rr * 1.18, 0.12, m.dark, 14); cap.position.y = b.h; g.add(cap);
|
||||
const band = cyl(rr * 1.06, rr * 1.06, 0.18, m.stripe, 14); band.position.y = b.h * 0.42; g.add(band);
|
||||
} else if (b.kind === 'scrap') {
|
||||
for (let k = 0; k < 5; k++) {
|
||||
const w2 = b.hw * (0.5 + brnd() * 0.75), h2 = b.h * (0.35 + brnd() * 0.65), d2 = b.hd * (0.5 + brnd() * 0.75);
|
||||
const p2 = box(w2, h2, d2, mat);
|
||||
p2.position.set((brnd() - 0.5) * b.hw, h2 / 2, (brnd() - 0.5) * b.hd);
|
||||
p2.rotation.y = brnd() * 3; p2.castShadow = true; g.add(p2);
|
||||
}
|
||||
} else if (b.kind === 'barrier') {
|
||||
const bar = box(b.hw * 2, b.h, b.hd * 2, mat); bar.position.y = b.h / 2; bar.castShadow = true; g.add(bar);
|
||||
const top = box(b.hw * 2, 0.1, b.hd * 2.1, m.stripe); top.position.y = b.h; g.add(top);
|
||||
} else {
|
||||
const bx = box(b.hw * 2, b.h, b.hd * 2, mat); bx.position.y = b.h / 2; bx.castShadow = true; g.add(bx);
|
||||
for (const sy of [0.28, 0.74]) { const band = box(b.hw * 2.05, 0.06, b.hd * 2.05, m.dark); band.position.y = b.h * sy; g.add(band); }
|
||||
}
|
||||
}
|
||||
for (const b of A.belts) {
|
||||
const g = new T.Group(); g.position.set(b.x, 0.012, b.z); scene.add(g);
|
||||
const pad = new T.Mesh(new T.PlaneGeometry(b.hw * 2, b.hd * 2), new T.MeshStandardMaterial({ color: 0x191d24, roughness: 0.92 }));
|
||||
pad.rotation.x = -Math.PI / 2; pad.receiveShadow = true; g.add(pad);
|
||||
const along = Math.abs(b.ax) > Math.abs(b.az); // slats across the running direction
|
||||
for (let k = -3; k <= 3; k++) {
|
||||
const slat = box(along ? 0.14 : b.hw * 1.9, 0.05, along ? b.hd * 1.9 : 0.14, m.stripe);
|
||||
slat.position.set(along ? k * b.hw / 3.4 : 0, 0.03, along ? 0 : k * b.hd / 3.4);
|
||||
g.add(slat);
|
||||
}
|
||||
}
|
||||
for (const o of A.oil) {
|
||||
const sl = new T.Mesh(new T.CircleGeometry(o.r, 22), new T.MeshStandardMaterial({ color: 0x06070b, roughness: 0.2, metalness: 0.75 }));
|
||||
sl.rotation.x = -Math.PI / 2; sl.position.set(o.x, 0.014, o.z); scene.add(sl);
|
||||
}
|
||||
out.rams = A.rams.map(d => {
|
||||
const g = new T.Group(); g.position.set(d.x, 0, d.z); scene.add(g);
|
||||
const head = box(0.5, 0.72, d.hd * 1.8, m.steel); head.position.y = 0.4; head.castShadow = true; g.add(head);
|
||||
const face = box(0.12, 0.74, d.hd * 1.85, m.stripe); face.position.set(d.nx * 0.3, 0.4, d.nz * 0.3); g.add(face);
|
||||
return { d, g, x0: d.x, z0: d.z };
|
||||
});
|
||||
|
||||
out.saws = A.saws.map(h => {
|
||||
const g = new T.Group(); g.position.set(h.x, 0.005, h.z); scene.add(g);
|
||||
const d = cyl(h.r * 0.85, h.r * 0.85, 0.035, m.steel, 32); g.add(d);
|
||||
@@ -648,7 +915,7 @@
|
||||
RC.buildRobotModel = buildRobot;
|
||||
|
||||
RC.Render = function (canvas, W, H) {
|
||||
const renderer = new T.WebGLRenderer({ canvas, antialias: true, alpha: true });
|
||||
const renderer = new T.WebGLRenderer({ canvas, antialias: true, alpha: true, powerPreference: 'high-performance' });
|
||||
renderer.setClearColor(0x000000, 0);
|
||||
renderer.outputEncoding = T.sRGBEncoding;
|
||||
renderer.toneMapping = T.ACESFilmicToneMapping;
|
||||
@@ -678,13 +945,49 @@
|
||||
fitCam(RC.ARENA.half);
|
||||
cam.position.copy(camBase); cam.lookAt(camLook);
|
||||
const gcam = new T.PerspectiveCamera(34, asp, 0.1, 60);
|
||||
gcam.position.set(3.7, 2.5, 4.4); gcam.lookAt(0, 0.3, 0);
|
||||
gcam.setViewOffset(W, H, 300, 40, W, H); // robot sits in the left part of the shop
|
||||
// put the shop camera at the current zoom (base distance / zoom, aimed at the turntable)
|
||||
function placeGarageCam() {
|
||||
const look = new T.Vector3(0, 0.3, 0), base = new T.Vector3(3.7, 2.5, 4.4);
|
||||
gcam.position.copy(look).add(base.clone().sub(look).multiplyScalar(1 / gcamZoom));
|
||||
gcam.lookAt(look);
|
||||
}
|
||||
gcam.setViewOffset(W, H, GARAGE_OFF_X, GARAGE_OFF_Y, W, H); // robot sits in the left part of the shop
|
||||
// intro / title: perspective camera flying over the arena
|
||||
const pcam = new T.PerspectiveCamera(40, asp, 0.1, 120);
|
||||
|
||||
let mode = 'garage', gRobot = null, robots = [], state = null, shake = 0, flashT = 0, introT = 0, scale = 1, hold = 0;
|
||||
let quality = 'high', fxMul = 1, camMode = 'iso', chaseInit = false;
|
||||
let quality = 'high', fxMul = 1, camMode = 'iso', chaseInit = false, gcamZoom = GZ_DEF;
|
||||
placeGarageCam(); // after gcamZoom exists: start fully zoomed out
|
||||
// workshop: show what the fitted weapon / turret actually does, on a short loop
|
||||
let demoT = 0;
|
||||
function demoGarage(dt) {
|
||||
const R = gRobot; if (!R) return;
|
||||
demoT += dt;
|
||||
const c = demoT % 3; // one signature move every 3 s
|
||||
if (R.saw) { R.sawA += dt * 26; R.saw.rotation[R.sawAxis || 'z'] = -R.sawA; }
|
||||
if (R.spinner) { R.spinA += dt * 17; R.spinner.rotation.y = R.spinA; }
|
||||
if (R.vspin) { R.spinA += dt * 19; R.vspin.rotation.z = -R.spinA; }
|
||||
if (R.hammer) {
|
||||
const k = c < 0.35 ? c / 0.35 : c < 1.2 ? 1 - (c - 0.35) / 0.85 : 0;
|
||||
R.hammer.rotation.z = lerp(1.9, -0.25, k);
|
||||
}
|
||||
if (R.flipper) R.flipper.rotation.z = -0.32 + (c < 0.3 ? Math.sin(c / 0.3 * Math.PI) * 1.5 : 0);
|
||||
if (R.jaws) {
|
||||
const k = c < 1.2 ? Math.abs(Math.sin(c / 1.2 * Math.PI)) : 0;
|
||||
for (const j of R.jaws) j.rotation.y = j.userData.side * (0.45 - k * 0.63);
|
||||
}
|
||||
if (R.gun) { R.gunA += dt * 16; R.gun.rotation.x = R.gunA; }
|
||||
const shooting = c > 1.5 && c < 2.3;
|
||||
if (R.flame) R.flame.visible = shooting;
|
||||
if (R.muzzle) R.muzzle.visible = shooting && Math.random() < 0.5;
|
||||
// launchers have no moving part: show a short recoil kick instead
|
||||
const tw2 = R.st.tower;
|
||||
if (R.turret && tw2 && (tw2.type === 'mortar' || tw2.type === 'swarm')) {
|
||||
const kick = c > 1.5 && c < 1.75 ? Math.sin((c - 1.5) / 0.25 * Math.PI) : 0;
|
||||
R.turret.rotation.z = -0.14 * kick;
|
||||
}
|
||||
}
|
||||
|
||||
const PX = [6, 34, 18], WORLD = [0.07, 0.7, 0.32]; // particle sizes: ortho px / perspective m
|
||||
const pointMode = persp => [sparks, smoke, fire].forEach((p, i) => { p.pts.material.size = persp ? WORLD[i] : PX[i]; });
|
||||
|
||||
@@ -693,7 +996,8 @@
|
||||
get introTime() { return introT; },
|
||||
resize(sc) {
|
||||
scale = sc;
|
||||
const cap = quality === 'low' ? 1 : quality === 'medium' ? 1.5 : 3;
|
||||
// the stage is scaled up by CSS; rendering at full devicePixelRatio on top of that is the main CPU/GPU hog
|
||||
const cap = quality === 'low' ? 1 : quality === 'medium' ? 1.25 : 1.5;
|
||||
renderer.setPixelRatio(Math.min(cap, sc * (root.devicePixelRatio || 1)));
|
||||
renderer.setSize(W, H);
|
||||
},
|
||||
@@ -702,7 +1006,7 @@
|
||||
quality = q; fxMul = q === 'low' ? 0.35 : q === 'medium' ? 0.7 : 1;
|
||||
const sh = q !== 'low';
|
||||
renderer.shadowMap.enabled = sh;
|
||||
renderer.shadowMap.type = q === 'high' ? T.PCFSoftShadowMap : T.PCFShadowMap;
|
||||
renderer.shadowMap.type = q === 'high' ? T.PCFSoftShadowMap : T.PCFShadowMap; // soft shadows only on high
|
||||
for (const sc of [arenaScene, garageScene]) sc.traverse(o => { if (o.material) [].concat(o.material).forEach(m => { m.needsUpdate = true; }); });
|
||||
api.resize(scale);
|
||||
},
|
||||
@@ -738,10 +1042,16 @@
|
||||
renderer.render(garageScene, gcam);
|
||||
let url = '';
|
||||
try { url = canvas.toDataURL('image/png'); } catch (e) { /* tainted canvas: no picture */ }
|
||||
gcam.setViewOffset(W, H, 300, 40, W, H); api.paintCam(false);
|
||||
gcam.setViewOffset(W, H, GARAGE_OFF_X, GARAGE_OFF_Y, W, H); api.paintCam(false);
|
||||
return url;
|
||||
},
|
||||
paintCam(on) { gcam.position.set(on ? 2.6 : 3.7, on ? 2.2 : 2.5, on ? 3.1 : 4.4); gcam.lookAt(0, 0.3, 0); },
|
||||
paintCam(on) {
|
||||
gcamZoom = GZ_DEF;
|
||||
if (on) { gcam.position.set(2.6, 2.2, 3.1); gcam.lookAt(0, 0.3, 0); } else placeGarageCam();
|
||||
},
|
||||
// garage preview zoom (shop "- Zoom +"): move the camera closer / further
|
||||
zoomGarage(mult) { gcamZoom = Kit.clamp(gcamZoom * mult, GZ_MIN, GZ_MAX); placeGarageCam(); },
|
||||
resetGarageZoom() { gcamZoom = GZ_DEF; placeGarageCam(); },
|
||||
// rebuild the arena scene if the fight uses a different one; rescale the camera
|
||||
setArena(A) {
|
||||
if (!A || arena.id === A.id) { if (A) fitCam(A.half); return; }
|
||||
@@ -755,7 +1065,7 @@
|
||||
mode = 'arena'; state = s; pointMode(camMode !== 'iso'); lightsOn(1); chaseInit = false;
|
||||
for (const R of robots) arenaScene.remove(R.root);
|
||||
robots = builds.map((b, i) => { const R = buildRobot(b, paints[i]); arenaScene.add(R.root); return R; });
|
||||
sparks.clear(); smoke.clear(); fire.clear(); shake = 0;
|
||||
sparks.clear(); smoke.clear(); fire.clear(); clearDebris(); shake = 0;
|
||||
for (const m of arena.rocketMeshes) arenaScene.remove(m);
|
||||
arena.rocketMeshes = [];
|
||||
},
|
||||
@@ -778,6 +1088,11 @@
|
||||
case 'press': puff(e.x, e.z, 14); burst(e.x, 0.1, e.z, 24, 5, [1, 0.8, 0.4]); shake = Math.max(shake, 0.45); break;
|
||||
case 'drop': puff(e.x, e.z, 8); shake = Math.max(shake, 0.2); break;
|
||||
case 'ko': explode(e.x, 0.5, e.z, 1.2); break;
|
||||
case 'broke':
|
||||
breakPart(robots[e.who], e.part);
|
||||
burst(e.x, 0.45, e.z, 22, 5, [1, 0.8, 0.4]); puff(e.x, e.z, 6);
|
||||
shake = Math.max(shake, 0.28);
|
||||
break;
|
||||
case 'boost': for (let k = 0; k < 6; k++) fire.spawn(e.x, 0.3, e.z, (Math.random() - 0.5), 0.6, (Math.random() - 0.5), 0.4, 1, 0.6, 0.2); break;
|
||||
}
|
||||
}
|
||||
@@ -799,6 +1114,7 @@
|
||||
frame(dt, now) {
|
||||
if (mode === 'garage') {
|
||||
if (hold > 0) hold -= dt; else garage.turntable.rotation.y += dt * 0.45;
|
||||
demoGarage(dt);
|
||||
renderer.render(garageScene, gcam);
|
||||
return;
|
||||
}
|
||||
@@ -903,9 +1219,49 @@
|
||||
arena.flashLight.position.set(x, 1.2, z); flashT = 1; shake = Math.max(shake, 0.3 * k);
|
||||
}
|
||||
|
||||
// parts torn off in a fight: the real mesh leaves the robot and tumbles over the floor
|
||||
const debris = [];
|
||||
function dropPiece(obj) {
|
||||
const wp = new T.Vector3(), wq = new T.Quaternion();
|
||||
obj.getWorldPosition(wp); obj.getWorldQuaternion(wq);
|
||||
arenaScene.add(obj);
|
||||
obj.position.copy(wp); obj.quaternion.copy(wq);
|
||||
debris.push({ o: obj, vx: (Math.random() - 0.5) * 3.5, vy: 2.2 + Math.random() * 1.8, vz: (Math.random() - 0.5) * 3.5,
|
||||
rx: (Math.random() - 0.5) * 9, rz: (Math.random() - 0.5) * 9, t: 9 });
|
||||
while (debris.length > 10) { const d = debris.shift(); arenaScene.remove(d.o); }
|
||||
}
|
||||
function updateDebris(dt) {
|
||||
for (let i = debris.length - 1; i >= 0; i--) {
|
||||
const d = debris[i];
|
||||
d.t -= dt; d.vy -= 22 * dt;
|
||||
d.o.position.x += d.vx * dt; d.o.position.y += d.vy * dt; d.o.position.z += d.vz * dt;
|
||||
if (d.o.position.y < 0.07) { d.o.position.y = 0.07; d.vy = -d.vy * 0.3; d.vx *= 0.6; d.vz *= 0.6; d.rx *= 0.5; d.rz *= 0.5; }
|
||||
d.o.rotation.x += d.rx * dt; d.o.rotation.z += d.rz * dt;
|
||||
if (d.t <= 0) { arenaScene.remove(d.o); debris.splice(i, 1); }
|
||||
}
|
||||
}
|
||||
function clearDebris() { for (const d of debris) arenaScene.remove(d.o); debris.length = 0; }
|
||||
// combat.js says a part broke off -> take it off the model (one piece tumbles away)
|
||||
function breakPart(R, part) {
|
||||
if (!R) return;
|
||||
if (part === 'wheels') {
|
||||
const w = (R.wheels || []).find(o => o.parent === R.tilt);
|
||||
if (w) { R.wheels.splice(R.wheels.indexOf(w), 1); dropPiece(w); }
|
||||
return;
|
||||
}
|
||||
const kill = R.tilt.children.filter(o => o.userData.part === part && o.visible);
|
||||
if (!kill.length) return;
|
||||
const main = kill[0];
|
||||
for (const o of kill) if (o !== main) o.visible = false;
|
||||
dropPiece(main);
|
||||
if (part === 'weapon') { R.saw = null; R.spinner = null; R.hammer = null; R.flipper = null; R.jaws = null; }
|
||||
if (part === 'tower') { R.turret = null; R.flame = null; R.gun = null; R.muzzle = null; }
|
||||
}
|
||||
|
||||
function animateArena(dt, now) {
|
||||
const s = state; if (!s) return;
|
||||
const A = state.arena || RC.ARENA;
|
||||
updateDebris(dt);
|
||||
robots.forEach((R, i) => {
|
||||
const r = s.robots[i];
|
||||
poseRobot(R, r, dt);
|
||||
@@ -923,6 +1279,12 @@
|
||||
fire.spawn(r.x + Math.cos(r.turretA) * 0.6, r.y + R.top + 0.18, r.z + Math.sin(r.turretA) * 0.6, Math.cos(a) * v, 0.3, Math.sin(a) * v, 0.45, 1, 0.55, 0.15);
|
||||
}
|
||||
});
|
||||
// wall rams punch out while they are armed
|
||||
for (const rm of arena.rams || []) {
|
||||
const on = RC.hazardOn(rm.d, s.t) ? 1 : 0, k = Math.min(1, dt * (on ? 20 : 5));
|
||||
rm.g.position.x = lerp(rm.g.position.x, rm.x0 + rm.d.nx * on * 1.2, k);
|
||||
rm.g.position.z = lerp(rm.g.position.z, rm.z0 + rm.d.nz * on * 1.2, k);
|
||||
}
|
||||
// saws
|
||||
for (const S of arena.saws) {
|
||||
const on = RC.hazardOn(S.h, s.t), warn = RC.hazardOn(S.h, s.t + 0.6);
|
||||
@@ -952,14 +1314,22 @@
|
||||
for (const d of arena.pitDoors) { d.position.x = A.pit.x + d.userData.sx * (A.pit.hw / 2 + o * A.pit.hw * 1.02); d.position.y = 0.025 + o * 0.01; }
|
||||
for (const l of arena.pitLamps) l.material.emissiveIntensity = s.pitAlarm ? (Math.sin(now / 150) > 0 ? 2.5 : 0.4) : 0;
|
||||
// rockets
|
||||
while (arena.rocketMeshes.length < s.rockets.length) { const m = new T.Mesh(arena.rocketGeo, arena.rocketMat); arenaScene.add(m); arena.rocketMeshes.push(m); }
|
||||
while (arena.rocketMeshes.length < s.rockets.length) {
|
||||
const gr = new T.Group();
|
||||
const body = new T.Mesh(arena.rocketGeo, arena.rocketMat); gr.add(body);
|
||||
const nose = new T.Mesh(new T.ConeGeometry(0.055, 0.12, 8), arena.rocketMat);
|
||||
nose.rotation.z = -Math.PI / 2; nose.position.x = 0.21; gr.add(nose);
|
||||
for (const sz of [-1, 1]) { const fin = new T.Mesh(new T.BoxGeometry(0.09, 0.012, 0.07), arena.rocketMat); fin.position.set(-0.13, 0, sz * 0.045); gr.add(fin); }
|
||||
arenaScene.add(gr); arena.rocketMeshes.push(gr);
|
||||
}
|
||||
arena.rocketMeshes.forEach((m, i) => {
|
||||
const k = s.rockets[i];
|
||||
m.visible = !!k;
|
||||
if (k) {
|
||||
m.position.set(k.x, k.y, k.z); m.rotation.y = -k.a;
|
||||
fire.spawn(k.x - Math.cos(k.a) * 0.2, k.y, k.z - Math.sin(k.a) * 0.2, 0, 0.2, 0, 0.3, 1, 0.6, 0.2);
|
||||
if (Math.random() < 0.5) smoke.spawn(k.x, k.y, k.z, 0, 0.2, 0, 0.8, 0.5, 0.5, 0.5);
|
||||
const bx = k.x - Math.cos(k.a) * 0.22, bz = k.z - Math.sin(k.a) * 0.22;
|
||||
for (let q = 0; q < 2; q++) fire.spawn(bx, k.y, bz, (Math.random() - 0.5) * 0.4, 0.25, (Math.random() - 0.5) * 0.4, 0.26, 1, 0.65, 0.22);
|
||||
smoke.spawn(bx, k.y, bz, (Math.random() - 0.5) * 0.3, 0.35, (Math.random() - 0.5) * 0.3, 1.1, 0.55, 0.55, 0.55);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
RC.stats = build => {
|
||||
const ch = part(build, 'chassis'), mo = part(build, 'motor'), wh = part(build, 'wheels');
|
||||
const ar = part(build, 'armour'), we = part(build, 'weapon'), to = part(build, 'tower');
|
||||
const ar = part(build, 'armour'), we = part(build, 'weapon'), to = part(build, 'tower'), gd = part(build, 'gadget');
|
||||
const v = RC.validate(build);
|
||||
const mass = Math.max(30, v.weight);
|
||||
let value = 0;
|
||||
@@ -46,7 +46,7 @@
|
||||
push: wh ? wh.push : 1,
|
||||
len, wid, h: ch ? ch.h : 0.42,
|
||||
rad: Math.hypot(len, wid) / 2 * 0.9, // close to the body corners so robots do not clip through each other
|
||||
weapon: we, tower: to,
|
||||
weapon: we, tower: to, gadget: gd, armour: ar,
|
||||
invertible: !!(wh && wh.invertible),
|
||||
lowProfile: !!(ch && ch.lowProfile),
|
||||
frontArmour: ch && ch.frontArmour ? ch.frontArmour : 0,
|
||||
|
||||
54
game/shop.js
@@ -10,9 +10,13 @@
|
||||
'use strict';
|
||||
const RC = root.RC, $ = Kit.$;
|
||||
RC.PAINTS = [0xd8452b, 0xff7a1a, 0xf2c230, 0x5fae3b, 0x2e9c8f, 0x2a6fd8, 0x6a3fb0, 0xd94f9a, 0xe6e6e6, 0x8c8c8c, 0x3a3d44, 0x15171b];
|
||||
// ready-made [body, accent] combinations
|
||||
RC.SCHEMES = [[0xff7a1a, 0x15171b], [0x15171b, 0xff7a1a], [0x2a6fd8, 0xe6e6e6], [0xd8452b, 0xf2c230],
|
||||
[0x5fae3b, 0x15171b], [0x6a3fb0, 0xf2c230], [0xe6e6e6, 0xd8452b], [0x3a3d44, 0x2e9c8f]];
|
||||
const hex = n => '#' + (n >>> 0).toString(16).padStart(6, '0');
|
||||
const SELL = 0.5;
|
||||
const GLYPH = { chassis: '🧱', motor: '⚙️', wheels: '🛞', battery: '🔋', armour: '🛡️', weapon: '🪓', tower: '🔥' };
|
||||
const HOTKEY = { weapon: 'hk_weapon', tower: 'hk_tower', gadget: 'hk_gadget' };
|
||||
const GLYPH = { chassis: '🧱', motor: '⚙️', wheels: '🛞', battery: '🔋', armour: '🛡️', weapon: '🪓', tower: '🔥', gadget: '🧰' };
|
||||
const ICO = { hp: ['ico_hp', '❤️'], armour: ['ico_armour', '🛡️'], speed: ['ico_speed', '⏱️'], weight: ['ico_weight', '⚖️'],
|
||||
power: ['ico_power', '⚡'], money: ['ico_credits', '🪙'], fame: ['ico_fame', '⭐'], accel: [null, '🚀'], turn: [null, '↻'] };
|
||||
RC.pic = (name, glyph = '', cls = '') =>
|
||||
@@ -21,7 +25,7 @@
|
||||
|
||||
RC.Shop = function (opt) {
|
||||
const t = opt.t;
|
||||
let slot = 'weapon', sel = undefined, tipN = 0;
|
||||
let slot = 'weapon', sel = undefined, tipN = 0, topTab = 'build';
|
||||
|
||||
function chipsFor(p) {
|
||||
const s = [];
|
||||
@@ -32,6 +36,8 @@
|
||||
if (p.dmg) s.push(`<span>${t('st_dmg', { n: p.dmg })}</span>`);
|
||||
if (p.dps) s.push(`<span>${t('st_dps', { n: p.dps })}</span>`);
|
||||
if (p.range) s.push(`<span>${t('st_range', { n: p.range })}</span>`);
|
||||
// which button works this part in a fight
|
||||
if (HOTKEY[p.slot]) s.push(`<span class="key">⌨ ${t(HOTKEY[p.slot])}</span>`);
|
||||
s.push(`<span>${ico('weight')}${p.weight} kg</span>`);
|
||||
if (p.slot === 'battery') s.push(`<span>${ico('power')}+${p.power}</span>`);
|
||||
else if (p.power) s.push(`<span>${ico('power')}${p.power}</span>`);
|
||||
@@ -101,14 +107,54 @@
|
||||
|
||||
// paint
|
||||
for (const [id, key] of [['paintBody', 'body'], ['paintAccent', 'accent']]) {
|
||||
$(id).innerHTML = `<span class="lb">${t('paint_' + key)}</span>` + RC.PAINTS.map(c => `<span class="sw ${save.paint[key] === c ? 'on' : ''}" data-c="${c}" style="background:${hex(c)}"></span>`).join('');
|
||||
$(id).innerHTML = RC.PAINTS.map(c => `<span class="sw ${save.paint[key] === c ? 'on' : ''}" data-c="${c}" style="background:${hex(c)}"></span>`).join('');
|
||||
$(id).querySelectorAll('.sw').forEach(el => { el.onclick = () => { save.paint[key] = +el.dataset.c; opt.sfx.click(); opt.onSave(); opt.onPaint(); render(); }; });
|
||||
}
|
||||
// ready-made two-colour schemes
|
||||
const sc = $('paintSchemes');
|
||||
if (sc) {
|
||||
sc.innerHTML = RC.SCHEMES.map(([b2, a2]) => {
|
||||
const on = save.paint.body === b2 && save.paint.accent === a2;
|
||||
return `<span class="sw duo ${on ? 'on' : ''}" data-b="${b2}" data-a="${a2}"><i style="background:${hex(b2)}"></i><i style="background:${hex(a2)}"></i></span>`;
|
||||
}).join('');
|
||||
sc.querySelectorAll('.sw').forEach(el => {
|
||||
el.onclick = () => { save.paint.body = +el.dataset.b; save.paint.accent = +el.dataset.a; opt.sfx.click(); opt.onSave(); opt.onPaint(); render(); };
|
||||
});
|
||||
}
|
||||
$('gErr').textContent = v.errors.map(e => t('err_' + e.replace(/^(need|bad)_.*/, '$1'), { slot: t('slot_' + e.split('_')[1]) })).join(' · ');
|
||||
$('bLeague').disabled = !v.ok; $('bTrain').disabled = !v.ok;
|
||||
const name = $('rname');
|
||||
if (document.activeElement !== name) name.value = save.robotName;
|
||||
if (!$('mechTip').textContent) tip();
|
||||
renderTopTabs(); renderFitted();
|
||||
// live preview: show the selected part on the 3D robot (even parts you can't afford yet)
|
||||
if (opt.onPreview) opt.onPreview(topTab === 'build' && sel !== b[slot] ? Object.assign({}, b, { [slot]: sel }) : b);
|
||||
}
|
||||
|
||||
// top mode tabs: Parts / Paint / Hangar
|
||||
function renderTopTabs() {
|
||||
const tabs = [['build', '🔧 ' + t('tab_build')], ['paint', '🎨 ' + t('tab_paint')], ['hangar', '🚗 ' + t('tab_hangar')]];
|
||||
$('shopTabs').innerHTML = tabs.map(([k, label]) => `<button class="${k === topTab ? 'on' : ''}" data-tab="${k}">${label}</button>`).join('');
|
||||
$('shopTabs').querySelectorAll('button').forEach(bt => { bt.onclick = () => { setTab(bt.dataset.tab); opt.sfx.click(); }; });
|
||||
$('buildView').classList.toggle('hide', topTab !== 'build');
|
||||
$('paintView').classList.toggle('hide', topTab !== 'paint');
|
||||
$('hangarView').classList.toggle('hide', topTab !== 'hangar');
|
||||
if (topTab === 'hangar' && opt.onHangarView) opt.onHangarView($('hangarView'));
|
||||
}
|
||||
function setTab(k) { topTab = k; renderTopTabs(); }
|
||||
|
||||
// fitted parts summary (left column): every slot with the equipped part + quick remove/jump
|
||||
function renderFitted() {
|
||||
const save = opt.getSave(), b = save.build;
|
||||
$('fitted').innerHTML = RC.SLOTS.map(sl => {
|
||||
const id = b[sl], p = id && RC.PARTS[id];
|
||||
const rm = p && !RC.REQUIRED[sl] ? `<span class="frm" data-rm="${sl}">✕</span>` : '<span></span>';
|
||||
return `<div class="frow" data-goto="${sl}">${RC.pic('slot_' + sl, GLYPH[sl])}<span class="fn ${p ? '' : 'empty'}">${p ? p.name : t('none')}</span>${rm}</div>`;
|
||||
}).join('');
|
||||
$('fitted').querySelectorAll('.frow').forEach(el => { el.onclick = e => {
|
||||
if (e.target.dataset.rm) { const s = e.target.dataset.rm; opt.getSave().build[s] = null; opt.sfx.click(); opt.onSave(); opt.onBuild(); render(); return; }
|
||||
slot = el.dataset.goto; sel = opt.getSave().build[slot] || null; topTab = 'build'; opt.sfx.click(); render();
|
||||
}; });
|
||||
}
|
||||
|
||||
function act2(what) {
|
||||
@@ -140,6 +186,6 @@
|
||||
});
|
||||
$('rname').addEventListener('keydown', e => { if (e.key === 'Enter') $('rname').blur(); e.stopPropagation(); });
|
||||
$('mechPic').innerHTML = `<img src="${Kit.asset('assets/Sprites/npc_mechanic.png')}" alt="" onerror="this.classList.add('missing')">`;
|
||||
return { render, tip, reset() { sel = undefined; } };
|
||||
return { render, tip, setTab, reset() { sel = undefined; topTab = 'build'; } };
|
||||
};
|
||||
})(window);
|
||||
|
||||
149
game/uicheck.js
Normal file
@@ -0,0 +1,149 @@
|
||||
/* Robot Clash - layout self-test (dev only, loaded always but idle without ?uicheck).
|
||||
|
||||
RC.uiCheck() measures the live DOM and reports layout faults as text:
|
||||
- containers that scroll (content taller than the box)
|
||||
- elements sticking out of #stage
|
||||
- overlapping pairs that must not touch (HUD over content, pad over cooldowns, ...)
|
||||
- tap targets below 34 px (tablet rule)
|
||||
- labels cut off with an ellipsis
|
||||
- heading font actually loaded
|
||||
The result goes into <pre id="uicheck"> and document.title, so it can be read from a
|
||||
headless --dump-dom run without taking a screenshot (Michael's rule: never screenshots). */
|
||||
(function (root) {
|
||||
'use strict';
|
||||
const RC = (root.RC = root.RC || {});
|
||||
// catch script errors as soon as this file loads (it runs before game.js), so a headless
|
||||
// --dump-dom run shows them instead of silently rendering a half-dead page
|
||||
const jsErrors = [];
|
||||
addEventListener('error', e => jsErrors.push(String(e.message || e.error) + ' @ ' + (e.filename || '').split('/').pop() + ':' + e.lineno));
|
||||
addEventListener('unhandledrejection', e => jsErrors.push('promise: ' + String(e.reason)));
|
||||
|
||||
const MIN_TAP = 34; // px, smallest allowed button edge on touch
|
||||
const EPS = 1.5; // rounding slack
|
||||
|
||||
const vis = el => {
|
||||
if (!el || !el.getBoundingClientRect) return false;
|
||||
const r = el.getBoundingClientRect();
|
||||
if (r.width < 1 || r.height < 1) return false;
|
||||
const st = getComputedStyle(el);
|
||||
return st.display !== 'none' && st.visibility !== 'hidden' && +st.opacity > 0.05;
|
||||
};
|
||||
const all = sel => Array.from(document.querySelectorAll(sel)).filter(vis);
|
||||
const one = sel => all(sel)[0] || null;
|
||||
const name = el => el.id ? '#' + el.id : '.' + (el.className || el.tagName).toString().trim().split(/\s+/)[0];
|
||||
const overlap = (a, b) => {
|
||||
const r = a.getBoundingClientRect(), q = b.getBoundingClientRect();
|
||||
const w = Math.min(r.right, q.right) - Math.max(r.left, q.left);
|
||||
const h = Math.min(r.bottom, q.bottom) - Math.max(r.top, q.top);
|
||||
return w > EPS && h > EPS ? Math.round(w) + 'x' + Math.round(h) : null;
|
||||
};
|
||||
|
||||
// containers that are allowed to scroll only when genuinely full (long lists)
|
||||
const SCROLLERS = ['#cards', '.roomlist', '.plist', '#hangarView', '#paintView', '.card', '.board'];
|
||||
// pairs that must never cover each other: [a, b, why]
|
||||
const PAIRS = [
|
||||
['#hud', '#rname', 'HUD over robot name'],
|
||||
['#hud', '#shopTabs', 'HUD over shop tabs'],
|
||||
['#hud', '.card', 'HUD over dialog'],
|
||||
['#hud', '.lobbyfull', 'HUD over lobby'],
|
||||
['#hud', '.opps', 'HUD over league grid'],
|
||||
['#hud', '.fbox', 'HUD over the health box'],
|
||||
['#winctl', '#hud', 'window buttons over HUD'],
|
||||
['#winctl', '#fightHud', 'window buttons over fight HUD'],
|
||||
['#fCds', '#pad > div:first-child', 'cooldown chips under the d-pad'],
|
||||
['#fCds', '#pad .fire', 'cooldown chips under the fire buttons'],
|
||||
['#fCds', '.fbox', 'cooldown chips over a fight box'],
|
||||
['#pad', '#fightHud', 'touch pad over fight HUD'],
|
||||
];
|
||||
|
||||
RC.uiCheck = function () {
|
||||
const bad = [], note = [];
|
||||
const stage = document.getElementById('stage');
|
||||
if (!stage) return { ok: false, lines: ['no #stage'] };
|
||||
const sr = stage.getBoundingClientRect();
|
||||
|
||||
// 1. scrolling containers
|
||||
for (const sel of SCROLLERS) {
|
||||
for (const el of all(sel)) {
|
||||
const over = el.scrollHeight - el.clientHeight;
|
||||
if (over > EPS) bad.push(`SCROLL ${name(el)} +${Math.round(over)}px (${el.scrollHeight}>${el.clientHeight})`);
|
||||
const overX = el.scrollWidth - el.clientWidth;
|
||||
if (overX > EPS) bad.push(`SCROLL-X ${name(el)} +${Math.round(overX)}px`);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. out of the stage
|
||||
for (const sel of ['#hud', '#shop', '#fightHud', '#pad', '.card', '.lobbyfull', '.title', '#fCds', '#detail', '.gbar', '.fitted']) {
|
||||
for (const el of all(sel)) {
|
||||
const r = el.getBoundingClientRect();
|
||||
const out = [
|
||||
r.left < sr.left - EPS ? 'left ' + Math.round(sr.left - r.left) : '',
|
||||
r.right > sr.right + EPS ? 'right ' + Math.round(r.right - sr.right) : '',
|
||||
r.top < sr.top - EPS ? 'top ' + Math.round(sr.top - r.top) : '',
|
||||
r.bottom > sr.bottom + EPS ? 'bottom ' + Math.round(r.bottom - sr.bottom) : '',
|
||||
].filter(Boolean);
|
||||
if (out.length) bad.push(`OUTSIDE ${name(el)} ${out.join(', ')}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. forbidden overlaps
|
||||
for (const [sa, sb, why] of PAIRS) {
|
||||
const a = one(sa), b = one(sb);
|
||||
if (!a || !b) continue;
|
||||
const o = overlap(a, b);
|
||||
if (o) bad.push(`OVERLAP ${sa} / ${sb} ${o} - ${why}`);
|
||||
}
|
||||
|
||||
// 4. tap targets (buttons that are visible right now)
|
||||
const scale = sr.width / (stage.offsetWidth || sr.width) || 1; // Kit.fit scales the stage
|
||||
for (const b of all('button')) {
|
||||
const r = b.getBoundingClientRect();
|
||||
const w = r.width / scale, h = r.height / scale;
|
||||
if (h < MIN_TAP - EPS || w < 18) {
|
||||
const lbl = (b.textContent || b.id || '?').trim().slice(0, 14);
|
||||
bad.push(`SMALL button "${lbl}" ${Math.round(w)}x${Math.round(h)} (min ${MIN_TAP} high)`);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. clipped labels
|
||||
for (const el of all('.nm, .fn, .pn, .rn, .hmn, .hn, .who')) {
|
||||
if (el.scrollWidth - el.clientWidth > 2) bad.push(`CLIPPED "${(el.textContent || '').trim().slice(0, 18)}" in ${name(el)}`);
|
||||
}
|
||||
|
||||
// 6. heading font - fonts.check() lies about missing families, so measure instead:
|
||||
// render the same text in "Russo One" and in a family that cannot exist; equal width = fallback.
|
||||
const fontOk = (() => {
|
||||
const c = document.createElement('canvas').getContext('2d');
|
||||
const probe = f => { c.font = '40px ' + f; return c.measureText('ROBOT CLASH 123').width; };
|
||||
const miss = probe('"__no_such_font__", monospace');
|
||||
return Math.abs(probe('"Russo One", "__no_such_font__", monospace') - miss) > 0.5;
|
||||
})();
|
||||
if (fontOk === false) bad.push('FONT "Russo One" not loaded (headings fall back)');
|
||||
note.push(`stage ${Math.round(sr.width)}x${Math.round(sr.height)} scale ${scale.toFixed(2)} · mode ${document.body.dataset.mode || '?'} · font ${fontOk}`);
|
||||
|
||||
for (const e of jsErrors) bad.unshift('JS ERROR ' + e);
|
||||
if (!document.body.dataset.mode) bad.push('NO SCREEN - setScreen() never ran (game did not start)');
|
||||
return { ok: bad.length === 0, lines: bad, note };
|
||||
};
|
||||
|
||||
// ?uicheck - run after layout settled and print into the page (and the title, for --dump-dom)
|
||||
RC.uiCheckRun = function () {
|
||||
const show = () => {
|
||||
const r = RC.uiCheck();
|
||||
let pre = document.getElementById('uicheck');
|
||||
if (!pre) {
|
||||
pre = document.createElement('pre');
|
||||
pre.id = 'uicheck';
|
||||
pre.style.cssText = 'position:fixed;left:0;top:0;max-width:60vw;max-height:100vh;overflow:auto;margin:0;z-index:9999;' +
|
||||
'font:12px/1.4 monospace;white-space:pre-wrap;padding:6px 8px;background:rgba(0,0,0,.85);pointer-events:none';
|
||||
document.body.appendChild(pre);
|
||||
}
|
||||
pre.style.color = r.ok ? '#6dff9e' : '#ff5a4a';
|
||||
pre.textContent = (r.ok ? 'UI ok' : 'UI FAIL ' + r.lines.length) + '\n' + r.note.join('\n') +
|
||||
(r.lines.length ? '\n' + r.lines.join('\n') : '');
|
||||
document.title = (r.ok ? 'UI ok' : 'UI FAIL ' + r.lines.length) + ' | ' + (document.body.dataset.mode || '?');
|
||||
};
|
||||
const go = () => { show(); setTimeout(show, 600); setTimeout(show, 1600); };
|
||||
if (document.fonts && document.fonts.ready) document.fonts.ready.then(go); else setTimeout(go, 300);
|
||||
};
|
||||
})(typeof window !== 'undefined' ? window : globalThis);
|
||||
@@ -100,9 +100,57 @@ PROMPTS = [
|
||||
"even lighting, no perspective, no shadows"),
|
||||
("tex_wall", "seamless texture of dark painted steel wall panel with rivets and yellow black hazard stripe band, "
|
||||
"even lighting, front view, no perspective"),
|
||||
|
||||
# --- new towers ---
|
||||
("part_zapper", f"robot turret: electric arc emitter with copper coils and crackling blue spark, {_STYLE}"),
|
||||
("part_mortar", f"robot turret: short stubby mortar tube angled upwards on a base plate, {_STYLE}"),
|
||||
("part_swarm", f"robot turret: boxy rocket pod with nine small launch tubes in a grid, {_STYLE}"),
|
||||
# --- new armour ---
|
||||
("part_mesh", f"set of thin steel wire mesh grille panels for a robot, {_STYLE}"),
|
||||
("part_buffer", f"set of fat black rubber buffer blocks and bumpers for a robot, {_STYLE}"),
|
||||
("part_spiked", f"set of steel armour plates covered in short sharp spikes, {_STYLE}"),
|
||||
("part_ceramic", f"set of pale ceramic armour tiles in a grid, chipped edges, {_STYLE}"),
|
||||
# --- new chassis ---
|
||||
("part_cage", f"open welded tube frame robot chassis, bare scrap metal cage, no panels, {_STYLE}"),
|
||||
("part_hexpod", f"six-sided hexagonal robot chassis shell with angled sloping sides, {_STYLE}"),
|
||||
("part_boiler", f"robot chassis made from a rolled steel drum lying on its side, riveted bands, {_STYLE}"),
|
||||
("part_fang", f"long low arrow-shaped robot chassis with a sharp pointed prow, {_STYLE}"),
|
||||
("part_plough", f"robot chassis with a big angled snowplough blade bolted across the nose, {_STYLE}"),
|
||||
("part_discus", f"wide flat round disc-shaped robot chassis, very low, {_STYLE}"),
|
||||
# --- new wheels ---
|
||||
("part_omni", f"set of small omni-directional caster wheels with rollers and steel forks, {_STYLE}"),
|
||||
("part_studs", f"pair of chunky studded off-road robot tyres with metal spikes, {_STYLE}"),
|
||||
("part_drumwh", f"single wide steel roller drum wheel with a hub, {_STYLE}"),
|
||||
("part_hover", f"robot hover skirt, a flat plate over a glowing orange air cushion ring, {_STYLE}"),
|
||||
# --- new weapons ---
|
||||
("part_lance", f"long pointed steel ramming lance spike on a front mount, {_STYLE}"),
|
||||
("part_drill", f"robot weapon: large conical spinning auger drill bit with spiral flutes, {_STYLE}"),
|
||||
("part_mace", f"robot weapon: heavy spiked steel ball mace on a swinging arm, {_STYLE}"),
|
||||
("part_launcher", f"robot weapon: huge curved scoop launcher plate on a hinge, {_STYLE}"),
|
||||
("part_drum", f"robot weapon: thick horizontal spinning drum rotor with hardened teeth, {_STYLE}"),
|
||||
("part_lifter", f"robot weapon: wide two-prong lifting scoop on a hinge, {_STYLE}"),
|
||||
("part_vdisc", f"robot weapon: large upright vertical spinning disc with four cutting teeth, {_STYLE}"),
|
||||
# --- gadgets ---
|
||||
("part_righter", f"robot gadget: pop-out self-righting lever arm device, {_STYLE}"),
|
||||
("part_turbo", f"robot gadget: nitro boost canister with orange flame jets, {_STYLE}"),
|
||||
("part_shield", f"robot gadget: glowing blue energy deflector field emitter dish, {_STYLE}"),
|
||||
("part_repair", f"robot gadget: repair kit toolbox with a red cross and a wrench, {_STYLE}"),
|
||||
("part_emp", f"robot gadget: EMP burst coil emitter crackling with blue electricity, {_STYLE}"),
|
||||
("slot_gadget", f"robot utility gadget module, {_ICON}"),
|
||||
|
||||
# --- title logo (wide lettering) + text-free emblem fallback ---
|
||||
("logo", "game logo lettering that reads exactly 'ROBOT CLASH', two words on two lines, bold industrial "
|
||||
"block capitals cut from brushed scratched steel, thick bevelled edges, orange rim glow, small "
|
||||
"yellow and black hazard stripe accents, a few sparks, centred, plain solid black background, "
|
||||
"no extra words, no frame, no border"),
|
||||
("logo_emblem", "game logo emblem without any text: a crossed wrench and circular saw blade behind a low "
|
||||
"flat wedge-shaped battle robot head with two glowing orange eyes, inside a worn steel "
|
||||
"badge with hazard stripes, bold simple silhouette, centred single subject, "
|
||||
"plain solid black background"),
|
||||
]
|
||||
|
||||
SIZES = {
|
||||
"logo": (1344, 576), "logo_emblem": (1024, 1024),
|
||||
"bg_workshop": (1536, 864), "bg_title": (1536, 864), "bg_win": (1536, 864), "bg_lose": (1536, 864),
|
||||
"npc_mechanic": (832, 1024),
|
||||
}
|
||||
|
||||
@@ -52,5 +52,144 @@ ok(wins.overlord >= wins.rustbucket, 'top robot beats bottom robot more often');
|
||||
RC.Combat.step(s, 1 / 60, [{}, {}]);
|
||||
ok(s.result && s.result.winner === 1 && s.result.reason === 'pit', 'pit = loss');
|
||||
}
|
||||
// gadgets
|
||||
ok(RC.validate({ ...RC.STARTER, gadget: 'turbo' }).ok, 'gadget build valid');
|
||||
ok(RC.stats({ ...RC.STARTER, gadget: 'emp' }).gadget.type === 'emp', 'gadget in stats');
|
||||
{
|
||||
// repair kit heals and spends a charge
|
||||
const s = RC.Combat.create({ robots: [RC.stats({ ...RC.STARTER, gadget: 'repair' }), RC.stats(RC.STARTER)], seed: 2 });
|
||||
const r = s.robots[0]; r.hp = r.maxHp * 0.3; const before = r.hp, uses = r.gUses;
|
||||
RC.Combat.step(s, 1 / 60, [{ fire3: true }, {}]);
|
||||
ok(r.hp > before && r.gUses === uses - 1, 'repair heals + spends charge');
|
||||
}
|
||||
{
|
||||
// shield cuts incoming damage
|
||||
const base = RC.stats(RC.STARTER), s = RC.Combat.create({ robots: [RC.stats({ ...RC.STARTER, gadget: 'shield' }), base], seed: 3 });
|
||||
const r = s.robots[0];
|
||||
RC.Combat.step(s, 1 / 60, [{ fire3: true }, {}]);
|
||||
ok(r.shield > 0, 'shield active after use');
|
||||
}
|
||||
{
|
||||
// emp stuns a nearby enemy
|
||||
const s = RC.Combat.create({ robots: [RC.stats({ ...RC.STARTER, gadget: 'emp' }), RC.stats(RC.STARTER)], seed: 4 });
|
||||
const a = s.robots[0], b = s.robots[1]; b.x = a.x + 1; b.z = a.z;
|
||||
RC.Combat.step(s, 1 / 60, [{ fire3: true }, {}]);
|
||||
ok(b.stun > 0, 'emp stuns nearby enemy');
|
||||
}
|
||||
{
|
||||
// self-righter flips a toppled robot back
|
||||
const s = RC.Combat.create({ robots: [RC.stats({ ...RC.STARTER, gadget: 'righter' }), RC.stats(RC.STARTER)], seed: 5 });
|
||||
const r = s.robots[0]; r.flipped = 2;
|
||||
RC.Combat.step(s, 1 / 60, [{ fire3: true }, {}]);
|
||||
ok(r.flipped === 0, 'self-righter clears flipped');
|
||||
}
|
||||
|
||||
// cooldown readout for the fight HUD
|
||||
{
|
||||
const s = RC.Combat.create({ robots: [RC.stats({ ...RC.STARTER, weapon: 'hammer', tower: 'rockets', gadget: 'repair' }), RC.stats(RC.STARTER)], seed: 6 });
|
||||
const r = s.robots[0];
|
||||
let cd = RC.Combat.cooldowns(r);
|
||||
ok(cd.length === 3 && cd.map(c => c.slot).join() === 'weapon,tower,gadget', 'cooldowns: one entry per fitted slot');
|
||||
ok(cd.every(c => c.p === 0), 'cooldowns: everything ready at the start');
|
||||
ok(cd[2].n === 2, 'cooldowns: repair kit reports its charges');
|
||||
r.hp = r.maxHp * 0.5;
|
||||
RC.Combat.step(s, 1 / 60, [{ fire: true, fire2: true, fire3: true }, {}]);
|
||||
cd = RC.Combat.cooldowns(r);
|
||||
ok(cd[0].p > 0.9 && cd[1].p > 0.9 && cd[2].p > 0.9, 'cooldowns: full right after use');
|
||||
ok(cd[2].n === 1, 'cooldowns: repair charge was spent');
|
||||
for (let i = 0; i < 60 * 12; i++) RC.Combat.step(s, 1 / 60, [{}, {}]);
|
||||
ok(RC.Combat.cooldowns(r).every(c => c.p === 0), 'cooldowns: back to zero when they ran out');
|
||||
}
|
||||
|
||||
// battle damage: parts tear off at fixed shares of health
|
||||
{
|
||||
const s = RC.Combat.create({ robots: [RC.stats({ ...RC.STARTER, armour: 'steel', weapon: 'hammer' }), RC.stats(RC.STARTER)], seed: 7 });
|
||||
const r = s.robots[0], A = s.arena;
|
||||
r.x = A.saws[0].x; r.z = A.saws[0].z; // park him on a floor saw so he keeps taking hits
|
||||
r.hp = r.maxHp * 0.61;
|
||||
const broke = [];
|
||||
for (let i = 0; i < 60 * 2 && !s.result; i++) {
|
||||
RC.Combat.step(s, 1 / 60, [{}, {}]);
|
||||
for (const e of s.events) if (e.type === 'broke') broke.push(e.part);
|
||||
s.events.length = 0;
|
||||
}
|
||||
ok(r.hp < r.maxHp * 0.6, 'the saw actually did damage');
|
||||
ok(broke.includes('armour'), 'armour tears off below 60% health');
|
||||
ok(r.lost.armour === true, 'the robot remembers the lost armour');
|
||||
}
|
||||
{
|
||||
const s = RC.Combat.create({ robots: [RC.stats({ ...RC.STARTER, weapon: 'hammer' }), RC.stats(RC.STARTER)], seed: 8 });
|
||||
const r = s.robots[0];
|
||||
r.lost.weapon = true;
|
||||
RC.Combat.step(s, 1 / 60, [{ fire: true }, {}]);
|
||||
ok(r.swing === 0 && r.cd === 0, 'a torn-off weapon cannot be fired any more');
|
||||
ok(RC.Combat.cooldowns(r)[0].broke === true, 'the HUD is told the weapon is gone');
|
||||
}
|
||||
{
|
||||
const speed = lost => {
|
||||
const s = RC.Combat.create({ robots: [RC.stats(RC.STARTER), RC.stats(RC.STARTER)], seed: 9 });
|
||||
const r = s.robots[0];
|
||||
if (lost) r.lost.wheels = true;
|
||||
for (let i = 0; i < 120; i++) RC.Combat.step(s, 1 / 60, [{ throttle: 1 }, {}]);
|
||||
return Math.hypot(r.vx, r.vz);
|
||||
};
|
||||
ok(speed(true) < speed(false) * 0.95, 'a burst wheel slows the robot down');
|
||||
}
|
||||
|
||||
// --- arena furniture: cover, belts, oil, and the new outlines ---
|
||||
const arenaById = id => RC.ARENAS.find(a => a.id === id);
|
||||
function drive(arenaId, place, input, secs) {
|
||||
const s = RC.Combat.create({ robots: [RC.stats(RC.STARTER), RC.stats(RC.STARTER)], seed: 11, arena: arenaId });
|
||||
const r = s.robots[0];
|
||||
Object.assign(r, place);
|
||||
for (let i = 0; i < 60 * secs && !s.result; i++) { RC.Combat.step(s, 1 / 60, [input, {}]); s.events.length = 0; }
|
||||
return { s, r };
|
||||
}
|
||||
{
|
||||
// every arena must be built sanely: nothing outside the outline, nothing buried in a block
|
||||
const rad = RC.stats(RC.STARTER).rad * 0.9;
|
||||
let bad = [];
|
||||
for (const A of RC.ARENAS) {
|
||||
const out = [];
|
||||
for (const p of A.starts) if (RC.wallPush(A, p.x, p.z, rad) || RC.inBlock(A, p.x, p.z, rad)) out.push('start');
|
||||
if (RC.wallPush(A, A.pit.x, A.pit.z, A.pit.hw) || RC.inBlock(A, A.pit.x, A.pit.z, 0)) out.push('pit');
|
||||
for (const g of [A.press, A.crane]) if (RC.wallPush(A, g.x, g.z, g.hw)) out.push('guardian');
|
||||
for (const h of A.saws) if (RC.wallPush(A, h.x, h.z, h.r)) out.push('saw');
|
||||
for (const h of A.flames) if (RC.wallPush(A, h.x, h.z, h.hw)) out.push('flame');
|
||||
for (const b of A.blocks) if (RC.wallPush(A, b.x, b.z, Math.max(b.hw, b.hd))) out.push('block');
|
||||
if (out.length) bad.push(A.id + ':' + out.join('/'));
|
||||
}
|
||||
ok(bad.length === 0, 'every arena fits inside its own outline (' + bad.join(' ') + ')');
|
||||
}
|
||||
{
|
||||
// a pillar is solid: driving at it does not get you through
|
||||
const A = arenaById('crucible'), b = A.blocks[0];
|
||||
const { r } = drive('crucible', { x: 0, z: -5, a: Math.PI / 2 }, { throttle: 1 }, 4);
|
||||
ok(r.z < b.z - b.hd, 'a solid block stops the robot (z=' + r.z.toFixed(2) + ')');
|
||||
}
|
||||
{
|
||||
// conveyor belt drags a robot that is not even driving
|
||||
const A = arenaById('colosseum'), bl = A.belts[0];
|
||||
const { r } = drive('colosseum', { x: bl.x, z: bl.z - 1, a: 0 }, {}, 1.2);
|
||||
ok(r.z > bl.z - 1 + 0.4, 'the belt drags an idle robot along (dz=' + (r.z - bl.z + 1).toFixed(2) + ')');
|
||||
}
|
||||
{
|
||||
// oil makes steering mushy
|
||||
const turn = place => Math.abs(drive('scrapyard', place, { throttle: 1, turn: 1 }, 0.6).r.av);
|
||||
const dry = turn({ x: 7.5, z: -1, a: 0 }), wet = turn({ x: -2.4, z: 1, a: 0 });
|
||||
ok(wet < dry * 0.85, 'oil cuts the turn rate (dry ' + dry.toFixed(2) + ' vs oil ' + wet.toFixed(2) + ')');
|
||||
}
|
||||
for (const id of ['crucible', 'colosseum', 'foundry', 'arena64']) {
|
||||
// round and octagon walls must hold the robot in
|
||||
const A = arenaById(id), rad = RC.stats(RC.STARTER).rad * 0.9;
|
||||
let worst = 0;
|
||||
for (const dir of [0, 1, 2, 3, 4, 5, 6, 7]) {
|
||||
const a = dir / 8 * Math.PI * 2;
|
||||
const { r } = drive(id, { x: 0, z: 0, a, vx: 0, vz: 0 }, { throttle: 1 }, 6);
|
||||
if (RC.wallPush(A, r.x, r.z, rad * 0.98)) worst++;
|
||||
}
|
||||
ok(worst === 0, `${A.shape} wall of ${id} keeps the robot inside`);
|
||||
}
|
||||
|
||||
console.log(fails ? `${fails} failure(s)` : 'all ok');
|
||||
process.exit(fails ? 1 : 0);
|
||||
|
||||