diff --git a/CLAUDE.md b/CLAUDE.md index 42d37c5..a628d29 100644 --- a/CLAUDE.md +++ b/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 `
` + `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
diff --git a/README.md b/README.md
index 9acb332..ba43cb7 100644
--- a/README.md
+++ b/README.md
@@ -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.
diff --git a/game/ai.js b/game/ai.js
index 66afb37..b2975f0 100644
--- a/game/ai.js
+++ b/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) };
diff --git a/game/assets/Fonts/OFL.txt b/game/assets/Fonts/OFL.txt
new file mode 100644
index 0000000..7a9a500
--- /dev/null
+++ b/game/assets/Fonts/OFL.txt
@@ -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.
diff --git a/game/assets/Fonts/RussoOne-Regular.ttf b/game/assets/Fonts/RussoOne-Regular.ttf
new file mode 100644
index 0000000..ba83727
Binary files /dev/null and b/game/assets/Fonts/RussoOne-Regular.ttf differ
diff --git a/game/assets/Sprites/logo.png b/game/assets/Sprites/logo.png
new file mode 100644
index 0000000..311059f
Binary files /dev/null and b/game/assets/Sprites/logo.png differ
diff --git a/game/assets/Sprites/logo_emblem.png b/game/assets/Sprites/logo_emblem.png
new file mode 100644
index 0000000..3104096
Binary files /dev/null and b/game/assets/Sprites/logo_emblem.png differ
diff --git a/game/assets/Sprites/part_boiler.png b/game/assets/Sprites/part_boiler.png
new file mode 100644
index 0000000..ef6ced4
Binary files /dev/null and b/game/assets/Sprites/part_boiler.png differ
diff --git a/game/assets/Sprites/part_buffer.png b/game/assets/Sprites/part_buffer.png
new file mode 100644
index 0000000..a192600
Binary files /dev/null and b/game/assets/Sprites/part_buffer.png differ
diff --git a/game/assets/Sprites/part_cage.png b/game/assets/Sprites/part_cage.png
new file mode 100644
index 0000000..72ef86c
Binary files /dev/null and b/game/assets/Sprites/part_cage.png differ
diff --git a/game/assets/Sprites/part_ceramic.png b/game/assets/Sprites/part_ceramic.png
new file mode 100644
index 0000000..cbe23fc
Binary files /dev/null and b/game/assets/Sprites/part_ceramic.png differ
diff --git a/game/assets/Sprites/part_discus.png b/game/assets/Sprites/part_discus.png
new file mode 100644
index 0000000..838cabf
Binary files /dev/null and b/game/assets/Sprites/part_discus.png differ
diff --git a/game/assets/Sprites/part_drill.png b/game/assets/Sprites/part_drill.png
new file mode 100644
index 0000000..0ad5c15
Binary files /dev/null and b/game/assets/Sprites/part_drill.png differ
diff --git a/game/assets/Sprites/part_drum.png b/game/assets/Sprites/part_drum.png
new file mode 100644
index 0000000..f374e31
Binary files /dev/null and b/game/assets/Sprites/part_drum.png differ
diff --git a/game/assets/Sprites/part_drumwh.png b/game/assets/Sprites/part_drumwh.png
new file mode 100644
index 0000000..31e6838
Binary files /dev/null and b/game/assets/Sprites/part_drumwh.png differ
diff --git a/game/assets/Sprites/part_emp.png b/game/assets/Sprites/part_emp.png
new file mode 100644
index 0000000..1aaff0e
Binary files /dev/null and b/game/assets/Sprites/part_emp.png differ
diff --git a/game/assets/Sprites/part_fang.png b/game/assets/Sprites/part_fang.png
new file mode 100644
index 0000000..3ab35c1
Binary files /dev/null and b/game/assets/Sprites/part_fang.png differ
diff --git a/game/assets/Sprites/part_hexpod.png b/game/assets/Sprites/part_hexpod.png
new file mode 100644
index 0000000..5e35bba
Binary files /dev/null and b/game/assets/Sprites/part_hexpod.png differ
diff --git a/game/assets/Sprites/part_hover.png b/game/assets/Sprites/part_hover.png
new file mode 100644
index 0000000..79f0d26
Binary files /dev/null and b/game/assets/Sprites/part_hover.png differ
diff --git a/game/assets/Sprites/part_lance.png b/game/assets/Sprites/part_lance.png
new file mode 100644
index 0000000..462d985
Binary files /dev/null and b/game/assets/Sprites/part_lance.png differ
diff --git a/game/assets/Sprites/part_launcher.png b/game/assets/Sprites/part_launcher.png
new file mode 100644
index 0000000..fa98b64
Binary files /dev/null and b/game/assets/Sprites/part_launcher.png differ
diff --git a/game/assets/Sprites/part_lifter.png b/game/assets/Sprites/part_lifter.png
new file mode 100644
index 0000000..5f2ec74
Binary files /dev/null and b/game/assets/Sprites/part_lifter.png differ
diff --git a/game/assets/Sprites/part_mace.png b/game/assets/Sprites/part_mace.png
new file mode 100644
index 0000000..f787301
Binary files /dev/null and b/game/assets/Sprites/part_mace.png differ
diff --git a/game/assets/Sprites/part_mesh.png b/game/assets/Sprites/part_mesh.png
new file mode 100644
index 0000000..b2c1549
Binary files /dev/null and b/game/assets/Sprites/part_mesh.png differ
diff --git a/game/assets/Sprites/part_mortar.png b/game/assets/Sprites/part_mortar.png
new file mode 100644
index 0000000..a2c8dba
Binary files /dev/null and b/game/assets/Sprites/part_mortar.png differ
diff --git a/game/assets/Sprites/part_omni.png b/game/assets/Sprites/part_omni.png
new file mode 100644
index 0000000..340e515
Binary files /dev/null and b/game/assets/Sprites/part_omni.png differ
diff --git a/game/assets/Sprites/part_plough.png b/game/assets/Sprites/part_plough.png
new file mode 100644
index 0000000..982e8b2
Binary files /dev/null and b/game/assets/Sprites/part_plough.png differ
diff --git a/game/assets/Sprites/part_repair.png b/game/assets/Sprites/part_repair.png
new file mode 100644
index 0000000..5166eb6
Binary files /dev/null and b/game/assets/Sprites/part_repair.png differ
diff --git a/game/assets/Sprites/part_righter.png b/game/assets/Sprites/part_righter.png
new file mode 100644
index 0000000..2128b30
Binary files /dev/null and b/game/assets/Sprites/part_righter.png differ
diff --git a/game/assets/Sprites/part_shield.png b/game/assets/Sprites/part_shield.png
new file mode 100644
index 0000000..ae46745
Binary files /dev/null and b/game/assets/Sprites/part_shield.png differ
diff --git a/game/assets/Sprites/part_spiked.png b/game/assets/Sprites/part_spiked.png
new file mode 100644
index 0000000..8667675
Binary files /dev/null and b/game/assets/Sprites/part_spiked.png differ
diff --git a/game/assets/Sprites/part_studs.png b/game/assets/Sprites/part_studs.png
new file mode 100644
index 0000000..78c76e5
Binary files /dev/null and b/game/assets/Sprites/part_studs.png differ
diff --git a/game/assets/Sprites/part_swarm.png b/game/assets/Sprites/part_swarm.png
new file mode 100644
index 0000000..c0cae6f
Binary files /dev/null and b/game/assets/Sprites/part_swarm.png differ
diff --git a/game/assets/Sprites/part_turbo.png b/game/assets/Sprites/part_turbo.png
new file mode 100644
index 0000000..b7b099f
Binary files /dev/null and b/game/assets/Sprites/part_turbo.png differ
diff --git a/game/assets/Sprites/part_vdisc.png b/game/assets/Sprites/part_vdisc.png
new file mode 100644
index 0000000..4b4a58c
Binary files /dev/null and b/game/assets/Sprites/part_vdisc.png differ
diff --git a/game/assets/Sprites/part_zapper.png b/game/assets/Sprites/part_zapper.png
new file mode 100644
index 0000000..488f9e6
Binary files /dev/null and b/game/assets/Sprites/part_zapper.png differ
diff --git a/game/assets/Sprites/slot_gadget.png b/game/assets/Sprites/slot_gadget.png
new file mode 100644
index 0000000..a227b00
Binary files /dev/null and b/game/assets/Sprites/slot_gadget.png differ
diff --git a/game/combat.js b/game/combat.js
index c553661..2d33877 100644
--- a/game/combat.js
+++ b/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,22 +300,32 @@
}
}
- // 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;
- 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 });
- damage(s, r, (vn - 1.8) * 4.5, null, { kind: 'spikes' });
- // 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;
+ // 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 });
+ damage(s, r, (vn - 1.8) * 4.5, null, { kind: 'spikes' });
+ // 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.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);
diff --git a/game/game.js b/game/game.js
index fa37703..8c4f879 100644
--- a/game/game.js
+++ b/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 => ``;
@@ -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 = `
`;
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
? `${online}`
: `${online}`;
- overlay.innerHTML = `ROBOT CLASH${t('menu_text')}
- ${btns}
-
+ // logo picture when ComfyGen made one, otherwise the lettering (never both, never nothing)
+ const logo = `
ROBOT CLASH`;
+ overlay.innerHTML = `
+ ${logo}
+ ${t('menu_text')}
+
+
+
${scores.enabled ? `` : ''}
- ${CREDITS}
`;
+ ${CREDITS}
`;
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 = `${flagHtml(lobbyRoom)}${esc(playerName())} (${t('you')})⭐ ${Kit.fmt(save.fame | 0)}`;
- const list = here.map(r => `${flagHtml(r.flag)}${esc(r.name)}⭐ ${Kit.fmt(r.fame | 0)}${r.state === 'idle' ? `` : `${t('busy')}`}`).join('');
- card(`${flagHtml(lobbyRoom)} ${t('room_title', { room: t('cc_' + lobbyRoom) })}
- ${t('room_count', { n: here.length + 1 })}
- ${meRow}${list || `${t('lobby_empty')}`}
- ${pendingOut ? `${t('waiting_accept')}
` : ''}
- `, { 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 => ``).join('');
+ const room = (f, label, flag) => ``;
+ const rooms = room('all', t('all_countries'), false) + FLAGS.map(f => room(f, t('cc_' + f), true)).join('');
+ const prow = (r, me) => `${flagHtml(me ? save.flag : r.flag)}${esc(me ? playerName() : r.name)}${me ? ` (${t('you')})` : ''}\u2B50 ${Kit.fmt((me ? save.fame : r.fame) | 0)}${me ? '' : (r.state === 'idle' ? `` : `${t('busy')}`)}`;
+ const list = here.map(r => prow(r, false)).join('');
+ const title = lobbyRoom === 'all' ? '🌍 ' + t('all_countries') : flagHtml(lobbyRoom) + ' ' + t('cc_' + lobbyRoom);
+ overlay.innerHTML = `
+ 🌍 ${t('lobby')}${rooms}
+
+ ${title} (${here.length + (showMe ? 1 : 0)})
+
+ ${showMe ? prow(null, true) : ''}${list || (showMe ? '' : `${t('lobby_empty')}`)}
+ ${pendingOut ? `${t('waiting_accept')}
` : ''}
+
+ `;
+ 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 ``; }).join('');
- card(`🌍 ${t('lobby')}
${t('pick_room')}
- ${rooms}
- `, { 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) => `
+ ${esc(r.name)}${esc(weaponName(r.build))}
+ ${i === save.active ? `${t('active_robot')}` : ``}
+ ${save.robots.length > 1 ? `` : ''}`).join('');
+ el.innerHTML = `${rows}
+ ${save.robots.length < MAX_ROBOTS ? `` : `${t('hangar_full')}
`}`;
+ 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) => `${opts.map(([v, label]) => ``).join('')}`;
const who = fbAcc() || (accounts.current && !accounts.current.guest ? accounts.current : null);
@@ -478,11 +564,13 @@
${t('key_pad')}${t('key_pad_text')}`;
}
function showHelp(back) {
+ overlayEnter();
card(`${t('how_to')}
${t('help_text')}
${keysHtml()}
${t('help_arena')}
`, { bg: 'bg_title.jpg' });
$('bOk').onclick = () => { SFX.click(); back(); };
}
function showRanking(back) {
+ overlayEnter();
card(`🏆 ${t('ranking')}
- ${t('loading')}
`, { 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 =>
+ `${RC.pic('part_' + c.id, '🔧')}` +
+ `${CD_KEY[c.slot]}${c.n === undefined ? '' : `${c.n}`}`).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 =>
+ `${RC.pic('part_' + build[k], GLYPH_SLOT[k])}`).join('');
+ $('fD' + i).innerHTML = `${icons}`;
+ }
+ 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
})();
diff --git a/game/index.html b/game/index.html
index eef6645..1e326cf 100644
--- a/game/index.html
+++ b/game/index.html
@@ -6,26 +6,53 @@
Robot Clash
@@ -284,17 +484,6 @@
↻ Turn your device sideways
-
- ROBOT CLASH
- 0
- 0
- League -
-
-
-
-
-
-
@@ -303,17 +492,30 @@
-
+
-
-
-
+
-
-
-
+
+
+
+
+
+ Fitted
+
+
+ Body
+ Accent
+ Schemes
+
+
+ Paint it yourselfPick quick colours above, or paint your own design.
+
+
+
+
-
+
2:00
-
+
+
+
+
-
+
+
+ ROBOT CLASH
+ 0
+ 0
+ League -
+
+
+
+
+
+
@@ -365,6 +581,7 @@
+