comparison game/js/main.js @ 6:910b26feca76

full game flow
author ark
date 2026-10-19 01:05 +0200
parents 2d46729a022e
children 2c4fed8baed9
comparison
equal deleted inserted replaced
5:67bf3c505145 6:910b26feca76
15 var ctx = canvas.getContext("2d"); 15 var ctx = canvas.getContext("2d");
16 var game = null; 16 var game = null;
17 var L = null; 17 var L = null;
18 var view = { dpr: 1, now: 0, refused: null, stats: { ms: 0 } }; 18 var view = { dpr: 1, now: 0, refused: null, stats: { ms: 0 } };
19 19
20 function newGame() { 20 // the first map is the debug start map; only it starts at the debug
21 var m = MM.util.clamp(cfg.debug.start_map, 0, MM.maps.length - 1); 21 // start wave
22 var FIRST = MM.util.clamp(cfg.debug.start_map, 0, MM.maps.length - 1);
23
24 function startMap(m) {
22 var seed = cfg.debug.seed || (Math.random() * 4294967296) >>> 0; 25 var seed = cfg.debug.seed || (Math.random() * 4294967296) >>> 0;
23 game = new MM.Game(m, seed); 26 game = new MM.Game(m, seed, m === FIRST ? cfg.debug.start_wave : 1);
24 resize(); 27 resize();
28 }
29
30 // the splash screen over the paused first map. the pause does not count
31 // for the sell refund, as nothing can be bought on the splash screen.
32 function splash() {
33 startMap(FIRST);
34 game.splash = true;
35 game.paused = true;
36 }
37
38 function play() {
39 game.splash = false;
40 game.paused = false;
25 } 41 }
26 42
27 // canvas resolution follows the device pixel ratio 43 // canvas resolution follows the device pixel ratio
28 function resize() { 44 function resize() {
29 var w = canvas.clientWidth, h = canvas.clientHeight; 45 var w = canvas.clientWidth, h = canvas.clientHeight;
71 MM.input.attach({ 87 MM.input.attach({
72 canvas: canvas, 88 canvas: canvas,
73 view: view, 89 view: view,
74 game: function () { return game; }, 90 game: function () { return game; },
75 layout: function () { return L; }, 91 layout: function () { return L; },
76 restart: newGame 92 play: play,
93 next: function () { startMap(game.map.index + 1); },
94 retry: function () { startMap(FIRST); },
95 restart: splash
77 }); 96 });
78 MM.assets.load(function (failed) { 97 MM.assets.load(function (failed) {
79 if (failed.length) console.error("images not loaded:", failed); 98 if (failed.length) console.error("images not loaded:", failed);
80 newGame(); 99 splash();
81 requestAnimationFrame(frame); 100 requestAnimationFrame(frame);
82 }); 101 });
83 })(); 102 })();