diff --git a/CLAUDE.md b/CLAUDE.md index e0d166a..54dfcfd 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -43,10 +43,16 @@ Roboter, KI-gesteuert), echtes PvP (WebRTC), Replays/Zuschauer, weitere Arenen + - `game/parts.js` Teilekatalog · `game/robot.js` Bauregeln + Werte · `game/combat.js` Physik, Waffen, Fallen, Siegregeln · `game/ai.js` KI + Liga-Kader – alle ohne DOM, laufen in Node. - `game/render3d.js` three.js-Szenen (Werkstatt, Arena), Roboter-Modelle aus Teilen, Partikel. -- `game/garage.js` Werkstatt-Panel · `game/game.js` Ablauf, Menüs, Kampf-HUD, Sound, Speichern. +- `game/shop.js` Werkstatt-Shop (Kategorien, Teile-Karten mit Sprites, Detail mit Vergleich, Mechaniker-Tipps) + · `game/painter.js` Lackiererei: selbst auf den Roboter malen (Ebene 512×256: links Draufsicht, rechts Seite, + Front jeweils rechts), 3D-Vorschau live; gespeichert als PNG-Data-URL in `save.paint.decal` + · `game/profiles.js` Konten (v1 lokal: Name + Passwort-Hash, je Konto eigener Spielstand; später Firebase) + · `game/game.js` Ablauf: Intro (3D-Kamerafahrt) → Titel → Login/Registrieren/Gast → Shop → Liga/VS → Kampf → Ergebnis, Einstellungen. - `game/vendor/three.min.js` three.js r149 (MIT, letzte Version mit klassischem Build – nicht auf ES-Module updaten). - Tests: `node tests/sim.test.js` (Regeln, Kämpfe ohne NaN, Grube), `node tests/balance.js [-v]` (Zahlen). -- Dev-Parameter: `index.html?play` (Werkstatt), `?fight=N` (Training gegen Liga-Gegner N), `&auto` (KI fährt +- 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. +- 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). ## Arbeitsweise diff --git a/README.md b/README.md index 1ce8f51..87598a8 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Angelegt am 2026-11-13 aus `_Tools\Library` (Vorlage `webgame`). Sprachen: Engli | M | Sound an/aus | | Gamepad | Stick fahren, A Waffe, B Turm, Start Pause | -Dev-Parameter: `index.html?play` (direkt in die Werkstatt), `?fight=N` (Training gegen Liga-Gegner N = 0…7), +Dev-Parameter: `index.html?title` (Titel ohne Intro), `?play` (direkt in den Shop, als Gast), `?play&paint` (Lackiererei mit Testbild), `?fight=N` (Training gegen Liga-Gegner N = 0…7), `&auto` (KI fährt deinen Roboter), `&ff=30` (30 Sekunden vorspulen). Tests (Node, ohne Browser): `node tests/sim.test.js` · Balance-Zahlen: `node tests/balance.js -v` @@ -29,8 +29,10 @@ Tests (Node, ohne Browser): `node tests/sim.test.js` · Balance-Zahlen: `node te ``` game/ index.html Seite, HUD, Werkstatt-Panel, Overlays (Styles inline) - game.js Ablauf: Menü, Werkstatt, Liga, Kampf, Ergebnis, Sound, Speichern - garage.js Werkstatt-Panel (Teile kaufen/einbauen/verkaufen, Lack) + game.js Ablauf: Intro, Titel, Konten, Einstellungen, Shop, Liga, Kampf, Ergebnis + shop.js Werkstatt-Shop (Teile kaufen/einbauen/verkaufen, Vergleich, Lack, Mechaniker) + painter.js Lackiererei: selbst auf den Roboter malen, live in 3D + profiles.js Konten: registrieren, einloggen, Gast (lokal, später Firebase) parts.js Teilekatalog (Werte, Preise) ┐ robot.js Bauregeln + Kampfwerte aus Teilen │ ohne DOM, combat.js Physik, Waffen, Fallen, Grube, Sieg │ laufen auch in Node diff --git a/game/ai.js b/game/ai.js index 7f038ea..32b944b 100644 --- a/game/ai.js +++ b/game/ai.js @@ -84,8 +84,13 @@ const rammer = !w || w.type === 'wedge'; const pushing = style === 'pusher' && s.pitOpen >= 1; contact = rammer && !pushing && dist < me.st.rad + e.st.rad + 0.3 ? contact + react : 0; - if (contact > 0.45 && retreat <= 0 && rand() < 0.25 + skill * 0.7) { retreat = 0.35 + rand() * 0.3; contact = 0; } - if (retreat > 0) { retreat -= react; cmd = { throttle: -1, turn: cmd.turn * 0.3 }; } + // only back off with room behind (no spike wall, no trap) + const half = A().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; } + if (retreat > 0 && !roomBehind) retreat = 0; + if (retreat > 0) { retreat -= react; cmd = { throttle: -0.85, turn: cmd.turn * 0.3 }; } hold = { throttle: cmd.throttle, turn: cmd.turn, fire: false, fire2: false }; return withWeapons(hold, s, me, e, dist, inZ); diff --git a/game/assets/Audio/music_fight.mp3 b/game/assets/Audio/music_fight.mp3 new file mode 100644 index 0000000..0dcbedb Binary files /dev/null and b/game/assets/Audio/music_fight.mp3 differ diff --git a/game/assets/Audio/music_garage.mp3 b/game/assets/Audio/music_garage.mp3 new file mode 100644 index 0000000..cf336c4 Binary files /dev/null and b/game/assets/Audio/music_garage.mp3 differ diff --git a/game/assets/Audio/music_title.mp3 b/game/assets/Audio/music_title.mp3 new file mode 100644 index 0000000..1b880dd Binary files /dev/null and b/game/assets/Audio/music_title.mp3 differ diff --git a/game/assets/Audio/sfx_boom.mp3 b/game/assets/Audio/sfx_boom.mp3 new file mode 100644 index 0000000..7dc46eb Binary files /dev/null and b/game/assets/Audio/sfx_boom.mp3 differ diff --git a/game/assets/Audio/sfx_buy.mp3 b/game/assets/Audio/sfx_buy.mp3 new file mode 100644 index 0000000..46616d9 Binary files /dev/null and b/game/assets/Audio/sfx_buy.mp3 differ diff --git a/game/assets/Audio/sfx_click.mp3 b/game/assets/Audio/sfx_click.mp3 new file mode 100644 index 0000000..9dd389c Binary files /dev/null and b/game/assets/Audio/sfx_click.mp3 differ diff --git a/game/assets/Audio/sfx_hit.mp3 b/game/assets/Audio/sfx_hit.mp3 new file mode 100644 index 0000000..e450a8e Binary files /dev/null and b/game/assets/Audio/sfx_hit.mp3 differ diff --git a/game/assets/Audio/sfx_lose.mp3 b/game/assets/Audio/sfx_lose.mp3 new file mode 100644 index 0000000..e62a6ea Binary files /dev/null and b/game/assets/Audio/sfx_lose.mp3 differ diff --git a/game/assets/Audio/sfx_saw.mp3 b/game/assets/Audio/sfx_saw.mp3 new file mode 100644 index 0000000..7aa1cb8 Binary files /dev/null and b/game/assets/Audio/sfx_saw.mp3 differ diff --git a/game/assets/Audio/sfx_win.mp3 b/game/assets/Audio/sfx_win.mp3 new file mode 100644 index 0000000..7e9e1ab Binary files /dev/null and b/game/assets/Audio/sfx_win.mp3 differ diff --git a/game/assets/Sprites/bg_lose.jpg b/game/assets/Sprites/bg_lose.jpg new file mode 100644 index 0000000..5021de2 Binary files /dev/null and b/game/assets/Sprites/bg_lose.jpg differ diff --git a/game/assets/Sprites/bg_title.jpg b/game/assets/Sprites/bg_title.jpg new file mode 100644 index 0000000..7666b1a Binary files /dev/null and b/game/assets/Sprites/bg_title.jpg differ diff --git a/game/assets/Sprites/bg_win.jpg b/game/assets/Sprites/bg_win.jpg new file mode 100644 index 0000000..d7cc462 Binary files /dev/null and b/game/assets/Sprites/bg_win.jpg differ diff --git a/game/assets/Sprites/bg_workshop.jpg b/game/assets/Sprites/bg_workshop.jpg new file mode 100644 index 0000000..619eded Binary files /dev/null and b/game/assets/Sprites/bg_workshop.jpg differ diff --git a/game/assets/Sprites/ico_armour.png b/game/assets/Sprites/ico_armour.png new file mode 100644 index 0000000..7d29682 Binary files /dev/null and b/game/assets/Sprites/ico_armour.png differ diff --git a/game/assets/Sprites/ico_credits.png b/game/assets/Sprites/ico_credits.png new file mode 100644 index 0000000..9dfaf06 Binary files /dev/null and b/game/assets/Sprites/ico_credits.png differ diff --git a/game/assets/Sprites/ico_fame.png b/game/assets/Sprites/ico_fame.png new file mode 100644 index 0000000..a97768c Binary files /dev/null and b/game/assets/Sprites/ico_fame.png differ diff --git a/game/assets/Sprites/ico_hp.png b/game/assets/Sprites/ico_hp.png new file mode 100644 index 0000000..a7161dd Binary files /dev/null and b/game/assets/Sprites/ico_hp.png differ diff --git a/game/assets/Sprites/ico_power.png b/game/assets/Sprites/ico_power.png new file mode 100644 index 0000000..fa5bb63 Binary files /dev/null and b/game/assets/Sprites/ico_power.png differ diff --git a/game/assets/Sprites/ico_speed.png b/game/assets/Sprites/ico_speed.png new file mode 100644 index 0000000..2be7dfe Binary files /dev/null and b/game/assets/Sprites/ico_speed.png differ diff --git a/game/assets/Sprites/ico_weight.png b/game/assets/Sprites/ico_weight.png new file mode 100644 index 0000000..43bce26 Binary files /dev/null and b/game/assets/Sprites/ico_weight.png differ diff --git a/game/assets/Sprites/icon.png b/game/assets/Sprites/icon.png new file mode 100644 index 0000000..ca007fd Binary files /dev/null and b/game/assets/Sprites/icon.png differ diff --git a/game/assets/Sprites/npc_mechanic.png b/game/assets/Sprites/npc_mechanic.png new file mode 100644 index 0000000..89f4468 Binary files /dev/null and b/game/assets/Sprites/npc_mechanic.png differ diff --git a/game/assets/Sprites/opp_buzzkill.png b/game/assets/Sprites/opp_buzzkill.png new file mode 100644 index 0000000..5a8b0ba Binary files /dev/null and b/game/assets/Sprites/opp_buzzkill.png differ diff --git a/game/assets/Sprites/opp_flapjack.png b/game/assets/Sprites/opp_flapjack.png new file mode 100644 index 0000000..523e500 Binary files /dev/null and b/game/assets/Sprites/opp_flapjack.png differ diff --git a/game/assets/Sprites/opp_gravedigger.png b/game/assets/Sprites/opp_gravedigger.png new file mode 100644 index 0000000..7cd15ee Binary files /dev/null and b/game/assets/Sprites/opp_gravedigger.png differ diff --git a/game/assets/Sprites/opp_overlord.png b/game/assets/Sprites/opp_overlord.png new file mode 100644 index 0000000..8f5e295 Binary files /dev/null and b/game/assets/Sprites/opp_overlord.png differ diff --git a/game/assets/Sprites/opp_pincer.png b/game/assets/Sprites/opp_pincer.png new file mode 100644 index 0000000..2e4ffec Binary files /dev/null and b/game/assets/Sprites/opp_pincer.png differ diff --git a/game/assets/Sprites/opp_rustbucket.png b/game/assets/Sprites/opp_rustbucket.png new file mode 100644 index 0000000..e9b7df2 Binary files /dev/null and b/game/assets/Sprites/opp_rustbucket.png differ diff --git a/game/assets/Sprites/opp_thunderclap.png b/game/assets/Sprites/opp_thunderclap.png new file mode 100644 index 0000000..e258e79 Binary files /dev/null and b/game/assets/Sprites/opp_thunderclap.png differ diff --git a/game/assets/Sprites/opp_tintoad.png b/game/assets/Sprites/opp_tintoad.png new file mode 100644 index 0000000..3bda7f4 Binary files /dev/null and b/game/assets/Sprites/opp_tintoad.png differ diff --git a/game/assets/Sprites/part_bigtyre.png b/game/assets/Sprites/part_bigtyre.png new file mode 100644 index 0000000..642ff39 Binary files /dev/null and b/game/assets/Sprites/part_bigtyre.png differ diff --git a/game/assets/Sprites/part_bulldog.png b/game/assets/Sprites/part_bulldog.png new file mode 100644 index 0000000..4fa7ca4 Binary files /dev/null and b/game/assets/Sprites/part_bulldog.png differ diff --git a/game/assets/Sprites/part_bulwark.png b/game/assets/Sprites/part_bulwark.png new file mode 100644 index 0000000..abc4b6a Binary files /dev/null and b/game/assets/Sprites/part_bulwark.png differ diff --git a/game/assets/Sprites/part_comet.png b/game/assets/Sprites/part_comet.png new file mode 100644 index 0000000..69d6c30 Binary files /dev/null and b/game/assets/Sprites/part_comet.png differ diff --git a/game/assets/Sprites/part_crate.png b/game/assets/Sprites/part_crate.png new file mode 100644 index 0000000..84bee44 Binary files /dev/null and b/game/assets/Sprites/part_crate.png differ diff --git a/game/assets/Sprites/part_crusher.png b/game/assets/Sprites/part_crusher.png new file mode 100644 index 0000000..aa04cb0 Binary files /dev/null and b/game/assets/Sprites/part_crusher.png differ diff --git a/game/assets/Sprites/part_doorstop.png b/game/assets/Sprites/part_doorstop.png new file mode 100644 index 0000000..c25ff8f Binary files /dev/null and b/game/assets/Sprites/part_doorstop.png differ diff --git a/game/assets/Sprites/part_flamer.png b/game/assets/Sprites/part_flamer.png new file mode 100644 index 0000000..7d2e631 Binary files /dev/null and b/game/assets/Sprites/part_flamer.png differ diff --git a/game/assets/Sprites/part_flipper.png b/game/assets/Sprites/part_flipper.png new file mode 100644 index 0000000..160aea8 Binary files /dev/null and b/game/assets/Sprites/part_flipper.png differ diff --git a/game/assets/Sprites/part_hammer.png b/game/assets/Sprites/part_hammer.png new file mode 100644 index 0000000..6a6340e Binary files /dev/null and b/game/assets/Sprites/part_hammer.png differ diff --git a/game/assets/Sprites/part_hardox.png b/game/assets/Sprites/part_hardox.png new file mode 100644 index 0000000..7a532b3 Binary files /dev/null and b/game/assets/Sprites/part_hardox.png differ diff --git a/game/assets/Sprites/part_hornet.png b/game/assets/Sprites/part_hornet.png new file mode 100644 index 0000000..bca1fb6 Binary files /dev/null and b/game/assets/Sprites/part_hornet.png differ diff --git a/game/assets/Sprites/part_lead.png b/game/assets/Sprites/part_lead.png new file mode 100644 index 0000000..6940a09 Binary files /dev/null and b/game/assets/Sprites/part_lead.png differ diff --git a/game/assets/Sprites/part_lipo.png b/game/assets/Sprites/part_lipo.png new file mode 100644 index 0000000..229af46 Binary files /dev/null and b/game/assets/Sprites/part_lipo.png differ diff --git a/game/assets/Sprites/part_minigun.png b/game/assets/Sprites/part_minigun.png new file mode 100644 index 0000000..958cd64 Binary files /dev/null and b/game/assets/Sprites/part_minigun.png differ diff --git a/game/assets/Sprites/part_nicd.png b/game/assets/Sprites/part_nicd.png new file mode 100644 index 0000000..8b36282 Binary files /dev/null and b/game/assets/Sprites/part_nicd.png differ diff --git a/game/assets/Sprites/part_rockets.png b/game/assets/Sprites/part_rockets.png new file mode 100644 index 0000000..910b207 Binary files /dev/null and b/game/assets/Sprites/part_rockets.png differ diff --git a/game/assets/Sprites/part_rubber.png b/game/assets/Sprites/part_rubber.png new file mode 100644 index 0000000..8dff059 Binary files /dev/null and b/game/assets/Sprites/part_rubber.png differ diff --git a/game/assets/Sprites/part_saw.png b/game/assets/Sprites/part_saw.png new file mode 100644 index 0000000..2bd7620 Binary files /dev/null and b/game/assets/Sprites/part_saw.png differ diff --git a/game/assets/Sprites/part_scarab.png b/game/assets/Sprites/part_scarab.png new file mode 100644 index 0000000..349d4dd Binary files /dev/null and b/game/assets/Sprites/part_scarab.png differ diff --git a/game/assets/Sprites/part_sparky.png b/game/assets/Sprites/part_sparky.png new file mode 100644 index 0000000..31a233b Binary files /dev/null and b/game/assets/Sprites/part_sparky.png differ diff --git a/game/assets/Sprites/part_spinner.png b/game/assets/Sprites/part_spinner.png new file mode 100644 index 0000000..207959b Binary files /dev/null and b/game/assets/Sprites/part_spinner.png differ diff --git a/game/assets/Sprites/part_steel.png b/game/assets/Sprites/part_steel.png new file mode 100644 index 0000000..7ac9ea3 Binary files /dev/null and b/game/assets/Sprites/part_steel.png differ diff --git a/game/assets/Sprites/part_titan.png b/game/assets/Sprites/part_titan.png new file mode 100644 index 0000000..6c63929 Binary files /dev/null and b/game/assets/Sprites/part_titan.png differ diff --git a/game/assets/Sprites/part_tracks.png b/game/assets/Sprites/part_tracks.png new file mode 100644 index 0000000..b03e97b Binary files /dev/null and b/game/assets/Sprites/part_tracks.png differ diff --git a/game/assets/Sprites/part_wedge.png b/game/assets/Sprites/part_wedge.png new file mode 100644 index 0000000..866348b Binary files /dev/null and b/game/assets/Sprites/part_wedge.png differ diff --git a/game/assets/Sprites/slot_armour.png b/game/assets/Sprites/slot_armour.png new file mode 100644 index 0000000..5e22512 Binary files /dev/null and b/game/assets/Sprites/slot_armour.png differ diff --git a/game/assets/Sprites/slot_battery.png b/game/assets/Sprites/slot_battery.png new file mode 100644 index 0000000..391e8a3 Binary files /dev/null and b/game/assets/Sprites/slot_battery.png differ diff --git a/game/assets/Sprites/slot_chassis.png b/game/assets/Sprites/slot_chassis.png new file mode 100644 index 0000000..bc0c53f Binary files /dev/null and b/game/assets/Sprites/slot_chassis.png differ diff --git a/game/assets/Sprites/slot_motor.png b/game/assets/Sprites/slot_motor.png new file mode 100644 index 0000000..ac7fb34 Binary files /dev/null and b/game/assets/Sprites/slot_motor.png differ diff --git a/game/assets/Sprites/slot_tower.png b/game/assets/Sprites/slot_tower.png new file mode 100644 index 0000000..d1dd9ab Binary files /dev/null and b/game/assets/Sprites/slot_tower.png differ diff --git a/game/assets/Sprites/slot_weapon.png b/game/assets/Sprites/slot_weapon.png new file mode 100644 index 0000000..901dda1 Binary files /dev/null and b/game/assets/Sprites/slot_weapon.png differ diff --git a/game/assets/Sprites/slot_wheels.png b/game/assets/Sprites/slot_wheels.png new file mode 100644 index 0000000..04636c9 Binary files /dev/null and b/game/assets/Sprites/slot_wheels.png differ diff --git a/game/assets/Sprites/tex_floor.jpg b/game/assets/Sprites/tex_floor.jpg new file mode 100644 index 0000000..81199e7 Binary files /dev/null and b/game/assets/Sprites/tex_floor.jpg differ diff --git a/game/game.js b/game/game.js index 0838706..843ac69 100644 --- a/game/game.js +++ b/game/game.js @@ -1,6 +1,7 @@ -/* Robot Clash - game frame: menu, workshop, league ladder, fight, result, saving, audio, scores. +/* Robot Clash - game frame: intro, title, accounts, settings, shop, league, fight, result, audio, scores. Logic lives in parts.js / robot.js / combat.js / ai.js (no DOM), the 3D view in render3d.js, - the workshop panel in garage.js. Texts: lang.js via t('key'). Credits line stays in the menu. */ + the shop panel in shop.js, accounts in profiles.js. Texts: lang.js via t('key'). + Credits line stays on the title screen. */ (function () { 'use strict'; const $ = Kit.$; @@ -11,23 +12,28 @@ // (docs/firebase/README.md). Empty = offline. const DB_URL = ''; - // Credits (standard for every game): shown in the menu, links open in the normal browser + // Credits (standard for every game): shown on the title screen, links open in the normal browser const DISCORD = 'https://discord.gg/Ej4JPmCZva'; const CREDITS = `© 2026 Michael Media · Discord`; // ---------------------------------------------------------------- services const L = Kit.i18n(window.LANG, { prefix: ID }); const t = L.t; - const slot = Kit.saveSlot(ID + '.save', () => ({ + const store = Kit.store(ID); + const settings = Object.assign({ gfx: 'high', intro: true }, store.get('settings', {})); + const saveSettings = () => store.set('settings', settings); + const accounts = RC.Accounts(ID); + const newSave = () => ({ money: 400, 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', name: '', tutorialSeen: false, - })); - let save = slot.load(); - const persist = () => slot.save(save); + paint: { body: 0xff7a1a, accent: 0x15171b }, robotName: 'Clank', tutorialSeen: false, + }); + let slot = null, save = null; // per account, set by enterAccount() + const persist = () => { if (slot && save) slot.save(save); }; const audio = Kit.createAudio({ prefix: ID, - files: ['sfx_click', 'sfx_buy', 'sfx_hit', 'sfx_win', 'sfx_lose', 'music_garage', 'music_fight'], + files: ['sfx_click', 'sfx_buy', 'sfx_hit', 'sfx_saw', 'sfx_boom', 'sfx_win', 'sfx_lose', 'music_title', 'music_garage', 'music_fight'], + throttle: { sfx_hit: 80, sfx_saw: 120, sfx_boom: 100 }, }); const scores = Kit.scores({ url: DB_URL }); const DEV = new URLSearchParams(location.search); @@ -39,36 +45,38 @@ ' ': 'fire', Shift: 'fire2', e: 'fire2', p: 'pause', Escape: 'pause', m: 'mute', Enter: 'ok', }, onPress(a) { + if (mode === 'intro') { skipIntro(); return; } if (a === 'pause') togglePause(); else if (a === 'mute') toggleMute(); else if (a === 'ok') { const b = overlay.querySelector('button.primary'); if (b && !b.disabled) b.click(); } }, }); - // ---------------------------------------------------------------- sound (synth until ComfyGen clips exist) + // ---------------------------------------------------------------- sound (ComfyGen clips + synth fallback) const last = {}; const every = (k, ms) => { const n = performance.now(); if (last[k] && n - last[k] < ms) return false; last[k] = n; return true; }; const SFX = { - click() { audio.sfx('sfx_click'); audio.tone(660, 0.05, 'square', 0.08); }, - buy() { audio.sfx('sfx_buy'); audio.arp([523, 784, 1046], 0.05, 'square', 0.1); }, + click() { audio.sfx('sfx_click'); audio.tone(660, 0.04, 'square', 0.05); }, + buy() { audio.sfx('sfx_buy'); audio.arp([523, 784, 1046], 0.05, 'square', 0.08); }, deny() { audio.tone(160, 0.15, 'square', 0.12, -40); }, beep(hi) { audio.tone(hi ? 1046 : 523, hi ? 0.4 : 0.15, 'square', 0.14); }, - win() { audio.sfx('sfx_win'); audio.arp([523, 659, 784, 1046, 1318], 0.09); }, - lose() { audio.sfx('sfx_lose'); audio.arp([392, 330, 262, 196], 0.14, 'sawtooth', 0.12); }, + clunk() { audio.noise(0.25, 0.5, 260); audio.tone(70, 0.3, 'sine', 0.4, -20); }, + win() { audio.sfx('sfx_win'); audio.arp([523, 659, 784, 1046, 1318], 0.09, 'square', 0.1); }, + lose() { audio.sfx('sfx_lose'); audio.arp([392, 330, 262, 196], 0.14, 'sawtooth', 0.1); }, event(e) { switch (e.type) { case 'bump': if (every('bump', 90)) audio.noise(0.12, Math.min(0.4, e.speed / 10), 700); break; - case 'wall': if (every('wall', 120)) { audio.noise(0.2, 0.35, 1600); audio.tone(190, 0.15, 'sawtooth', 0.1, -90); } break; + case 'wall': if (every('wall', 120)) { audio.sfx('sfx_hit'); audio.noise(0.2, 0.3, 1600); } break; case 'flip': audio.tone(200, 0.2, 'square', 0.13, 500); audio.noise(0.12, 0.25, 3000); break; case 'swing': audio.noise(0.15, 0.12, 900); break; case 'smash': audio.sfx('sfx_hit'); audio.noise(0.25, 0.45, 650); audio.tone(95, 0.25, 'sine', 0.4, -45); break; - case 'spinhit': audio.noise(0.3, 0.5, 2600); audio.tone(1200, 0.12, 'sawtooth', 0.1, -800); break; + case 'spinhit': audio.sfx('sfx_hit'); audio.noise(0.3, 0.5, 2600); audio.tone(1200, 0.12, 'sawtooth', 0.1, -800); break; case 'sparks': if (every('grind', 70)) audio.noise(0.06, 0.1, 5200); break; - case 'boom': audio.noise(0.6, 0.5, 420); audio.tone(70, 0.5, 'sine', 0.5, -40); break; - case 'ko': audio.noise(1.0, 0.6, 350); audio.tone(55, 0.9, 'sine', 0.5, -25); break; + case 'boom': audio.sfx('sfx_boom'); audio.noise(0.6, 0.5, 420); audio.tone(70, 0.5, 'sine', 0.5, -40); break; + case 'ko': audio.sfx('sfx_boom'); audio.noise(1.0, 0.6, 350); audio.tone(55, 0.9, 'sine', 0.5, -25); break; case 'launch': audio.noise(0.3, 0.18, 2200); audio.tone(300, 0.3, 'sawtooth', 0.07, 600); break; case 'press_warn': for (let k = 0; k < 3; k++) audio.tone(880, 0.1, 'square', 0.1, 0, k * 0.2); break; - case 'press': audio.noise(0.5, 0.65, 300); audio.tone(55, 0.5, 'sine', 0.6, -20); break; + 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 'pit_open': for (let k = 0; k < 3; k++) audio.tone(700, 0.3, 'square', 0.12, -250, k * 0.4); break; @@ -79,7 +87,7 @@ }, loops(s) { // continuous weapons as short repeated bursts for (const r of s.robots) { - if (r.sawOn && every('saw' + r.i, 110)) audio.tone(900 + Math.random() * 60, 0.1, 'sawtooth', 0.035); + if (r.sawOn && every('saw' + r.i, 110)) { audio.sfx('sfx_saw'); audio.tone(900 + Math.random() * 60, 0.1, 'sawtooth', 0.03); } if (r.flameOn && every('fl' + r.i, 120)) audio.noise(0.14, 0.12, 900); if (r.gunOn && every('gun' + r.i, 70)) audio.noise(0.04, 0.16, 3500); if (r.spin > 0.2 && every('spin' + r.i, 100)) audio.tone(120 + r.spin * 260, 0.1, 'sawtooth', 0.03 * r.spin); @@ -91,49 +99,268 @@ const cv = $('cv'); let ctx = cv.getContext('2d'); let view = null; - try { view = RC.Render($('gl'), W, H); } catch (err) { console.error(err); } + 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); } }); Kit.host.dragArea(document.body); const hex = n => '#' + (n >>> 0).toString(16).padStart(6, '0'); + const img = name => Kit.asset('assets/Sprites/' + name); + function backdrop(name) { $('bgimg').style.backgroundImage = name ? `url("${img(name)}")` : 'none'; } + $('icoMoney').innerHTML = ``; + $('icoFame').innerHTML = ``; - const garage = RC.Garage({ + const shop = RC.Shop({ t, getSave: () => save, onSave: persist, - onBuild: () => { view.showGarage(save.build, save.paint); garageTitle(); }, - onPaint: () => { view.showGarage(save.build, save.paint); garageTitle(); }, + onBuild: () => view.showGarage(save.build, paintObj()), + onPaint: () => view.setPaint(paintObj()), sfx: SFX, }); + // own artwork on the robot (painter.js): transparent 512x256 layer, saved per account as PNG data + const layer = document.createElement('canvas'); + layer.width = 512; layer.height = 256; + const paintObj = () => ({ body: save.paint.body, accent: save.paint.accent, layer, drawn: painter.isOpen || !!save.paint.drawn }); + const painter = RC.Painter({ + t, layer, view, sfx: SFX, getPaint: paintObj, + onLive: () => view.setPaint(paintObj()), + onDone: () => { + const art = painter.hasArt(); + save.paint.decal = art ? layer.toDataURL('image/png') : null; save.paint.drawn = art; + persist(); view.showGarage(save.build, paintObj()); + }, + onCancel: () => view.showGarage(save.build, paintObj()), + }); + $('bPaint').onclick = () => { SFX.click(); painter.open(); view.showGarage(save.build, paintObj()); }; + // drag on the robot turns it + let drag = null; + $('gl').addEventListener('pointerdown', e => { if (mode === 'garage') { drag = e.clientX; $('gl').setPointerCapture(e.pointerId); } }); + $('gl').addEventListener('pointermove', e => { if (drag != null) { view.turn(e.clientX - drag); drag = e.clientX; } }); + $('gl').addEventListener('pointerup', () => { drag = null; }); + // ---------------------------------------------------------------- state - let mode = 'menu'; // menu | garage | league | fight | pause | result + let mode = 'intro'; // intro | title | account | garage | league | fight | pause | result let F = null; // current fight const show = (id, on) => $(id).classList.toggle('hide', !on); const overlay = $('overlay'); - function card(html) { overlay.innerHTML = `
${html}
`; overlay.classList.remove('hide'); } - function hideOverlay() { overlay.classList.add('hide'); overlay.innerHTML = ''; } + function card(html, opt = {}) { + overlay.innerHTML = `
${html}
`; + overlay.classList.remove('hide'); overlay.classList.toggle('clear', !!opt.clear); + 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 = ''; } 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 : ''); + const playerName = () => (accounts.current && !accounts.current.guest ? accounts.current.name : save ? save.robotName : ''); function hud() { - $('hMoney').textContent = Kit.fmt(save.money); - $('hFame').textContent = Kit.fmt(save.fame); - $('hLeague').textContent = t('league_chip', { s: save.season, n: save.beaten, m: RC.LEAGUE.length }); + $('hMoney').textContent = save ? Kit.fmt(save.money) : '–'; + $('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 = accounts.current ? (accounts.current.guest ? '👤 ' + t('guest') : '👤 ' + accounts.current.name) : '👤 –'; $('bMute').textContent = audio.muted ? t('sound_off') : t('sound_on'); } - function garageTitle() { - $('gName').textContent = save.robotName; - $('gSub').textContent = weaponName(save.build); - } function setScreen(m) { + if (m !== 'garage' && painter.isOpen) painter.close(); mode = m; document.body.classList.toggle('fighting', m === 'fight' || m === 'pause'); - show('garage', m === 'garage'); - show('gTitle', m === 'garage'); + show('shop', m === 'garage'); show('fightHud', m === 'fight' || m === 'pause' || m === 'result'); + backdrop(m === 'garage' ? 'bg_workshop.jpg' : null); } - // ---------------------------------------------------------------- menu - function boardHtml() { return scores.enabled ? `

