annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
1 // game state and rules: coins, hearts, building, upgrading, selling, win
910b26feca76 full game flow
ark
parents: 4
diff changeset
2 // and loss
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
3
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
4 window.MM = window.MM || {};
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
5
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
6 MM.Game = (function () {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
7 "use strict";
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
8
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
9 var cfg = MM.config;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
10 var dbg = cfg.debug;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
11
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
12 // firstWave counts from 1
910b26feca76 full game flow
ark
parents: 4
diff changeset
13 function Game(mapIndex, seed, firstWave) {
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
14 var mc = cfg.maps[mapIndex];
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
15 this.map = new MM.GameMap(mapIndex);
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
16 this.seed = seed;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
17 this.random = MM.util.rng(seed);
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
18 this.coins = dbg.start_coins >= 0 ? dbg.start_coins : mc.starting_coins;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
19 this.hearts = cfg.hearts.per_map;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
20 this.monsters = [];
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
21 this.towers = [];
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
22 this.projectiles = [];
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
23 this.flights = []; // coins flying to the counter
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
24 this.puffs = []; // death puffs, {x, y, boss, t}
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
25 this.waves = new MM.Waves(mapIndex, MM.util.clamp(firstWave - 1, 0, mc.waves.length - 1));
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
26 this.time = 0;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
27 this.paused = false;
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
28 this.pauses = 0; // number of pauses so far, for the sell refund
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
29 this.speeds = cfg.controls.speeds.concat(dbg.extra_speeds);
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
30 this.speedIndex = 0;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
31 this.result = null; // "won" or "lost"
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
32 this.splash = false; // splash screen shown over the paused map
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
33 // player selection: shop tower type, its snapped preview, a built tower
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
34 this.shop = null;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
35 this.preview = null;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
36 this.selected = null;
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
37 this.sellArmed = false; // sell was tapped once and waits for the second tap
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
38 }
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
39
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
40 Game.prototype.speed = function () {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
41 return this.speeds[this.speedIndex];
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
42 };
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
43
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
44 Game.prototype.lastMap = function () {
910b26feca76 full game flow
ark
parents: 4
diff changeset
45 return this.map.index === MM.maps.length - 1;
910b26feca76 full game flow
ark
parents: 4
diff changeset
46 };
910b26feca76 full game flow
ark
parents: 4
diff changeset
47
910b26feca76 full game flow
ark
parents: 4
diff changeset
48 Game.prototype.togglePause = function () {
910b26feca76 full game flow
ark
parents: 4
diff changeset
49 this.paused = !this.paused;
910b26feca76 full game flow
ark
parents: 4
diff changeset
50 if (this.paused) this.pauses++;
910b26feca76 full game flow
ark
parents: 4
diff changeset
51 };
910b26feca76 full game flow
ark
parents: 4
diff changeset
52
910b26feca76 full game flow
ark
parents: 4
diff changeset
53 // number of the current pause, 0 while the game runs
910b26feca76 full game flow
ark
parents: 4
diff changeset
54 Game.prototype.pauseNumber = function () {
910b26feca76 full game flow
ark
parents: 4
diff changeset
55 return this.paused ? this.pauses : 0;
910b26feca76 full game flow
ark
parents: 4
diff changeset
56 };
910b26feca76 full game flow
ark
parents: 4
diff changeset
57
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
58 Game.prototype.canAfford = function (cost) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
59 return dbg.unlimited_coins || this.coins >= cost;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
60 };
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
61
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
62 Game.prototype.pay = function (cost) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
63 if (!dbg.unlimited_coins) this.coins -= cost;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
64 };
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
65
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
66 // one simulation step of dt seconds
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
67 Game.prototype.step = function (dt) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
68 if (this.result) return;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
69 var self = this;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
70 this.time += dt;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
71 this.waves.update(dt, this.monsters.length, function (kind) {
4
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
72 var m = MM.monster.create(self, kind);
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
73 self.monsters.push(m);
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
74 MM.audio.play(m.boss ? "boss_enter" : "monster_enter");
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
75 });
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
76 this.monsters.forEach(function (m) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
77 if (m.alive && MM.monster.update(m, dt)) self.escape(m);
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
78 });
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
79 this.towers.forEach(function (t) { MM.tower.update(t, self, dt); });
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
80 this.projectiles.forEach(function (p) { MM.projectile.update(p, self, dt); });
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
81 this.monsters = this.monsters.filter(function (m) { return m.alive; });
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
82 this.projectiles = this.projectiles.filter(function (p) { return !p.done; });
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
83 this.flights.forEach(function (f) { f.t += dt; });
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
84 this.puffs.forEach(function (p) { p.t += dt; });
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
85 this.puffs = this.puffs.filter(function (p) { return p.t < cfg.animation.death_puff; });
4
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
86 var flying = this.flights.length;
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
87 this.flights = this.flights.filter(function (f) { return f.t < cfg.coins.flight_time; });
4
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
88 if (this.flights.length < flying) MM.audio.play("coins_arrive");
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
89
4
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
90 // the end sound waits for the last exit or death sound
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
91 if (this.hearts <= 0) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
92 this.result = "lost";
4
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
93 MM.audio.play("map_lost", ["monster_exit", "boss_exit"]);
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
94 } else if (this.waves.phase === "done" && this.monsters.length === 0) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
95 this.result = "won";
4
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
96 MM.audio.play("map_won", ["monster_die", "boss_die"]);
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
97 }
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
98 // the simulation stops here; the coins in flight are counted already
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
99 if (this.result) {
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
100 this.flights = [];
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
101 this.puffs = [];
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
102 }
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
103 };
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
104
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
105 // a monster reached the exit
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
106 Game.prototype.escape = function (m) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
107 m.alive = false;
4
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
108 MM.audio.play(m.boss ? "boss_exit" : "monster_exit");
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
109 if (!dbg.no_heart_loss) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
110 this.hearts = Math.max(0, this.hearts - (m.boss ? cfg.hearts.boss : cfg.hearts.monster));
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
111 }
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
112 };
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
113
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
114 Game.prototype.damage = function (m, amount) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
115 if (!m.alive) return;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
116 m.hp -= amount;
4
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
117 if (m.hp > 0) {
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
118 MM.audio.play("monster_hit");
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
119 return;
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
120 }
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
121 m.alive = false;
4
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
122 MM.audio.play(m.boss ? "boss_die" : "monster_die");
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
123 this.puffs.push({ x: m.x, y: m.y, boss: m.boss, t: 0 });
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
124 // coins count at once; the flying coins only show it (balance.md)
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
125 this.coins += m.coins;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
126 var n = Math.min(m.coins, cfg.coins.max_sprites);
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
127 for (var i = 0; i < n; i++) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
128 this.flights.push({
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
129 x: m.x + (this.random() - 0.5) * m.w,
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
130 y: m.y - m.h / 2 + (this.random() - 0.5) * m.h / 2,
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
131 sprite: "c" + Math.floor(this.random() * 4),
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
132 // stagger the coins a little
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
133 t: -i * 0.05
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
134 });
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
135 }
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
136 };
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
137
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
138 Game.prototype.startEarly = function () {
4
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
139 var bonus = this.waves.startEarly();
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
140 this.coins += bonus;
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
141 if (bonus > 0) MM.audio.play("early_bonus");
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
142 };
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
143
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
144 Game.prototype.towerAt = function (x, y) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
145 var r = cfg.placement.footprint_radius;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
146 for (var i = 0; i < this.towers.length; i++) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
147 var t = this.towers[i];
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
148 if (Math.hypot(t.x - x, t.y - y) <= r) return t;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
149 }
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
150 return null;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
151 };
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
152
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
153 Game.prototype.chooseShop = function (type) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
154 this.selected = null;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
155 this.preview = null;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
156 this.shop = this.shop === type ? null : type;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
157 };
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
158
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
159 // a tap on the map at map position x, y. hitRadius is how close the tap
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
160 // must be to the preview to build. returns false when no legal position
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
161 // was found for a preview.
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
162 Game.prototype.tapMap = function (x, y, hitRadius) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
163 var t = this.towerAt(x, y);
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
164 this.sellArmed = false;
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
165 if (t && !(this.preview && Math.hypot(this.preview.x - x, this.preview.y - y) <= hitRadius)) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
166 this.shop = null;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
167 this.preview = null;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
168 this.selected = t === this.selected ? null : t;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
169 return true;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
170 }
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
171 this.selected = null;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
172 if (!this.shop) return true;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
173 if (this.preview && Math.hypot(this.preview.x - x, this.preview.y - y) <= hitRadius) {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
174 return this.build();
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
175 }
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
176 this.preview = this.map.snap(x, y, this.towers);
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
177 if (!this.preview) return false;
910b26feca76 full game flow
ark
parents: 4
diff changeset
178 // t0 draws spikes only towards the path, judged by its top level range
910b26feca76 full game flow
ark
parents: 4
diff changeset
179 var def = cfg.tower[this.shop];
910b26feca76 full game flow
ark
parents: 4
diff changeset
180 if (def.projectile_speed === 0) {
910b26feca76 full game flow
ark
parents: 4
diff changeset
181 this.preview.sides = this.map.facingSides(this.preview.x, this.preview.y,
910b26feca76 full game flow
ark
parents: 4
diff changeset
182 def.range[def.range.length - 1]);
910b26feca76 full game flow
ark
parents: 4
diff changeset
183 }
910b26feca76 full game flow
ark
parents: 4
diff changeset
184 return true;
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
185 };
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
186
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
187 Game.prototype.build = function () {
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
188 var cost = cfg.tower[this.shop].cost;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
189 if (!this.canAfford(cost)) return false;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
190 this.pay(cost);
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
191 var pv = this.preview;
910b26feca76 full game flow
ark
parents: 4
diff changeset
192 var t = MM.tower.create(this.shop, pv.x, pv.y, pv.sides);
910b26feca76 full game flow
ark
parents: 4
diff changeset
193 t.paid.push({ cost: cost, pause: this.pauseNumber() });
910b26feca76 full game flow
ark
parents: 4
diff changeset
194 this.towers.push(t);
4
2d46729a022e sound processing and in-game sounds
ark
parents: 1
diff changeset
195 MM.audio.play("tower_built");
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
196 this.shop = null;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
197 this.preview = null;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
198 return true;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
199 };
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
200
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
201 // upgrade the selected tower by one level
910b26feca76 full game flow
ark
parents: 4
diff changeset
202 Game.prototype.upgrade = function () {
910b26feca76 full game flow
ark
parents: 4
diff changeset
203 var t = this.selected;
910b26feca76 full game flow
ark
parents: 4
diff changeset
204 var cost = t && MM.tower.upgradeCost(t);
910b26feca76 full game flow
ark
parents: 4
diff changeset
205 if (!cost || !this.canAfford(cost)) return;
910b26feca76 full game flow
ark
parents: 4
diff changeset
206 this.pay(cost);
910b26feca76 full game flow
ark
parents: 4
diff changeset
207 t.level++;
910b26feca76 full game flow
ark
parents: 4
diff changeset
208 t.paid.push({ cost: cost, pause: this.pauseNumber() });
910b26feca76 full game flow
ark
parents: 4
diff changeset
209 MM.audio.play("tower_upgraded");
910b26feca76 full game flow
ark
parents: 4
diff changeset
210 };
910b26feca76 full game flow
ark
parents: 4
diff changeset
211
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
212 // the first tap arms selling, the second sells
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
213 Game.prototype.sell = function () {
910b26feca76 full game flow
ark
parents: 4
diff changeset
214 var t = this.selected;
910b26feca76 full game flow
ark
parents: 4
diff changeset
215 if (!t) return;
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
216 if (!this.sellArmed) {
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
217 this.sellArmed = true;
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
218 return;
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
219 }
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
220 this.sellArmed = false;
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
221 this.coins += MM.tower.refund(t, this.pauseNumber());
910b26feca76 full game flow
ark
parents: 4
diff changeset
222 this.towers.splice(this.towers.indexOf(t), 1);
910b26feca76 full game flow
ark
parents: 4
diff changeset
223 this.selected = null;
910b26feca76 full game flow
ark
parents: 4
diff changeset
224 MM.audio.play("tower_sold");
910b26feca76 full game flow
ark
parents: 4
diff changeset
225 };
910b26feca76 full game flow
ark
parents: 4
diff changeset
226
1
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
227 return Game;
5492efd60e2c first prototype + updated art sheet
ark
parents:
diff changeset
228 })();