wobblyhead hg > minor_monsters
diff game/js/main.js @ 6:910b26feca76
full game flow
| author | ark |
|---|---|
| date | 2026-10-19 01:05 +0200 |
| parents | 2d46729a022e |
| children | 2c4fed8baed9 |
line wrap: on
line diff
--- a/game/js/main.js Sun Oct 18 22:50:24 2026 +0200 +++ b/game/js/main.js Mon Oct 19 01:05:29 2026 +0200 @@ -17,13 +17,29 @@ var L = null; var view = { dpr: 1, now: 0, refused: null, stats: { ms: 0 } }; - function newGame() { - var m = MM.util.clamp(cfg.debug.start_map, 0, MM.maps.length - 1); + // the first map is the debug start map; only it starts at the debug + // start wave + var FIRST = MM.util.clamp(cfg.debug.start_map, 0, MM.maps.length - 1); + + function startMap(m) { var seed = cfg.debug.seed || (Math.random() * 4294967296) >>> 0; - game = new MM.Game(m, seed); + game = new MM.Game(m, seed, m === FIRST ? cfg.debug.start_wave : 1); resize(); } + // the splash screen over the paused first map. the pause does not count + // for the sell refund, as nothing can be bought on the splash screen. + function splash() { + startMap(FIRST); + game.splash = true; + game.paused = true; + } + + function play() { + game.splash = false; + game.paused = false; + } + // canvas resolution follows the device pixel ratio function resize() { var w = canvas.clientWidth, h = canvas.clientHeight; @@ -73,11 +89,14 @@ view: view, game: function () { return game; }, layout: function () { return L; }, - restart: newGame + play: play, + next: function () { startMap(game.map.index + 1); }, + retry: function () { startMap(FIRST); }, + restart: splash }); MM.assets.load(function (failed) { if (failed.length) console.error("images not loaded:", failed); - newGame(); + splash(); requestAnimationFrame(frame); }); })();