${t('ranking')}

  1. ${t('loading')}
` : ''; } + // ---------------------------------------------------------------- intro + title + let introCue = 0; + function startIntro() { + setScreen('intro'); + hideOverlay(); + if (!view) { showTitle(); return; } + const a = RC.LEAGUE[7], b = RC.LEAGUE[4]; + view.showIntro([a.build, b.build], [a.paint, b.paint]); + introCue = 0; + audio.music('music_title'); + if (!settings.intro) view.skipIntro(); + } + function skipIntro() { if (view) view.skipIntro(); } + stageClick(() => { if (mode === 'intro') skipIntro(); }); + function stageClick(fn) { $('stage').addEventListener('pointerdown', fn); } + function introTick() { + if (mode !== 'intro' || !view) return; + const it = view.introTime; + for (const [at, f] of [[1.2, SFX.clunk], [1.5, SFX.clunk], [1.62, SFX.clunk], [4.25, SFX.clunk], [4.6, SFX.clunk]]) { + if (introCue < at && it >= at) f(); + } + introCue = it; + if (it >= RC.INTRO_END) showTitle(); + } + + function showTitle() { + setScreen('title'); + audio.music('music_title'); + const acc = accounts.current && !accounts.current.guest ? accounts.current : null; + const btns = acc + ? `` + : ``; + overlay.innerHTML = `
ROBOT CLASH
${t('menu_text')}
+
${btns}
+
+ ${scores.enabled ? `` : ''}
+

