wobblyhead hg > minor_monsters
diff game/js/game.js @ 4:2d46729a022e
sound processing and in-game sounds
| author | ark |
|---|---|
| date | 2026-10-18 20:58 +0200 |
| parents | 5492efd60e2c |
| children | 910b26feca76 |
line wrap: on
line diff
--- a/game/js/game.js Sun Oct 18 20:09:40 2026 +0200 +++ b/game/js/game.js Sun Oct 18 20:58:33 2026 +0200 @@ -49,7 +49,9 @@ var self = this; this.time += dt; this.waves.update(dt, this.monsters.length, function (kind) { - self.monsters.push(MM.monster.create(self, kind)); + var m = MM.monster.create(self, kind); + self.monsters.push(m); + MM.audio.play(m.boss ? "boss_enter" : "monster_enter"); }); this.monsters.forEach(function (m) { if (m.alive && MM.monster.update(m, dt)) self.escape(m); @@ -59,12 +61,17 @@ this.monsters = this.monsters.filter(function (m) { return m.alive; }); this.projectiles = this.projectiles.filter(function (p) { return !p.done; }); this.flights.forEach(function (f) { f.t += dt; }); + 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"); + // the end sound waits for the last exit or death sound if (this.hearts <= 0) { this.result = "lost"; + MM.audio.play("map_lost", ["monster_exit", "boss_exit"]); } else if (this.waves.phase === "done" && this.monsters.length === 0) { this.result = "won"; + MM.audio.play("map_won", ["monster_die", "boss_die"]); } // the simulation stops here; the coins in flight are counted already if (this.result) this.flights = []; @@ -73,6 +80,7 @@ // a monster reached the exit Game.prototype.escape = function (m) { m.alive = false; + MM.audio.play(m.boss ? "boss_exit" : "monster_exit"); if (!dbg.no_heart_loss) { this.hearts = Math.max(0, this.hearts - (m.boss ? cfg.hearts.boss : cfg.hearts.monster)); } @@ -81,8 +89,12 @@ Game.prototype.damage = function (m, amount) { if (!m.alive) return; m.hp -= amount; - if (m.hp > 0) return; + if (m.hp > 0) { + MM.audio.play("monster_hit"); + return; + } m.alive = false; + MM.audio.play(m.boss ? "boss_die" : "monster_die"); // coins count at once; the flying coins only show it (balance.md) this.coins += m.coins; var n = Math.min(m.coins, cfg.coins.max_sprites); @@ -98,7 +110,9 @@ }; Game.prototype.startEarly = function () { - this.coins += this.waves.startEarly(); + var bonus = this.waves.startEarly(); + this.coins += bonus; + if (bonus > 0) MM.audio.play("early_bonus"); }; Game.prototype.towerAt = function (x, y) { @@ -141,6 +155,7 @@ if (!this.canAfford(cost)) return false; this.pay(cost); this.towers.push(MM.tower.create(this.shop, this.preview.x, this.preview.y)); + MM.audio.play("tower_built"); this.shop = null; this.preview = null; return true;
