wobblyhead hg > minor_monsters
diff game/js/game.js @ 24:3f2811aebb3d 0.9.0
splash screen buttons, help button, info screen
| author | ark |
|---|---|
| date | 2026-10-20 15:58 +0200 |
| parents | 2f555a54c332 |
| children | 75deda08db90 |
line wrap: on
line diff
--- a/game/js/game.js Tue Oct 20 12:04:42 2026 +0200 +++ b/game/js/game.js Tue Oct 20 15:58:17 2026 +0200 @@ -22,6 +22,7 @@ this.projectiles = []; this.flights = []; // coins flying to the counter this.puffs = []; // death puffs, {x, y, boss, t} + this.freezes = []; // t2 freeze splashes, {x, y, r, t} this.waves = new MM.Waves(mapIndex, MM.util.clamp(firstWave - 1, 0, mc.waves.length - 1), this.random); this.time = 0; @@ -30,6 +31,8 @@ this.speedIndex = 0; this.result = null; // "won" or "lost" this.splash = false; // splash screen shown over the paused map + this.help = false; // help popup shown over everything + this.helpResume = false; // the game ran when the help popup opened // player selection: shop tower type, its snapped preview, a built tower this.shop = null; this.preview = null; @@ -57,6 +60,19 @@ } }; + // the help popup pauses the game while it is shown. closing it lets a + // game that was running before go on + Game.prototype.openHelp = function () { + this.help = true; + this.helpResume = !this.paused; + if (!this.paused) this.togglePause(); + }; + + Game.prototype.closeHelp = function () { + this.help = false; + if (this.helpResume) this.togglePause(); + }; + Game.prototype.canAfford = function (cost) { return dbg.unlimited_coins || this.coins >= cost; }; @@ -85,6 +101,8 @@ this.flights.forEach(function (f) { f.t += dt; }); this.puffs.forEach(function (p) { p.t += dt; }); this.puffs = this.puffs.filter(function (p) { return p.t < cfg.animation.death_puff; }); + this.freezes.forEach(function (f) { f.t += dt; }); + this.freezes = this.freezes.filter(function (f) { return f.t < cfg.animation.freeze_splash; }); var flying = this.flights.length; this.flights = this.flights.filter(function (f) { return f.t < cfg.coins.flight_time; }); if (this.flights.length < flying) MM.audio.play("coins_arrive"); @@ -101,6 +119,7 @@ if (this.result) { this.flights = []; this.puffs = []; + this.freezes = []; } }; @@ -113,6 +132,17 @@ } }; + // a freeze splash of radius r at x, y: slows every monster whose hit + // area it touches to factor of its speed for time seconds + Game.prototype.freeze = function (x, y, r, factor, time) { + this.freezes.push({ x: x, y: y, r: r, t: 0 }); + this.monsters.forEach(function (m) { + if (m.alive && Math.hypot(m.x - x, m.y - y) <= r + m.hitRadius) { + MM.monster.slow(m, factor, time); + } + }); + }; + Game.prototype.damage = function (m, amount) { if (!m.alive) return; m.hp -= amount;