${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()); + on('bSwitch', () => { accounts.logout(); hud(); showLogin(); }); + on('bLogin', () => showLogin()); + on('bReg', () => showRegister()); + on('bGuest', () => { accounts.guest(); enterAccount(); }); + on('bSet', () => showSettings(showTitle)); + on('bHelp', () => showHelp(showTitle)); + on('bLang', () => L.next()); + on('bRank', () => showRanking(showTitle)); + hud(); + } + + // ---------------------------------------------------------------- accounts + function showLogin(errKey) { + setScreen('account'); + const profs = accounts.list(); + card(`

${t('login')}

+ ${profs.length ? `

${t('local_profiles')}

${profs.map(p => ``).join('')}
` : ''} +
+ +
+
${errKey ? t(errKey) : ''}
+
+

${t('no_account')}

+

${t('local_note')}

`, { bg: 'bg_title.jpg' }); + overlay.querySelectorAll('.profiles button').forEach(b => { b.onclick = () => { $('fName').value = b.dataset.n; $('fPass').focus(); }; }); + $('bBack').onclick = () => { SFX.click(); showTitle(); }; + $('bToReg').onclick = () => { SFX.click(); showRegister(); }; + $('bGo').onclick = async () => { + const r = await accounts.login($('fName').value, $('fPass').value, $('fRem').checked); + if (!r.ok) { SFX.deny(); $('fErr').textContent = t('e_' + r.error); return; } + SFX.click(); enterAccount(); + }; + formKeys(); + setTimeout(() => $(profs.length ? 'fPass' : 'fName').focus(), 50); + } + function showRegister() { + setScreen('account'); + card(`

