diff game/js/game.js @ 23:2f555a54c332

layout fixes and balancing
author ark
date 2026-10-20 12:04 +0200
parents fe680946164b
children 3f2811aebb3d
line wrap: on
line diff
--- a/game/js/game.js	Tue Oct 20 03:08:56 2026 +0200
+++ b/game/js/game.js	Tue Oct 20 12:04:42 2026 +0200
@@ -70,7 +70,7 @@
         if (this.result) return;
         var self = this;
         this.time += dt;
-        this.waves.update(dt, this.monsters.length, function (kind) {
+        this.waves.update(dt, function (kind) {
             var m = MM.monster.create(self, kind);
             self.monsters.push(m);
             MM.audio.play(m.boss ? "boss_enter" : "monster_enter");
@@ -127,20 +127,35 @@
         this.coins += m.coins;
         var n = Math.min(m.coins, cfg.coins.max_sprites);
         for (var i = 0; i < n; i++) {
-            this.flights.push({
-                x: m.x + (this.random() - 0.5) * m.w,
-                y: m.y - m.h / 2 + (this.random() - 0.5) * m.h / 2,
-                sprite: "c" + Math.floor(this.random() * 4),
-                // stagger the coins a little
-                t: -i * 0.05
-            });
+            this.flight(m.x + (this.random() - 0.5) * m.w,
+                        m.y - m.h / 2 + (this.random() - 0.5) * m.h / 2, i);
         }
     };
 
+    // the i-th coin of a group flying from (x, y) to the counter
+    Game.prototype.flight = function (x, y, i) {
+        this.flights.push({
+            x: x,
+            y: y,
+            sprite: "c" + Math.floor(this.random() * 4),
+            // stagger the coins a little
+            t: -i * 0.05
+        });
+    };
+
+    // the bonus coins count at once and fly from the exits, taking turns
+    // if there are several
     Game.prototype.startEarly = function () {
         var bonus = this.waves.startEarly();
+        if (bonus <= 0) return;
         this.coins += bonus;
-        if (bonus > 0) MM.audio.play("early_bonus");
+        MM.audio.play("early_bonus");
+        var exits = this.map.data.exits;
+        var n = exits.length ? Math.min(bonus, cfg.coins.max_sprites) : 0;
+        for (var i = 0; i < n; i++) {
+            var e = exits[i % exits.length];
+            this.flight(e[0] + (this.random() - 0.5) * e[2], e[1] + (this.random() - 0.5) * e[2], i);
+        }
     };
 
     Game.prototype.towerAt = function (x, y) {