changeset 13:8df95050fc8b

no more build during pause; tower popup closes on any click outside it
author ark
date 2026-10-19 21:59 +0200
parents dc314bfbb1cf
children 7fda634d15ad
files doc/architecture.md doc/balance.md doc/game_design.md doc/roadmap.md game/js/game.js game/js/input.js game/js/main.js game/js/tower.js game/js/ui.js
diffstat 9 files changed, 41 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/doc/architecture.md	Mon Oct 19 20:41:45 2026 +0200
+++ b/doc/architecture.md	Mon Oct 19 21:59:53 2026 +0200
@@ -224,7 +224,7 @@
 - the simulation advances in fixed steps of 1/60 s. drawing happens once per
   browser frame and is independent of it
 - game speed 2x runs two simulation steps per frame
-- pause stops the simulation; drawing and input continue
+- pause stops the simulation; drawing and the top bar buttons continue
 - a frame that takes too long runs at most a few steps and drops the rest, so
   the game slows down rather than freezing after the tab was in the background
 
--- a/doc/balance.md	Mon Oct 19 20:41:45 2026 +0200
+++ b/doc/balance.md	Mon Oct 19 21:59:53 2026 +0200
@@ -150,8 +150,7 @@
 | t3    | 25              | 50      | 75      | 100     | 125     | 375   |
 
 selling refunds half of everything paid for the tower, build and upgrades,
-rounded down (decided). a tower is sold whole. purchases made during the
-current pause are refunded in full instead (see game_design.md).
+rounded down (decided). a tower is sold whole.
 
 | tower | level 1 | level 2 | level 3 | level 4 | level 5 |
 |-------|---------|---------|---------|---------|---------|
--- a/doc/game_design.md	Mon Oct 19 20:41:45 2026 +0200
+++ b/doc/game_design.md	Mon Oct 19 21:59:53 2026 +0200
@@ -84,10 +84,6 @@
 - selling a tower refunds half of everything paid for it: the build and all
   its upgrades. a tower is always sold whole; upgrades cannot be sold one by
   one
-    exception: purchases made during the current pause are refunded in full.
-    a tower built and sold during the same pause, never used, costs nothing.
-    an upgrade bought during a pause comes back in full if the tower is sold
-    before the game resumes; the rest of the tower sells at half
 
 monsters
 --------
@@ -147,7 +143,9 @@
 controls
 --------
 
-- pause, with building, upgrading and selling allowed while paused
+- pause. towers cannot be built, upgraded or sold while paused. building
+  during a pause was allowed at first, but it clashed with starting waves
+  early
 - game speed 1x, 2x and 4x (decided)
 - sound on and off, kept in the browser
 - input via pointer events, so mouse and touch work the same. no part of the
--- a/doc/roadmap.md	Mon Oct 19 20:41:45 2026 +0200
+++ b/doc/roadmap.md	Mon Oct 19 21:59:53 2026 +0200
@@ -25,7 +25,7 @@
       damage, hp bars, coin drops and flying coins
     - first playable version of map0
 6. tower details
-    - upgrades, selling the whole tower with the pause refund rule, t0 melee
+    - upgrades, selling the whole tower, t0 melee
       and spike sides, t2 slow with the blue hp bar, boss with its bar
 7. game flow
     - splash screen with title, byline and play button over the paused first
@@ -147,8 +147,7 @@
 - game flow: the first map is debug.start_map, and only the first map
   starts at debug.start_wave; the next maps start at wave 1.
   debug.start_coins applies to every map. the splash screen pauses the
-  first map without counting the pause for the sell refund, and only its
-  play button responds. the next map starts with its break running, as
+  first map, and only its play button responds. the next map starts with its break running, as
   does the first map after a lost map. the splash screen has a pale veil
   over the map, the other screens a dark one
 - screens: the scale is the same for all four drawings, set so the widest
@@ -186,12 +185,14 @@
   price below, and each takes half of the bubble as tap area. the upgrade
   price is the cost of the next level, dimmed when it cannot be afforded; at
   level 5 upgrade is left out and sell takes the whole bubble. the sell