${t('register')}

${t('register_text')}

+
+ +
+
+
+

${t('local_note')}

`, { bg: 'bg_title.jpg' }); + $('bBack').onclick = () => { SFX.click(); showTitle(); }; + $('bGo').onclick = async () => { + if ($('fPass').value !== $('fPass2').value) { SFX.deny(); $('fErr').textContent = t('e_pass_match'); return; } + const r = await accounts.register($('fName').value, $('fPass').value); + if (!r.ok) { SFX.deny(); $('fErr').textContent = t('e_' + r.error); return; } + SFX.buy(); enterAccount(true); + }; + formKeys(); + setTimeout(() => $('fName').focus(), 50); + } + // Enter in a form = primary button; typing never reaches the game keys + function formKeys() { + overlay.querySelectorAll('input').forEach(el => el.addEventListener('keydown', e => { + e.stopPropagation(); + if (e.key === 'Enter') { const b = overlay.querySelector('button.primary'); if (b) b.click(); } + })); + } + + function enterAccount(fresh) { + slot = Kit.saveSlot(accounts.saveKey(), newSave); + save = slot.load(); + repairSave(); + RC.layerFromData(layer, save.paint.decal, () => { if (mode === 'garage') view.showGarage(save.build, paintObj()); }); + if (fresh && accounts.current && !accounts.current.guest) save.robotName = accounts.current.name.slice(0, 18); + persist(); + hud(); + shop.reset(); + if (!save.tutorialSeen) { save.tutorialSeen = true; persist(); showHelp(openGarage); } else openGarage(); + } + // saves from older versions: missing parts, invalid ids + 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]); + } + 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.beaten = Kit.clamp(save.beaten | 0, 0, RC.LEAGUE.length - 1); + } + function logout() { persist(); accounts.logout(); save = null; slot = null; F = null; hud(); startIntroOrTitle(); } + function startIntroOrTitle() { if (view) { const a = RC.LEAGUE[7], b = RC.LEAGUE[4]; view.showIntro([a.build, b.build], [a.paint, b.paint]); view.skipIntro(); } showTitle(); } + $('hUser').onclick = () => { + if (!accounts.current || mode === 'fight' || mode === 'pause') return; + SFX.click(); + const back = currentBack(); + card(`

