diff game/js/game.js @ 8:2c4fed8baed9

art update, persistent sound setting, tower selling as double action
author ark
date 2026-10-19 13:37 +0200
parents 910b26feca76
children a77857594150
line wrap: on
line diff
--- a/game/js/game.js	Mon Oct 19 11:50:24 2026 +0200
+++ b/game/js/game.js	Mon Oct 19 13:37:52 2026 +0200
@@ -21,6 +21,7 @@
         this.towers = [];
         this.projectiles = [];
         this.flights = [];      // coins flying to the counter
+        this.puffs = [];        // death puffs, {x, y, boss, t}
         this.waves = new MM.Waves(mapIndex, MM.util.clamp(firstWave - 1, 0, mc.waves.length - 1));
         this.time = 0;
         this.paused = false;
@@ -33,6 +34,7 @@
         this.shop = null;
         this.preview = null;
         this.selected = null;
+        this.sellArmed = false; // sell was tapped once and waits for the second tap
     }
 
     Game.prototype.speed = function () {
@@ -79,6 +81,8 @@
         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; });
+        this.puffs.forEach(function (p) { p.t += dt; });
+        this.puffs = this.puffs.filter(function (p) { return p.t < cfg.animation.death_puff; });
         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");
@@ -92,7 +96,10 @@
             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 = [];
+        if (this.result) {
+            this.flights = [];
+            this.puffs = [];
+        }
     };
 
     // a monster reached the exit
@@ -113,6 +120,7 @@
         }
         m.alive = false;
         MM.audio.play(m.boss ? "boss_die" : "monster_die");
+        this.puffs.push({ x: m.x, y: m.y, boss: m.boss, t: 0 });
         // 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);
@@ -153,6 +161,7 @@
     // was found for a preview.
     Game.prototype.tapMap = function (x, y, hitRadius) {
         var t = this.towerAt(x, y);
+        this.sellArmed = false;
         if (t && !(this.preview && Math.hypot(this.preview.x - x, this.preview.y - y) <= hitRadius)) {
             this.shop = null;
             this.preview = null;
@@ -200,9 +209,15 @@
         MM.audio.play("tower_upgraded");
     };
 
+    // the first tap arms selling, the second sells
     Game.prototype.sell = function () {
         var t = this.selected;
         if (!t) return;
+        if (!this.sellArmed) {
+            this.sellArmed = true;
+            return;
+        }
+        this.sellArmed = false;
         this.coins += MM.tower.refund(t, this.pauseNumber());
         this.towers.splice(this.towers.indexOf(t), 1);
         this.selected = null;