comparison game/js/main.js @ 27:75deda08db90 0.9.1

game debug functions separated into own file; release build option, distribution script
author ark
date 2026-10-20 17:19 +0200
parents fe680946164b
children 85d23328a215
comparison
equal deleted inserted replaced
26:28e1fc486be5 27:75deda08db90
3 window.MM = window.MM || {}; 3 window.MM = window.MM || {};
4 4
5 (function () { 5 (function () {
6 "use strict"; 6 "use strict";
7 7
8 var cfg = MM.config;
9 var STEP = 1 / 60; 8 var STEP = 1 / 60;
10 // most simulation steps per frame and game speed step; the rest of a 9 // most simulation steps per frame and game speed step; the rest of a
11 // long frame is dropped, so the game slows down instead of freezing 10 // long frame is dropped, so the game slows down instead of freezing
12 var MAX_STEPS = 4; 11 var MAX_STEPS = 4;
13 12
14 var canvas = document.getElementById("game"); 13 var canvas = document.getElementById("game");
15 var ctx = canvas.getContext("2d"); 14 var ctx = canvas.getContext("2d");
16 var game = null; 15 var game = null;
17 var L = null; 16 var L = null;
18 var view = { dpr: 1, now: 0, refused: null, hover: null, stats: { ms: 0 } }; 17 var view = { dpr: 1, now: 0, refused: null, hover: null };
19 18
20 // the first map is the debug start map; only it starts at the debug 19 // the first map, the wave it starts at and the seed, 0 for a new seed
20 // per map. js/debug.js may set them; only the first map starts at the
21 // start wave 21 // start wave
22 var FIRST = MM.util.clamp(cfg.debug.start_map, 0, MM.maps.length - 1); 22 var start = MM.debug ? MM.debug.start : { map: 0, wave: 1, seed: 0 };
23 var FIRST = MM.util.clamp(start.map, 0, MM.maps.length - 1);
23 24
24 function startMap(m) { 25 function startMap(m) {
25 var seed = cfg.debug.seed || (Math.random() * 4294967296) >>> 0; 26 var seed = start.seed || (Math.random() * 4294967296) >>> 0;
26 game = new MM.Game(m, seed, m === FIRST ? cfg.debug.start_wave : 1); 27 game = new MM.Game(m, seed, m === FIRST ? start.wave : 1);
27 resize(); 28 resize();
28 } 29 }
29 30
30 // the splash screen over the paused first map 31 // the splash screen over the paused first map
31 function splash() { 32 function splash() {
75 ctx.fillRect(0, 0, canvas.width, canvas.height); 76 ctx.fillRect(0, 0, canvas.width, canvas.height);
76 MM.render.draw(ctx, game, L, view); 77 MM.render.draw(ctx, game, L, view);
77 MM.ui.draw(ctx, game, L, view); 78 MM.ui.draw(ctx, game, L, view);
78 MM.render.drawFlights(ctx, game, L, view); 79 MM.render.drawFlights(ctx, game, L, view);
79 80
80 view.stats.ms = view.stats.ms * 0.9 + (performance.now() - t0) * 0.1; 81 if (MM.debug) MM.debug.frameTime(performance.now() - t0);
81 requestAnimationFrame(frame); 82 requestAnimationFrame(frame);
82 } 83 }
83 84
84 window.addEventListener("resize", resize); 85 window.addEventListener("resize", resize);
85 MM.audio.init(); 86 MM.audio.init();