${t('account')}

${accounts.current.guest ? t('guest_text') : t('logged_in_as', { name: esc(accounts.current.name) })}

+
`); + $('bOut').onclick = () => { SFX.click(); logout(); }; + $('bBack').onclick = () => { SFX.click(); back(); }; + }; + function currentBack() { return mode === 'garage' ? openGarage : mode === 'league' ? showLeague : mode === 'result' ? openGarage : mode === 'title' ? showTitle : save ? openGarage : showTitle; } + + // ---------------------------------------------------------------- settings / help / ranking + function showSettings(back) { + const prev = mode; + const seg = (id, val, opts) => `
${opts.map(([v, label]) => ``).join('')}
`; + card(`

${t('settings')}

+ ${t('s_lang')}${seg('sLang', L.lang, L.langs.map(l => [l, window.LANG[l].lang_self]))} + ${t('s_music')} + ${t('s_sfx')} + ${t('s_mute')}${seg('sMute', audio.muted ? '1' : '0', [['0', t('on')], ['1', t('off')]])} + ${t('s_gfx')}${seg('sGfx', settings.gfx, [['low', t('gfx_low')], ['medium', t('gfx_medium')], ['high', t('gfx_high')]])} + ${t('s_intro')}${seg('sIntro', settings.intro ? '1' : '0', [['1', t('on')], ['0', t('off')]])} + ${t('s_screen')}
+
+

