comparison game/js/game.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 3f2811aebb3d
children 85d23328a215
comparison
equal deleted inserted replaced
26:28e1fc486be5 27:75deda08db90
5 5
6 MM.Game = (function () { 6 MM.Game = (function () {
7 "use strict"; 7 "use strict";
8 8
9 var cfg = MM.config; 9 var cfg = MM.config;
10 var dbg = cfg.debug;
11 10
12 // firstWave counts from 1 11 // firstWave counts from 1
13 function Game(mapIndex, seed, firstWave) { 12 function Game(mapIndex, seed, firstWave) {
14 var mc = cfg.maps[mapIndex]; 13 var mc = cfg.maps[mapIndex];
15 this.map = new MM.GameMap(mapIndex); 14 this.map = new MM.GameMap(mapIndex);
16 this.seed = seed; 15 this.seed = seed;
17 this.random = MM.util.rng(seed); 16 this.random = MM.util.rng(seed);
18 this.coins = dbg.start_coins >= 0 ? dbg.start_coins : mc.starting_coins; 17 this.coins = mc.starting_coins;
19 this.hearts = cfg.hearts.per_map; 18 this.hearts = cfg.hearts.per_map;
20 this.monsters = []; 19 this.monsters = [];
21 this.towers = []; 20 this.towers = [];
22 this.projectiles = []; 21 this.projectiles = [];
23 this.flights = []; // coins flying to the counter 22 this.flights = []; // coins flying to the counter
25 this.freezes = []; // t2 freeze splashes, {x, y, r, t} 24 this.freezes = []; // t2 freeze splashes, {x, y, r, t}
26 this.waves = new MM.Waves(mapIndex, MM.util.clamp(firstWave - 1, 0, mc.waves.length - 1), 25 this.waves = new MM.Waves(mapIndex, MM.util.clamp(firstWave - 1, 0, mc.waves.length - 1),
27 this.random); 26 this.random);
28 this.time = 0; 27 this.time = 0;
29 this.paused = false; 28 this.paused = false;
30 this.speeds = cfg.controls.speeds.concat(dbg.extra_speeds); 29 this.speeds = cfg.controls.speeds;
31 this.speedIndex = 0; 30 this.speedIndex = 0;
32 this.result = null; // "won" or "lost" 31 this.result = null; // "won" or "lost"
33 this.splash = false; // splash screen shown over the paused map 32 this.splash = false; // splash screen shown over the paused map
34 this.help = false; // help popup shown over everything 33 this.help = false; // help popup shown over everything
35 this.helpResume = false; // the game ran when the help popup opened 34 this.helpResume = false; // the game ran when the help popup opened
72 this.help = false; 71 this.help = false;
73 if (this.helpResume) this.togglePause(); 72 if (this.helpResume) this.togglePause();
74 }; 73 };
75 74
76 Game.prototype.canAfford = function (cost) { 75 Game.prototype.canAfford = function (cost) {
77 return dbg.unlimited_coins || this.coins >= cost; 76 return this.coins >= cost;
78 }; 77 };
79 78
80 Game.prototype.pay = function (cost) { 79 Game.prototype.pay = function (cost) {
81 if (!dbg.unlimited_coins) this.coins -= cost; 80 this.coins -= cost;
82 }; 81 };
83 82
84 // one simulation step of dt seconds 83 // one simulation step of dt seconds
85 Game.prototype.step = function (dt) { 84 Game.prototype.step = function (dt) {
86 if (this.result) return; 85 if (this.result) return;
125 124
126 // a monster reached the exit 125 // a monster reached the exit
127 Game.prototype.escape = function (m) { 126 Game.prototype.escape = function (m) {
128 m.alive = false; 127 m.alive = false;
129 MM.audio.play(m.boss ? "boss_exit" : "monster_exit"); 128 MM.audio.play(m.boss ? "boss_exit" : "monster_exit");
130 if (!dbg.no_heart_loss) { 129 this.hearts = Math.max(0, this.hearts - (m.boss ? cfg.hearts.boss : cfg.hearts.monster));
131 this.hearts = Math.max(0, this.hearts - (m.boss ? cfg.hearts.boss : cfg.hearts.monster));
132 }
133 }; 130 };
134 131
135 // a freeze splash of radius r at x, y: slows every monster whose hit 132 // a freeze splash of radius r at x, y: slows every monster whose hit
136 // area it touches to factor of its speed for time seconds 133 // area it touches to factor of its speed for time seconds
137 Game.prototype.freeze = function (x, y, r, factor, time) { 134 Game.prototype.freeze = function (x, y, r, factor, time) {