comparison game/js/wave.js @ 23:2f555a54c332

layout fixes and balancing
author ark
date 2026-10-20 12:04 +0200
parents fe680946164b
children
comparison
equal deleted inserted replaced
22:ad1b478fc4dc 23:2f555a54c332
6 "use strict"; 6 "use strict";
7 7
8 var cfg = MM.config; 8 var cfg = MM.config;
9 9
10 // phases: "break" counts down to the next wave, "spawning" releases 10 // phases: "break" counts down to the next wave, "spawning" releases
11 // the wave's monsters, "clearing" waits until the wave's monsters are 11 // the wave's monsters, "done" follows the last wave. a break starts when
12 // gone, "done" follows the last wave. random gives numbers in [0, 1). 12 // the last monster of a wave has spawned, so monsters may still be on
13 // the map. random gives numbers in [0, 1).
13 function Waves(mapIndex, firstWave, random) { 14 function Waves(mapIndex, firstWave, random) {
14 var mc = cfg.maps[mapIndex]; 15 var mc = cfg.maps[mapIndex];
15 this.list = mc.waves; 16 this.list = mc.waves;
16 this.rate = mc.early_bonus; 17 this.rate = mc.early_bonus;
17 this.interval = mc.spawn_interval !== undefined ? mc.spawn_interval : cfg.waves.spawn_interval; 18 this.interval = mc.spawn_interval !== undefined ? mc.spawn_interval : cfg.waves.spawn_interval;
61 var b = this.bonus(); 62 var b = this.bonus();
62 this.start(); 63 this.start();
63 return b; 64 return b;
64 }; 65 };
65 66
66 // advance by dt. spawn(kind) creates a monster; alive is the number of 67 // advance by dt. spawn(kind) creates a monster.
67 // monsters on the map. 68 Waves.prototype.update = function (dt, spawn) {
68 Waves.prototype.update = function (dt, alive, spawn) {
69 if (this.phase === "break") { 69 if (this.phase === "break") {
70 this.left -= dt; 70 this.left -= dt;
71 if (this.left <= 0) this.start(); 71 if (this.left <= 0) this.start();
72 return; 72 return;
73 } 73 }
75 this.wait -= dt; 75 this.wait -= dt;
76 while (this.pending.length && this.wait <= 0) { 76 while (this.pending.length && this.wait <= 0) {
77 spawn(this.take()); 77 spawn(this.take());
78 this.wait += this.interval; 78 this.wait += this.interval;
79 } 79 }
80 if (!this.pending.length) this.phase = "clearing"; 80 if (this.pending.length) return;
81 return;
82 }
83 if (this.phase === "clearing" && alive === 0) {
84 if (this.next >= this.list.length) { 81 if (this.next >= this.list.length) {
85 this.phase = "done"; 82 this.phase = "done";
86 } else { 83 } else {
87 this.phase = "break"; 84 this.phase = "break";
88 this.left = cfg.waves.break; 85 this.left = cfg.waves.break;