${t('s_controls')}

${keysHtml()} + ${save ? `

${t('s_career')}

` : ''} +
`, { wide: true, clear: prev === 'title' || prev === 'intro' }); + const segOn = (id, f) => $(id).querySelectorAll('button').forEach(b => { b.onclick = () => { SFX.click(); f(b.dataset.v); $(id).querySelectorAll('button').forEach(x => x.classList.toggle('on', x === b)); }; }); + segOn('sLang', v => { L.set(v); showSettings(back); }); + segOn('sMute', v => { if ((v === '1') !== audio.muted) audio.toggleMute(); hud(); }); + segOn('sGfx', v => { settings.gfx = v; saveSettings(); if (view) view.setQuality(v); }); + segOn('sIntro', v => { settings.intro = v === '1'; saveSettings(); }); + $('sMusic').oninput = e => audio.setVolume(+e.target.value, audio.sfxVol); + $('sSfx').oninput = e => audio.setVolume(audio.musicVol, +e.target.value); + $('sSfx').onchange = () => SFX.click(); + $('sFull').onclick = () => { SFX.click(); Kit.host.fullscreen(); }; + if ($('sReset')) $('sReset').onclick = () => { SFX.click(); confirmReset(() => showSettings(back)); }; + $('bBack').onclick = () => { SFX.click(); back(); }; + } + function keysHtml() { + return `
W A S D / ↑ ← ↓ →${t('key_drive')}${t('key_space')}${t('key_weapon')} + Shift / E${t('key_tower')}P / Esc${t('pause')}M${t('sound_on')} / ${t('sound_off')} + ${t('key_pad')}${t('key_pad_text')}
`; + } + function showHelp(back) { + card(`

${t('how_to')}

${t('help_text')}

${keysHtml()} +

${t('help_arena')}

`, { bg: 'bg_title.jpg' }); + $('bOk').onclick = () => { SFX.click(); back(); }; + } + function showRanking(back) { + card(`

🏆 ${t('ranking')}

  1. ${t('loading')}
`, { bg: 'bg_title.jpg' }); + $('bBack').onclick = () => { SFX.click(); back(); }; + fillBoard(); + } + function confirmReset(back) { + card(`

${t('reset')}

${t('reset_text')}

`); + $('bNo').onclick = () => { SFX.click(); back(); }; + $('bYes').onclick = () => { Object.assign(save, newSave()); RC.layerFromData(layer, null); save.tutorialSeen = true; persist(); hud(); shop.reset(); SFX.click(); openGarage(); }; + } + $('bSettings').onclick = () => { + if (mode === 'fight') togglePause(); + if (mode === 'intro') skipIntro(); + SFX.click(); + const back = mode === 'pause' ? () => { mode = 'fight'; togglePause(); } : currentBack(); + showSettings(back); + }; + + function boardHtml() { return scores.enabled ? `

${t('ranking')}

  1. ${t('loading')}