-  price is the refund. selling clears the selection; upgrading keeps it
+  price is the refund. selling clears the selection; upgrading keeps it.
+  a tap anywhere outside the bubble closes it
 - selling takes two taps. the first arms it: sell_button pulses by 15 %
   every 0.5 s with a red glow. the second sells. a tap anywhere else,
   another button or the map, cancels it; there is no timeout
-- the pause refund counts pauses: each purchase records the pause it was
-  made in. a purchase made during the current pause is refunded in full
+- pausing clears the shop choice, the preview and the tower selection.
+  while paused, presses on the map do nothing and the shop is dimmed. the
+  top bar buttons, early start included, still work
 - placement: a press on the map puts the preview at the nearest legal
   position, and the preview follows the pointer until it is let go. only
   the first pointer is followed. a press within the footprint radius or 28
--- a/game/js/game.js	Mon Oct 19 20:41:45 2026 +0200
+++ b/game/js/game.js	Mon Oct 19 21:59:53 2026 +0200
@@ -25,7 +25,6 @@
         this.waves = new MM.Waves(mapIndex, MM.util.clamp(firstWave - 1, 0, mc.waves.length - 1));
         this.time = 0;
         this.paused = false;
-        this.pauses = 0;        // number of pauses so far, for the sell refund
         this.speeds = cfg.controls.speeds.concat(dbg.extra_speeds);
         this.speedIndex = 0;
         this.result = null;     // "won" or "lost"
@@ -45,14 +44,16 @@
         return this.map.index === MM.maps.length - 1;
     };
 
+    // towers cannot be built, upgraded or sold while paused, so pausing
+    // drops the shop choice, its preview and the tower selection
     Game.prototype.togglePause = function () {
         this.paused = !this.paused;
-        if (this.paused) this.pauses++;
-    };
-
-    // number of the current pause, 0 while the game runs
-    Game.prototype.pauseNumber = function () {
-        return this.paused ? this.pauses : 0;
+        if (this.paused) {
+            this.shop = null;
+            this.preview = null;
+            this.selected = null;
+            this.sellArmed = false;
+        }
     };
 
     Game.prototype.canAfford = function (cost) {
@@ -202,7 +203,7 @@
         this.pay(cost);
         var pv = this.preview;
         var t = MM.tower.create(this.shop, pv.x, pv.y, pv.sides);
-        t.paid.push({ cost: cost, pause: this.pauseNumber() });
+        t.paid += cost;
         this.towers.push(t);
         MM.audio.play("tower_built");
         this.shop = null;
@@ -217,7 +218,7 @@
         if (!cost || !this.canAfford(cost)) return;
         this.pay(cost);
         t.level++;
-        t.paid.push({ cost: cost, pause: this.pauseNumber() });
+        t.paid += cost;
         MM.audio.play("tower_upgraded");
     };
 
@@ -230,7 +231,7 @@
             return;
         }
         this.sellArmed = false;
-        this.coins += MM.tower.refund(t, this.pauseNumber());
+        this.coins += MM.tower.refund(t);
         this.towers.splice(this.towers.indexOf(t), 1);
         this.selected = null;
         MM.audio.play("tower_sold");
--- a/game/js/input.js	Mon Oct 19 20:41:45 2026 +0200
+++ b/game/js/input.js	Mon Oct 19 21:59:53 2026 +0200
@@ -100,8 +100,10 @@
             if (b.id === "play") MM.audio.start();
             if (b.id === "sound") MM.audio.toggle();
             MM.audio.play("button_tap");
-            // any other button cancels an armed sell
+            // any other button cancels an armed sell, and any button outside
+            // the tower menu closes it
             if (b.id !== "sell") game.sellArmed = false;
+            if (b.id !== "sell" && b.id !== "upgrade") game.selected = null;
             if (b.id === "play") app.play();
             else if (b.id === "next") app.next();
             else if (b.id === "retry") app.retry();
@@ -109,14 +111,18 @@
             else if (b.id === "pause") game.togglePause();
             else if (b.id === "speed") game.speedIndex = (game.speedIndex + 1) % game.speeds.length;
             else if (b.id === "early") game.startEarly();
