wobblyhead hg > minor_monsters
comparison game/js/game.js @ 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 | a77857594150 |
| children | 7fda634d15ad |
comparison
equal
deleted
inserted
replaced
| 12:dc314bfbb1cf | 13:8df95050fc8b |
|---|---|
| 23 this.flights = []; // coins flying to the counter | 23 this.flights = []; // coins flying to the counter |
| 24 this.puffs = []; // death puffs, {x, y, boss, t} | 24 this.puffs = []; // death puffs, {x, y, boss, t} |
| 25 this.waves = new MM.Waves(mapIndex, MM.util.clamp(firstWave - 1, 0, mc.waves.length - 1)); | 25 this.waves = new MM.Waves(mapIndex, MM.util.clamp(firstWave - 1, 0, mc.waves.length - 1)); |
| 26 this.time = 0; | 26 this.time = 0; |
| 27 this.paused = false; | 27 this.paused = false; |
| 28 this.pauses = 0; // number of pauses so far, for the sell refund | |
| 29 this.speeds = cfg.controls.speeds.concat(dbg.extra_speeds); | 28 this.speeds = cfg.controls.speeds.concat(dbg.extra_speeds); |
| 30 this.speedIndex = 0; | 29 this.speedIndex = 0; |
| 31 this.result = null; // "won" or "lost" | 30 this.result = null; // "won" or "lost" |
| 32 this.splash = false; // splash screen shown over the paused map | 31 this.splash = false; // splash screen shown over the paused map |
| 33 // player selection: shop tower type, its snapped preview, a built tower | 32 // player selection: shop tower type, its snapped preview, a built tower |
| 43 | 42 |
| 44 Game.prototype.lastMap = function () { | 43 Game.prototype.lastMap = function () { |
| 45 return this.map.index === MM.maps.length - 1; | 44 return this.map.index === MM.maps.length - 1; |
| 46 }; | 45 }; |
| 47 | 46 |
| 47 // towers cannot be built, upgraded or sold while paused, so pausing | |
| 48 // drops the shop choice, its preview and the tower selection | |
| 48 Game.prototype.togglePause = function () { | 49 Game.prototype.togglePause = function () { |
| 49 this.paused = !this.paused; | 50 this.paused = !this.paused; |
| 50 if (this.paused) this.pauses++; | 51 if (this.paused) { |
| 51 }; | 52 this.shop = null; |
| 52 | 53 this.preview = null; |
| 53 // number of the current pause, 0 while the game runs | 54 this.selected = null; |
| 54 Game.prototype.pauseNumber = function () { | 55 this.sellArmed = false; |
| 55 return this.paused ? this.pauses : 0; | 56 } |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 Game.prototype.canAfford = function (cost) { | 59 Game.prototype.canAfford = function (cost) { |
| 59 return dbg.unlimited_coins || this.coins >= cost; | 60 return dbg.unlimited_coins || this.coins >= cost; |
| 60 }; | 61 }; |
| 200 var cost = cfg.tower[this.shop].cost; | 201 var cost = cfg.tower[this.shop].cost; |
| 201 if (!this.canAfford(cost)) return false; | 202 if (!this.canAfford(cost)) return false; |
| 202 this.pay(cost); | 203 this.pay(cost); |
| 203 var pv = this.preview; | 204 var pv = this.preview; |
| 204 var t = MM.tower.create(this.shop, pv.x, pv.y, pv.sides); | 205 var t = MM.tower.create(this.shop, pv.x, pv.y, pv.sides); |
| 205 t.paid.push({ cost: cost, pause: this.pauseNumber() }); | 206 t.paid += cost; |
| 206 this.towers.push(t); | 207 this.towers.push(t); |
| 207 MM.audio.play("tower_built"); | 208 MM.audio.play("tower_built"); |
| 208 this.shop = null; | 209 this.shop = null; |
| 209 this.preview = null; | 210 this.preview = null; |
| 210 return true; | 211 return true; |
| 215 var t = this.selected; | 216 var t = this.selected; |
| 216 var cost = t && MM.tower.upgradeCost(t); | 217 var cost = t && MM.tower.upgradeCost(t); |
| 217 if (!cost || !this.canAfford(cost)) return; | 218 if (!cost || !this.canAfford(cost)) return; |
| 218 this.pay(cost); | 219 this.pay(cost); |
| 219 t.level++; | 220 t.level++; |
| 220 t.paid.push({ cost: cost, pause: this.pauseNumber() }); | 221 t.paid += cost; |
| 221 MM.audio.play("tower_upgraded"); | 222 MM.audio.play("tower_upgraded"); |
| 222 }; | 223 }; |
| 223 | 224 |
| 224 // the first tap arms selling, the second sells | 225 // the first tap arms selling, the second sells |
| 225 Game.prototype.sell = function () { | 226 Game.prototype.sell = function () { |
| 228 if (!this.sellArmed) { | 229 if (!this.sellArmed) { |
| 229 this.sellArmed = true; | 230 this.sellArmed = true; |
| 230 return; | 231 return; |
| 231 } | 232 } |
| 232 this.sellArmed = false; | 233 this.sellArmed = false; |
| 233 this.coins += MM.tower.refund(t, this.pauseNumber()); | 234 this.coins += MM.tower.refund(t); |
| 234 this.towers.splice(this.towers.indexOf(t), 1); | 235 this.towers.splice(this.towers.indexOf(t), 1); |
| 235 this.selected = null; | 236 this.selected = null; |
| 236 MM.audio.play("tower_sold"); | 237 MM.audio.play("tower_sold"); |
| 237 }; | 238 }; |
| 238 | 239 |