` : ''; } async function fillBoard(myKey) { const el = $('board'); if (!el) return; @@ -145,77 +372,44 @@ } catch (e) { el.innerHTML = `
  • ${t('scores_offline')}
  • `; } } - function showMenu() { - setScreen('menu'); - F = null; - if (view) view.showGarage(save.build, save.paint); - audio.music('music_garage'); - if (!view) { card(`

    Robot Clash

    ${t('no_webgl')}

    ${CREDITS}

    `); return; } - const nameField = scores.enabled ? `
    ` : ''; - card(`

    ROBOT CLASH

    ${t('menu_text')}

    - ${nameField} -
    -
    - ${boardHtml()}

    ${CREDITS}

    `); - $('bLang').onclick = () => { SFX.click(); L.next(); }; - $('bHelp').onclick = () => { SFX.click(); showHelp(showMenu); }; - $('bReset').onclick = () => { SFX.click(); confirmReset(); }; - const name = $('name'), start = $('bStart'); - if (name) { - const check = () => { const n = Kit.cleanName(name.value); start.disabled = !n || Kit.badName(n); }; - name.addEventListener('input', check); check(); - name.addEventListener('keydown', e => { if (e.key === 'Enter' && !start.disabled) start.click(); }); - } - start.onclick = () => { - if (name) { save.name = Kit.cleanName(name.value); persist(); } - SFX.click(); - if (!save.tutorialSeen) { save.tutorialSeen = true; persist(); showHelp(openGarage); } else openGarage(); - }; - fillBoard(); - } - - function showHelp(back) { - card(`

    ${t('how_to')}

    ${t('help_text')}

    -
    W A S D / ↑ ← ↓ →${t('key_drive')}${t('key_space')}${t('key_weapon')} - Shift / E${t('key_tower')}P / Esc${t('pause')}${t('key_pad')}${t('key_pad_text')}
    -

    ${t('help_arena')}

    `); - $('bOk').onclick = () => { SFX.click(); back(); }; - } - function confirmReset() { - card(`

    ${t('reset')}

    ${t('reset_text')}

    `); - $('bNo').onclick = () => { SFX.click(); showMenu(); }; - $('bYes').onclick = () => { resetSave(); persist(); hud(); SFX.click(); showMenu(); }; - } - function resetSave() { - save.money = 400; save.fame = 0; save.best = 0; save.season = 1; save.beaten = 0; save.wins = 0; save.losses = 0; save.games = 0; - save.owned = Object.values(RC.STARTER).filter(Boolean); save.build = Object.assign({}, RC.STARTER); - save.paint = { body: 0xff7a1a, accent: 0x15171b }; save.robotName = 'Clank'; save.tutorialSeen = false; - } - - // ---------------------------------------------------------------- workshop + league + // ---------------------------------------------------------------- shop + league function openGarage() { hideOverlay(); setScreen('garage'); - view.showGarage(save.build, save.paint); + view.showGarage(save.build, paintObj()); audio.music('music_garage'); - garage.render(); garageTitle(); hud(); + shop.render(); hud(); } - $('bGMenu').onclick = () => { SFX.click(); showMenu(); }; + $('bGMenu').onclick = () => { SFX.click(); persist(); startIntroOrTitle(); }; $('bTrain').onclick = () => { SFX.click(); startFight(RC.DUMMY, true); }; $('bLeague').onclick = () => { SFX.click(); showLeague(); }; function showLeague() { setScreen('league'); - const rows = RC.LEAGUE.map((o, i) => { + const cards = RC.LEAGUE.map((o, i) => { const cls = i < save.beaten ? 'done' : i === save.beaten ? 'next' : 'locked'; - return `
  • ${i < save.beaten ? '✓' : i + 1}${o.name}
    ${t('style_' + o.style)}
    - ${weaponName(o.build)}${Kit.fmt(Math.round(o.prize * seasonMul()))}
  • `; + return `
    ${RC.pic('opp_' + o.id, '🤖')}
    ${i + 1}. ${o.name}
    +
    ${i <= save.beaten ? t('style_' + o.style) : '???'}
    +
    ${RC.pic('ico_credits', '🪙')}${Kit.fmt(Math.round(o.prize * seasonMul()))}
    `; }).join(''); - card(`

    ${t('league_title', { s: save.season })}

    ${t('league_text')}

      ${rows}
    -
    `); - $('bFight').onclick = () => { SFX.click(); startFight(RC.LEAGUE[save.beaten], false); }; + card(`

    ${t('league_title', { s: save.season })}

    ${t('league_text')}

    ${cards}
    +
    `, + { wide: true, bg: 'bg_title.jpg' }); + overlay.querySelectorAll('.opp.next').forEach(el => { el.style.cursor = 'pointer'; el.onclick = () => { SFX.click(); showVs(RC.LEAGUE[save.beaten]); }; }); + $('bFight').onclick = () => { SFX.click(); showVs(RC.LEAGUE[save.beaten]); }; $('bBack').onclick = () => { SFX.click(); openGarage(); }; } + function showVs(opp) { + const me = RC.stats(save.build), en = RC.stats(opp.build); + const line = s => `${Math.round(s.hp)} ${t('m_hp')} · ${Math.round(s.reduce * 100)}% ${t('m_armour')} · ${s.top.toFixed(1)} m/s`; + card(`
    ${RC.pic('icon', '🤖')}
    ${esc(save.robotName)}
    ${weaponName(save.build)}
    ${line(me)}
    +
    VS
    +
    ${RC.pic('opp_' + opp.id, '🤖')}
    ${opp.name}
    ${weaponName(opp.build)}
    ${line(en)}
    +

    ${t('style_' + opp.style)}

    +
    `, { wide: true, bg: 'bg_title.jpg' }); + $('bBack').onclick = () => { SFX.click(); showLeague(); }; + $('bGo').onclick = () => { SFX.click(); startFight(opp, false); }; + } // ---------------------------------------------------------------- fight function startFight(opp, training) { @@ -236,7 +430,7 @@ s.events.length = 0; } } - view.showArena(s, [save.build, opp.build], [save.paint, opp.paint]); + view.showArena(s, [save.build, opp.build], [paintObj(), opp.paint]); $('fN0').textContent = save.robotName; $('fN1').textContent = opp.name; $('fW0').textContent = weaponName(save.build); $('fW1').textContent = weaponName(opp.build); $('fH0').style.background = hex(save.paint.body); $('fH1').style.background = hex(opp.paint.body); @@ -273,6 +467,7 @@ function update(dt) { fx.update(dt); + introTick(); if (mode !== 'fight' || !F) return; if (F.count > 0) { F.count -= dt; @@ -363,12 +558,13 @@ ${champion ? `

    ${t('champion_title', { s: save.season - 1 })}

    ${t('champion_text')}

    ` : ''}
    ${stats}${rows}${!F.training && fame ? `${t('hud_fame')}+${Kit.fmt(fame)}` : ''}
    ${F.training ? `

    ${t('training_note')}

    ` : ''} -
    ${!F.training && !won ? `` : ''}
    ${boardHtml()}`); +
    ${!F.training && !won ? `` : ''}
    ${boardHtml()}`, + { bg: won ? 'bg_win.jpg' : 'bg_lose.jpg' }); $('bGarage').onclick = () => { SFX.click(); openGarage(); }; if ($('bRetry')) $('bRetry').onclick = () => { SFX.click(); startFight(opp, false); }; if (!F.training && save.fame > save.best) { save.best = save.fame; persist(); - scores.submit({ name: save.name || save.robotName, score: save.fame, level: save.season }).then(fillBoard); + scores.submit({ name: playerName(), score: save.fame, level: save.season }).then(fillBoard); } else fillBoard(); } @@ -378,6 +574,20 @@ 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 (mode === 'intro' && view) { + const it = view.introTime; + if (it > 5.6) { + const k = Math.min(1, (it - 5.6) / 0.8); + ctx.save(); ctx.globalAlpha = k; ctx.translate(W / 2, H * 0.4); ctx.scale(1.4 - 0.4 * k, 1.4 - 0.4 * k); + ctx.font = '84px "Russo One", "Segoe UI Black", "Arial Black", Impact, sans-serif'; + ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; + ctx.lineWidth = 10; ctx.strokeStyle = '#000'; ctx.strokeText('ROBOT CLASH', 0, 0); + ctx.fillStyle = '#ff7a1a'; ctx.fillText('ROBOT CLASH', 0, 0); + ctx.restore(); + } + ctx.font = '12px "Segoe UI", sans-serif'; ctx.textAlign = 'right'; ctx.fillStyle = 'rgba(255,255,255,.55)'; + ctx.fillText(t('skip_intro'), W - 14, H - 12); + } if (F && (mode === 'fight' || mode === 'pause' || mode === 'result')) { fightHud(); fx.apply(ctx); fx.draw(ctx); ctx.restore(); @@ -405,8 +615,9 @@ function togglePause() { if (mode === 'fight') { mode = 'pause'; loop.pause(); - card(`

    ${t('pause')}

    `); + card(`

    ${t('pause')}

    `); $('bGo').onclick = togglePause; + $('bSet2').onclick = () => { SFX.click(); showSettings(() => { mode = 'fight'; togglePause(); }); }; $('bQuit').onclick = () => { mode = 'fight'; loop.resume(); hideOverlay(); if (F && !F.s.result) { F.s.robots[0].hp = 0; F.s.robots[0].dead = true; F.s.result = { winner: 1, reason: 'ko' }; F.s.endIn = 0; } @@ -416,25 +627,33 @@ function toggleMute() { audio.toggleMute(); hud(); } $('bMute').onclick = toggleMute; $('bPause').onclick = togglePause; - $('bLangTop').onclick = () => { SFX.click(); L.next(); }; addEventListener('blur', () => { if (mode === 'fight') togglePause(); }); // language switch: static texts update themselves (data-i18n), dynamic screens are drawn again L.onChange(() => { hud(); - if (mode === 'menu') showMenu(); - else if (mode === 'garage') { garage.render(); garageTitle(); } + if (mode === 'title') showTitle(); + else if (mode === 'garage') shop.render(); else if (mode === 'league') showLeague(); if (F) { $('fW0').textContent = weaponName(save.build); $('fW1').textContent = weaponName(F.opp.build); } }); - if (slot.failed()) console.warn('save failed'); - // repair saves from older versions: missing parts, invalid ids - 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]); } - 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.beaten = Kit.clamp(save.beaten | 0, 0, RC.LEAGUE.length - 1); + // ---------------------------------------------------------------- start + accounts.resume(); hud(); - // dev: index.html?play = straight into the workshop, ?fight = training fight - if (view && DEV.has('fight')) startFight(RC.LEAGUE[Kit.clamp(+DEV.get('fight') || 0, 0, 7)], true); - else if (view && DEV.has('play')) openGarage(); else showMenu(); + if (!view) { + card(`

    Robot Clash

    ${t('no_webgl')}

    ${CREDITS}

    `); + } else if (DEV.has('fight') || DEV.has('play')) { + // dev: ?play = straight into the shop, ?fight=N = training fight against league robot N + if (!accounts.current) accounts.guest(); + slot = Kit.saveSlot(accounts.saveKey(), newSave); save = slot.load(); repairSave(); hud(); + RC.layerFromData(layer, save.paint.decal, () => { if (mode === 'garage') view.showGarage(save.build, paintObj()); }); + if (DEV.has('fight')) startFight(RC.LEAGUE[Kit.clamp(+DEV.get('fight') || 0, 0, 7)], true); else openGarage(); + if (DEV.has('paint')) { // dev: open the paint booth with a test drawing + const c = layer.getContext('2d'); + c.fillStyle = '#15171b'; c.fillRect(0, 100, 256, 56); c.fillStyle = '#f2c230'; c.font = 'bold 70px sans-serif'; c.fillText('★ 7', 300, 170); + c.strokeStyle = '#00e5ff'; c.lineWidth = 14; c.beginPath(); c.moveTo(270, 220); c.lineTo(500, 200); c.stroke(); + painter.open(); view.showGarage(save.build, paintObj()); + } + } else if (DEV.has('title')) startIntroOrTitle(); + else startIntro(); })(); diff --git a/game/garage.js b/game/garage.js deleted file mode 100644 index ab9edeb..0000000 --- a/game/garage.js +++ /dev/null @@ -1,95 +0,0 @@ -/* Robot Clash - workshop panel (#garage in index.html): slot tabs, buy / equip / sell parts, - weight + power meters, paint. Needs parts.js, robot.js, kit-core.js. - - const gar = RC.Garage({ t, getSave, onBuild(), onPaint(), onSave(), sfx: { click, buy, deny } }); - gar.render() redraw everything (after language switch, money change) - save fields used: money, owned [ids], build {slot: id|null}, paint {body, accent}, robotName */ -(function (root) { - 'use strict'; - const RC = root.RC, $ = Kit.$; - RC.PAINTS = [0xd8452b, 0xff7a1a, 0xf2c230, 0x5fae3b, 0x2e9c8f, 0x2a6fd8, 0x6a3fb0, 0xd94f9a, 0xe6e6e6, 0x8c8c8c, 0x3a3d44, 0x15171b]; - const hex = n => '#' + n.toString(16).padStart(6, '0'); - const SELL = 0.5; - - RC.Garage = function (opt) { - const t = opt.t; - let slot = 'weapon'; - - function statLine(p) { - const s = []; - if (p.hp) s.push(t('st_hp', { n: p.hp * RC.HP_SCALE })); - if (p.slot === 'motor') s.push(t('st_speed', { n: p.speed.toFixed(1) }), t('st_force', { n: p.force })); - if (p.slot === 'wheels') s.push(t('st_grip', { n: p.grip }), t('st_turn', { n: p.turn }), p.invertible ? t('st_invert') : ''); - if (p.slot === 'armour') s.push(t('st_reduce', { n: Math.round(p.reduce * 100) })); - if (p.dmg) s.push(t('st_dmg', { n: p.dmg })); - if (p.dps) s.push(t('st_dps', { n: p.dps })); - if (p.range) s.push(t('st_range', { n: p.range })); - s.push(t('st_weight', { n: p.weight })); - if (p.slot === 'battery') s.push(t('st_supply', { n: p.power })); - else if (p.power) s.push(t('st_power', { n: p.power })); - return s.filter(Boolean).join(' · '); - } - - function render() { - const save = opt.getSave(), b = save.build, v = RC.validate(b); - // tabs - $('tabs').innerHTML = RC.SLOTS.map(sl => ``).join(''); - $('tabs').querySelectorAll('button').forEach(el => { el.onclick = () => { slot = el.dataset.slot; opt.sfx.click(); render(); }; }); - // parts of this slot - const rows = []; - if (!RC.REQUIRED[slot]) rows.push(`
    ${t('none')}${b[slot] ? `` : `${t('equipped')}`}${t('none_' + slot)}
    `); - for (const p of RC.partsFor(slot)) { - const own = save.owned.includes(p.id), eq = b[slot] === p.id; - let btns; - if (eq) btns = `${t('equipped')}`; - else if (own) btns = ``; - else btns = ``; - rows.push(`
    ${p.name}${btns}${t('pd_' + p.id)}${statLine(p)}
    `); - } - $('parts').innerHTML = rows.join(''); - $('parts').querySelectorAll('button[data-act]').forEach(el => { el.onclick = () => act(el.dataset.act, el.dataset.id || null); }); - - // meters - const st = RC.stats(b); - const bar = (val, max, over) => `
    `; - $('meters').innerHTML = [ - [t('m_weight'), bar(v.weight, RC.WEIGHT_LIMIT, v.weight > RC.WEIGHT_LIMIT), `${v.weight}/${RC.WEIGHT_LIMIT} kg`], - [t('m_power'), bar(v.power, Math.max(1, v.supply), v.power > v.supply), `${v.power}/${v.supply}`], - [t('m_hp'), bar(st.hp, 175 * RC.HP_SCALE), Math.round(st.hp)], - [t('m_armour'), bar(st.reduce, 0.4), Math.round(st.reduce * 100) + '%'], - [t('m_speed'), bar(st.top, 7), st.top.toFixed(1) + ' m/s'], - [t('m_accel'), bar(st.accel, 30), st.accel.toFixed(1)], - [t('m_turn'), bar(st.turn, 3), st.turn.toFixed(1)], - ].map(r => `${r[0]}${r[1]}${r[2]}`).join(''); - - // paint - for (const [id, key] of [['paintBody', 'body'], ['paintAccent', 'accent']]) { - $(id).innerHTML = `${t('paint_' + key)}` + RC.PAINTS.map(c => ``).join(''); - $(id).querySelectorAll('.sw').forEach(el => { el.onclick = () => { save.paint[key] = +el.dataset.c; 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; - } - - function act(what, id) { - const save = opt.getSave(), p = id ? RC.PARTS[id] : null; - if (what === 'buy' && p && save.money >= p.cost && !save.owned.includes(id)) { - save.money -= p.cost; save.owned.push(id); save.build[slot] = id; opt.sfx.buy(); - } else if (what === 'eq') { - save.build[slot] = id; opt.sfx.click(); - } else if (what === 'sell' && p && save.build[slot] !== id) { - save.owned = save.owned.filter(x => x !== id); save.money += Math.round(p.cost * SELL); opt.sfx.buy(); - } else { opt.sfx.deny(); return; } - opt.onSave(); opt.onBuild(); render(); - } - - $('rname').addEventListener('input', () => { - const s = opt.getSave(), n = Kit.cleanName($('rname').value).slice(0, 18); - if (n && !Kit.badName(n)) { s.robotName = n; opt.onSave(); opt.onPaint(); } - }); - $('rname').addEventListener('keydown', e => { if (e.key === 'Enter') $('rname').blur(); e.stopPropagation(); }); - return { render, get slot() { return slot; } }; - }; -})(window); diff --git a/game/index.html b/game/index.html index 5a32a47..ff8220c 100644 --- a/game/index.html +++ b/game/index.html @@ -8,7 +8,7 @@