-            else if (b.id === "shop" && game.canAfford(MM.config.tower[b.tower].cost)) game.chooseShop(b.tower);
+            else if (b.id === "shop" && !game.paused && game.canAfford(MM.config.tower[b.tower].cost)) game.chooseShop(b.tower);
             else if (b.id === "upgrade") game.upgrade();
             else if (b.id === "sell") game.sell();
             return null;
         }
-        if (game.result || game.splash) return null;
+        if (game.result || game.paused) return null;
         var m = mapPos(game, L, x, y);
-        if (!m) return null;
+        if (!m) {
+            game.sellArmed = false;
+            game.selected = null;
+            return null;
+        }
         var hitR = Math.max(MM.config.placement.footprint_radius, PREVIEW_HIT / L.scale);
         var kind = game.pressMap(m.x, m.y, hitR);
         if (!kind) return null;
@@ -150,7 +156,7 @@
     // preview builds; a drag that never found a legal position is refused
     function release(app, d, x, y) {
         var game = app.game(), L = app.layout();
-        if (game !== d.game || game.result) return;
+        if (game !== d.game || game.result || game.paused) return;
         var ok = d.onPreview && !d.moved ? game.build() : d.found;
         if (ok) return;
         MM.audio.play("placement_refused");
--- a/game/js/main.js	Mon Oct 19 20:41:45 2026 +0200
+++ b/game/js/main.js	Mon Oct 19 21:59:53 2026 +0200
@@ -27,8 +27,7 @@
         resize();
     }
 
-    // the splash screen over the paused first map. the pause does not count
-    // for the sell refund, as nothing can be bought on the splash screen.
+    // the splash screen over the paused first map
     function splash() {
         startMap(FIRST);
         game.splash = true;
--- a/game/js/tower.js	Mon Oct 19 20:41:45 2026 +0200
+++ b/game/js/tower.js	Mon Oct 19 21:59:53 2026 +0200
@@ -19,9 +19,7 @@
             x: x,
             y: y,
             sides: sides || [true, true, true, true],
-            // purchases, {cost, pause}: pause is the number of the pause
-            // the purchase was made in, 0 while the game ran
-            paid: [],
+            paid: 0,            // coins paid for building and upgrades
             angle: -Math.PI / 2,
             cooldown: 0,
             burst: 0
@@ -35,16 +33,9 @@
     }
 
     // coins back for selling the tower: half of everything paid for it,
-    // rounded down, except purchases made during the current pause, which
-    // come back in full. pause is the number of the current pause, 0 while
-    // the game runs.
-    function refund(t, pause) {
-        var rest = 0, full = 0;
-        t.paid.forEach(function (p) {
-            if (pause && p.pause === pause) full += p.cost;
-            else rest += p.cost;
-        });
-        return Math.floor(rest * cfg.tower_rules.sell_refund) + full;
+    // rounded down
+    function refund(t) {
+        return Math.floor(t.paid * cfg.tower_rules.sell_refund);
     }
 
     function sprite(t) {
--- a/game/js/ui.js	Mon Oct 19 20:41:45 2026 +0200
+++ b/game/js/ui.js	Mon Oct 19 21:59:53 2026 +0200
@@ -273,7 +273,7 @@
             var bubble = game.shop !== b.tower ? "shop_bubble"
                 : Math.floor(view.now / BUBBLE_FLIP) % 2 ? "shop_bubble_dark2" : "shop_bubble_dark";
             ctx.drawImage(A.img(bubble), b.x, b.y, b.w, b.h);
-            ctx.globalAlpha = game.canAfford(def.cost) ? 1 : 0.35;
+            ctx.globalAlpha = game.canAfford(def.cost) && !game.paused ? 1 : 0.35;
             fit(ctx, b.tower, cx, b.y + 28, 44, 38);
             price(ctx, def.cost, cx, b.y + b.h - 15);
             ctx.globalAlpha = 1;
@@ -295,7 +295,7 @@
             }
             fit(ctx, "sell_button", b.cx, b.bubble.y + b.bubble.h * 0.4, 46 * k, 44 * k);
             ctx.restore();
-            price(ctx, MM.tower.refund(game.selected, game.pauseNumber()), b.cx,
+            price(ctx, MM.tower.refund(game.selected), b.cx,
                   b.bubble.y + b.bubble.h * 0.7);
         }
     }