|
17
|
1 // screen layout, top bar, tower shop, tower menu, splash and end screens,
|
|
24
|
2 // help popup, drawn from the supplied icons and drawings (art.md). numbers use the
|
|
17
|
3 // hand-drawn digits.
|
|
|
4
|
|
|
5 window.MM = window.MM || {};
|
|
|
6
|
|
|
7 MM.ui = (function () {
|
|
|
8 "use strict";
|
|
|
9
|
|
|
10 var cfg = MM.config;
|
|
|
11 var A = MM.assets;
|
|
23
|
12 var TOP = 60; // height of one top bar row, css pixels
|
|
17
|
13 var SHOP = 96; // shop width (landscape) or height (portrait)
|
|
|
14 var BUTTON = 52; // top bar buttons, at least 48 for touch
|
|
|
15 var SHOP_W = 84; // shop items
|
|
|
16 var SHOP_H = 72;
|
|
|
17 var POPUP_W = 168; // tower menu bubble; its height follows the drawing
|
|
|
18 var DIGIT = 28; // digit height in the top bar
|
|
|
19 var PRICE = 18; // digit height of prices
|
|
|
20 var DIGIT_GAP = 0.08; // space between digits, a share of their height
|
|
|
21 var BUBBLE_FLIP = 400; // ms between the two drawings of the chosen shop item
|
|
|
22 var PULSE = 1.2; // seconds of one pulse of a screen button
|
|
|
23 var WARN_PULSE = 0.5; // seconds of one pulse of an armed sell button
|
|
|
24 var INK = "#3a3530";
|
|
|
25 var PAPER = "#f6f1e6";
|
|
|
26 var FONT = "bold 22px system-ui, -apple-system, Segoe UI, sans-serif";
|
|
|
27 var TOWERS = ["t0", "t1", "t2", "t3"];
|
|
23
|
28 // widest usual values of the coin, heart and wave counters
|
|
|
29 var USUAL = ["000", "00", "00/00"];
|
|
17
|
30 // each screen drawing, its separate button image and the button's action
|
|
|
31 var SCREENS = {
|
|
|
32 splash: { image: "splash_play", id: "play" },
|
|
|
33 map_won: { image: "map_won_button", id: "next" },
|
|
|
34 game_lost: { image: "game_lost_button", id: "retry" },
|
|
|
35 game_won: { image: "game_won_button", id: "restart" }
|
|
|
36 };
|
|
24
|
37 // the extra buttons of the splash screen beside the play button, placed
|
|
|
38 // by [art.screen] in the config
|
|
|
39 var SPLASH_EXTRA = [
|
|
|
40 { image: "wobbly_logo", id: "logo", at: "splash_logo" },
|
|
|
41 { image: "help_splash", id: "help", at: "splash_help" }
|
|
|
42 ];
|
|
17
|
43
|
|
|
44 // digit variants from the sprite table: character -> sprite names
|
|
|
45 var DIGITS = {};
|
|
|
46 Object.keys(cfg.sprites).forEach(function (n) {
|
|
|
47 var m = /^digit_(\d|slash)_\d+$/.exec(n);
|
|
|
48 if (!m) return;
|
|
|
49 var ch = m[1] === "slash" ? "/" : m[1];
|
|
|
50 (DIGITS[ch] = DIGITS[ch] || []).push(n);
|
|
|
51 });
|
|
|
52
|
|
|
53 // all screens share one scale, set by the largest drawing, so they keep
|
|
|
54 // the sizes of the drawings relative to each other
|
|
|
55 function screenScale(w, h) {
|
|
|
56 var mw = 0, mh = 0;
|
|
|
57 Object.keys(SCREENS).forEach(function (n) {
|
|
|
58 mw = Math.max(mw, cfg.sprites[n][0]);
|
|
|
59 mh = Math.max(mh, cfg.sprites[n][1]);
|
|
|
60 });
|
|
|
61 return Math.min(1, 0.92 * w / mw, 0.9 * h / mh);
|
|
|
62 }
|
|
|
63
|
|
23
|
64 // width of the top bar counters, each at its widest usual value, for
|
|
|
65 // icons of the given size
|
|
|
66 function countersWidth(icon) {
|
|
|
67 var w = 0;
|
|
|
68 USUAL.forEach(function (s) { w += icon + 6 + numberWidth(s, DIGIT) + 18; });
|
|
|
69 return w - 18;
|
|
|
70 }
|
|
|
71
|
|
|
72 // width of the top bar buttons, the early start button included
|
|
|
73 function buttonsWidth() {
|
|
|
74 var s = cfg.sprites.next_wave;
|
|
24
|
75 return 4 * (BUTTON + 8) + BUTTON * s[0] / s[1];
|
|
23
|
76 }
|
|
|
77
|
|
|
78 // positions of everything on screen for a window of w x h css pixels.
|
|
|
79 // when the counters and the buttons do not fit side by side, the buttons
|
|
|
80 // get a second top bar row under the counters.
|
|
17
|
81 function layout(w, h, map) {
|
|
23
|
82 var land = w >= h, icon = 32;
|
|
|
83 var rows = 8 + countersWidth(icon) + 16 + buttonsWidth() + 8 > w ? 2 : 1;
|
|
|
84 var top = rows * TOP;
|
|
|
85 var area = land ? { x: 0, y: top, w: w - SHOP, h: h - top }
|
|
|
86 : { x: 0, y: top, w: w, h: h - top - SHOP };
|
|
17
|
87 var scale = Math.min(area.w / map.width, area.h / map.height);
|
|
|
88 var L = {
|
|
|
89 w: w, h: h, land: land, area: area, scale: scale,
|
|
23
|
90 top: top, // top bar height
|
|
|
91 buttonRow: top - TOP, // top of the button row
|
|
17
|
92 ox: area.x + (area.w - map.width * scale) / 2,
|
|
|
93 oy: area.y + (area.h - map.height * scale) / 2,
|
|
23
|
94 shop: land ? { x: w - SHOP, y: top, w: SHOP, h: h - top }
|
|
17
|
95 : { x: 0, y: h - SHOP, w: w, h: SHOP },
|
|
23
|
96 coinIcon: { x: 8 + icon / 2, y: TOP / 2, size: icon },
|
|
17
|
97 screen: screenScale(w, h)
|
|
|
98 };
|
|
|
99 return L;
|
|
|
100 }
|
|
|
101
|
|
|
102 // the screen shown over the map, or null during play
|
|
|
103 function screenName(game) {
|
|
24
|
104 if (game.help) return "help_info";
|
|
17
|
105 if (game.splash) return "splash";
|
|
|
106 if (game.result === "lost") return "game_lost";
|
|
|
107 if (game.result) return game.lastMap() ? "game_won" : "map_won";
|
|
|
108 return null;
|
|
|
109 }
|
|
|
110
|
|
24
|
111 // the help popup centred in the window, scaled on its own to fit 96 %
|
|
|
112 // of the window, at most 1. its buttons are the email address, when
|
|
|
113 // there is one, and the whole window, which closes the popup. they are
|
|
|
114 // not drawn
|
|
|
115 function helpRects(L) {
|
|
|
116 var s = cfg.sprites.help_info, e = cfg.art.screen.help_email;
|
|
|
117 var k = Math.min(1, 0.96 * L.w / s[0], 0.96 * L.h / s[1]);
|
|
|
118 var p = { x: (L.w - s[0] * k) / 2, y: (L.h - s[1] * k) / 2, w: s[0] * k, h: s[1] * k };
|
|
|
119 var list = [];
|
|
|
120 if (cfg.links.email) {
|
|
|
121 list.push({ id: "email", x: p.x + e[0] * k, y: p.y + e[1] * k, w: e[2] * k, h: e[3] * k });
|
|
|
122 }
|
|
|
123 list.push({ id: "close_help", x: 0, y: 0, w: L.w, h: L.h });
|
|
|
124 return { panel: p, buttons: list };
|
|
|
125 }
|
|
|
126
|
|
|
127 // the drawing of a screen centred in the window, and its buttons: the
|
|
|
128 // screen's own button, and on the splash screen the extra buttons. each
|
|
|
129 // button is {id, image, screen, x, y, w, h}
|
|
17
|
130 function screenRects(name, L) {
|
|
24
|
131 if (name === "help_info") return helpRects(L);
|
|
17
|
132 var k = L.screen, s = cfg.sprites[name];
|
|
|
133 var bs = cfg.sprites[SCREENS[name].image], at = cfg.art.screen[name];
|
|
|
134 var p = { x: (L.w - s[0] * k) / 2, y: (L.h - s[1] * k) / 2, w: s[0] * k, h: s[1] * k };
|
|
24
|
135 var list = [{ id: SCREENS[name].id, image: SCREENS[name].image, screen: name,
|
|
|
136 x: p.x + at[0] * k, y: p.y + at[1] * k, w: bs[0] * k, h: bs[1] * k }];
|
|
|
137 if (name === "splash") {
|
|
|
138 // these are placed by height; the width follows the drawing
|
|
|
139 SPLASH_EXTRA.forEach(function (e) {
|
|
|
140 var es = cfg.sprites[e.image], ea = cfg.art.screen[e.at];
|
|
|
141 var h = ea[2] * k;
|
|
|
142 list.push({ id: e.id, image: e.image, screen: name,
|
|
|
143 x: p.x + ea[0] * k, y: p.y + ea[1] * k, w: h * es[0] / es[1], h: h });
|
|
|
144 });
|
|
|
145 }
|
|
|
146 return { panel: p, buttons: list };
|
|
17
|
147 }
|
|
|
148
|
|
|
149 // the tower menu: a bubble above the selected tower, or below it when
|
|
|
150 // there is no room above, kept inside the map area. upgrade and sell each
|
|
|
151 // take half of the bubble; at the top level there is no upgrade and sell
|
|
|
152 // takes all of it. cx is where the button's drawing is centred.
|
|
|
153 function towerMenu(game, L) {
|
|
|
154 var t = game.selected, a = L.area, gap = 8;
|
|
|
155 var s = cfg.sprites.tower_popup, w = POPUP_W, h = POPUP_W * s[1] / s[0];
|
|
|
156 var x = L.ox + t.x * L.scale, y = L.oy + t.y * L.scale;
|
|
|
157 var half = A.size(MM.tower.sprite(t), cfg.scale.sprite)[1] / 2 * L.scale + gap;
|
|
|
158 var top = y - half - h;
|
|
|
159 if (top < a.y + gap) top = y + half;
|
|
|
160 var left = MM.util.clamp(x - w / 2, a.x + gap, a.x + a.w - w - gap);
|
|
|
161 var bubble = { x: left, y: top, w: w, h: h };
|
|
|
162 if (!MM.tower.upgradeCost(t)) {
|
|
|
163 return [{ id: "sell", x: left, y: top, w: w, h: h, cx: left + w / 2, bubble: bubble }];
|
|
|
164 }
|
|
|
165 return [
|
|
|
166 { id: "upgrade", x: left, y: top, w: w / 2, h: h, cx: left + w * 0.34, bubble: bubble },
|
|
|
167 { id: "sell", x: left + w / 2, y: top, w: w / 2, h: h, cx: left + w * 0.66, bubble: bubble }
|
|
|
168 ];
|
|
|
169 }
|
|
|
170
|
|
|
171 // the buttons for the current state, each {id, x, y, w, h}
|
|
|
172 function buttons(game, L) {
|
|
|
173 var out = [];
|
|
|
174 var name = screenName(game);
|
|
24
|
175 if (name) return screenRects(name, L).buttons;
|
|
17
|
176 // top bar, right to left
|
|
23
|
177 var y = L.buttonRow + (TOP - BUTTON) / 2, x = L.w - 8;
|
|
24
|
178 ["help", "pause", "speed", "sound"].forEach(function (id) {
|
|
17
|
179 x -= BUTTON;
|
|
|
180 out.push({ id: id, x: x, y: y, w: BUTTON, h: BUTTON });
|
|
|
181 x -= 8;
|
|
|
182 });
|
|
|
183 if (game.waves.phase === "break") {
|
|
|
184 var s = cfg.sprites.next_wave, w = BUTTON * s[0] / s[1];
|
|
|
185 out.push({ id: "early", x: x - w, y: y, w: w, h: BUTTON });
|
|
|
186 }
|
|
|
187 TOWERS.forEach(function (t, i) {
|
|
|
188 var b = L.land ? { x: L.shop.x + (SHOP - SHOP_W) / 2, y: L.shop.y + 10 + i * (SHOP_H + 10) }
|
|
|
189 : { x: L.shop.x + 10 + i * (SHOP_W + 10), y: L.shop.y + (SHOP - SHOP_H) / 2 };
|
|
|
190 b.id = "shop";
|
|
|
191 b.tower = t;
|
|
|
192 b.w = SHOP_W;
|
|
|
193 b.h = SHOP_H;
|
|
|
194 out.push(b);
|
|
|
195 });
|
|
|
196 if (game.selected) out = out.concat(towerMenu(game, L));
|
|
|
197 return out;
|
|
|
198 }
|
|
|
199
|
|
|
200 function inside(b, x, y) {
|
|
|
201 return x >= b.x && x < b.x + b.w && y >= b.y && y < b.y + b.h;
|
|
|
202 }
|
|
|
203
|
|
|
204 function hit(game, L, x, y) {
|
|
|
205 var list = buttons(game, L);
|
|
|
206 for (var i = 0; i < list.length; i++) {
|
|
|
207 if (inside(list[i], x, y)) return list[i];
|
|
|
208 }
|
|
|
209 return null;
|
|
|
210 }
|
|
|
211
|
|
|
212 // system font text, for the debug stats only
|
|
|
213 function text(ctx, s, x, y, align, size) {
|
|
|
214 ctx.font = size ? FONT.replace("22px", size + "px") : FONT;
|
|
|
215 ctx.textAlign = align || "left";
|
|
|
216 ctx.textBaseline = "middle";
|
|
|
217 ctx.lineWidth = 4;
|
|
|
218 ctx.strokeStyle = PAPER;
|
|
|
219 ctx.strokeText(s, x, y);
|
|
|
220 ctx.fillStyle = INK;
|
|
|
221 ctx.fillText(s, x, y);
|
|
|
222 }
|
|
|
223
|
|
|
224 // a sprite fitted into a box of w x h centred on x, y, keeping its shape
|
|
|
225 function fit(ctx, name, x, y, w, h) {
|
|
|
226 var s = cfg.sprites[name], k = Math.min(w / s[0], h / s[1]);
|
|
|
227 ctx.drawImage(A.img(name), x - s[0] * k / 2, y - s[1] * k / 2, s[0] * k, s[1] * k);
|
|
|
228 }
|
|
|
229
|
|
|
230 // the digit sprites for string s. the variant of each digit depends on
|
|
|
231 // the digit and its place counted from the right, so a number keeps its
|
|
|
232 // look while other places change.
|
|
|
233 function glyphs(s) {
|
|
|
234 var out = [];
|
|
|
235 for (var i = 0; i < s.length; i++) {
|
|
|
236 var list = DIGITS[s[i]];
|
|
|
237 if (!list) continue;
|
|
|
238 var place = s.length - 1 - i;
|
|
|
239 out.push(list[(place * 5 + s.charCodeAt(i)) % list.length]);
|
|
|
240 }
|
|
|
241 return out;
|
|
|
242 }
|
|
|
243
|
|
|
244 function numberWidth(s, h) {
|
|
|
245 var g = glyphs(s), w = 0;
|
|
|
246 g.forEach(function (n) { w += cfg.sprites[n][0] * h / cfg.sprites[n][1]; });
|
|
|
247 return w + Math.max(0, g.length - 1) * h * DIGIT_GAP;
|
|
|
248 }
|
|
|
249
|
|
|
250 // number s in digits of height h, vertically centred on y. align is
|
|
|
251 // "left", "center" or "right" of x.
|
|
|
252 function number(ctx, s, x, y, h, align) {
|
|
|
253 s = String(s);
|
|
|
254 var w = numberWidth(s, h);
|
|
|
255 if (align === "center") x -= w / 2;
|
|
|
256 else if (align === "right") x -= w;
|
|
|
257 glyphs(s).forEach(function (n) {
|
|
|
258 var gw = cfg.sprites[n][0] * h / cfg.sprites[n][1];
|
|
|
259 ctx.drawImage(A.img(n), x, y - h / 2, gw, h);
|
|
|
260 x += gw + h * DIGIT_GAP;
|
|
|
261 });
|
|
|
262 }
|
|
|
263
|
|
|
264 // a price, the coin icon followed by the amount, centred on x, y
|
|
|
265 function price(ctx, amount, x, y) {
|
|
|
266 var s = String(amount), coin = PRICE * 0.8, gap = 3;
|
|
|
267 var left = x - (coin + gap + numberWidth(s, PRICE)) / 2;
|
|
|
268 fit(ctx, "coin_icon", left + coin / 2, y, coin, coin);
|
|
|
269 number(ctx, s, left + coin + gap, y, PRICE, "left");
|
|
|
270 }
|
|
|
271
|
|
|
272 function box(ctx, b, fill, line) {
|
|
|
273 ctx.fillStyle = fill;
|
|
|
274 ctx.strokeStyle = line || INK;
|
|
|
275 ctx.lineWidth = 2;
|
|
|
276 ctx.beginPath();
|
|
|
277 if (ctx.roundRect) ctx.roundRect(b.x, b.y, b.w, b.h, 10);
|
|
|
278 else ctx.rect(b.x, b.y, b.w, b.h);
|
|
|
279 ctx.fill();
|
|
|
280 ctx.stroke();
|
|
|
281 }
|
|
|
282
|
|
|
283 // a screen's button image over the same button in the drawing. it pulses
|
|
|
284 // slowly as a cue to tap; under the mouse it is drawn larger, lifted by
|
|
|
285 // a shadow.
|
|
|
286 function screenButton(ctx, b, view) {
|
|
|
287 var cx = b.x + b.w / 2, cy = b.y + b.h / 2;
|
|
|
288 var hover = view.hover && inside(b, view.hover.x, view.hover.y);
|
|
|
289 var k = hover ? 1.08 : 1 + 0.04 * (0.5 - 0.5 * Math.cos(2 * Math.PI * view.now / 1000 / PULSE));
|
|
|
290 var w = b.w * k, h = b.h * k;
|
|
|
291 ctx.save();
|
|
|
292 if (hover) {
|
|
|
293 ctx.shadowColor = "rgba(0, 0, 0, 0.35)";
|
|
|
294 ctx.shadowBlur = 12;
|
|
|
295 ctx.shadowOffsetY = 3;
|
|
|
296 }
|
|
24
|
297 ctx.drawImage(A.img(b.image), cx - w / 2, cy - h / 2, w, h);
|
|
17
|
298 ctx.restore();
|
|
|
299 }
|
|
|
300
|
|
|
301 function drawButton(ctx, game, b, view) {
|
|
|
302 var cx = b.x + b.w / 2, cy = b.y + b.h / 2;
|
|
|
303 if (b.screen) {
|
|
|
304 screenButton(ctx, b, view);
|
|
24
|
305 } else if (b.id === "help") {
|
|
|
306 fit(ctx, "help_button", cx, cy, b.w, b.h);
|
|
17
|
307 } else if (b.id === "pause") {
|
|
|
308 // shows what a tap does: pause while running, play while paused
|
|
|
309 fit(ctx, game.paused ? "play_button" : "pause_button", cx, cy, b.w, b.h);
|
|
|
310 } else if (b.id === "speed") {
|
|
|
311 // debug speeds have no drawing and show their number
|
|
|
312 var sp = game.speed(), name = "speed_x" + sp;
|
|
|
313 if (cfg.sprites[name]) {
|
|
|
314 fit(ctx, name, cx, cy, b.w, b.h);
|
|
|
315 } else {
|
|
|
316 box(ctx, b, PAPER);
|
|
|
317 number(ctx, sp, cx, cy, DIGIT, "center");
|
|
|
318 }
|
|
|
319 } else if (b.id === "sound") {
|
|
|
320 fit(ctx, MM.audio.enabled() ? "sound_on" : "sound_off", cx, cy, b.w, b.h);
|
|
|
321 } else if (b.id === "early") {
|
|
|
322 // the countdown fills the empty right part of the drawing
|
|
|
323 ctx.drawImage(A.img("next_wave"), b.x, b.y, b.w, b.h);
|
|
|
324 number(ctx, Math.ceil(game.waves.left), b.x + b.w * 0.66, cy, DIGIT, "center");
|
|
|
325 } else if (b.id === "shop") {
|
|
|
326 var def = cfg.tower[b.tower];
|
|
|
327 // the chosen item's bubble switches between its two drawings
|
|
|
328 var bubble = game.shop !== b.tower ? "shop_bubble"
|
|
|
329 : Math.floor(view.now / BUBBLE_FLIP) % 2 ? "shop_bubble_dark2" : "shop_bubble_dark";
|
|
|
330 ctx.drawImage(A.img(bubble), b.x, b.y, b.w, b.h);
|
|
|
331 ctx.globalAlpha = game.canAfford(def.cost[0]) && !game.paused ? 1 : 0.35;
|
|
|
332 fit(ctx, b.tower, cx, b.y + 28, 44, 38);
|
|
|
333 price(ctx, def.cost[0], cx, b.y + b.h - 15);
|
|
|
334 ctx.globalAlpha = 1;
|
|
|
335 } else if (b.id === "upgrade") {
|
|
|
336 var cost = MM.tower.upgradeCost(game.selected);
|
|
|
337 ctx.globalAlpha = game.canAfford(cost) ? 1 : 0.35;
|
|
|
338 fit(ctx, "upgrade_button", b.cx, b.bubble.y + b.bubble.h * 0.4, 46, 44);
|
|
|
339 price(ctx, cost, b.cx, b.bubble.y + b.bubble.h * 0.7);
|
|
|
340 ctx.globalAlpha = 1;
|
|
|
341 } else if (b.id === "sell") {
|
|
|
342 // armed by a first tap: a fast pulse with a red glow until the
|
|
|
343 // second tap sells
|
|
|
344 var k = 1;
|
|
|
345 ctx.save();
|
|
|
346 if (game.sellArmed) {
|
|
|
347 k = 1 + 0.15 * (0.5 - 0.5 * Math.cos(2 * Math.PI * view.now / 1000 / WARN_PULSE));
|
|
|
348 ctx.shadowColor = "rgba(220, 30, 20, 0.9)";
|
|
|
349 ctx.shadowBlur = 14;
|
|
|
350 }
|
|
|
351 fit(ctx, "sell_button", b.cx, b.bubble.y + b.bubble.h * 0.4, 46 * k, 44 * k);
|
|
|
352 ctx.restore();
|
|
|
353 price(ctx, MM.tower.refund(game.selected), b.cx,
|
|
|
354 b.bubble.y + b.bubble.h * 0.7);
|
|
|
355 }
|
|
|
356 }
|
|
|
357
|
|
|
358 function draw(ctx, game, L, view) {
|
|
|
359 var dpr = view.dpr;
|
|
|
360 ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
|
361
|
|
|
362 // top bar: coins, hearts, wave
|
|
|
363 ctx.fillStyle = "rgba(246, 241, 230, 0.92)";
|
|
23
|
364 ctx.fillRect(0, 0, L.w, L.top);
|
|
17
|
365 ctx.fillStyle = "rgba(246, 241, 230, 0.92)";
|
|
|
366 ctx.fillRect(L.shop.x, L.shop.y, L.shop.w, L.shop.h);
|
|
|
367 ctx.fillStyle = "rgba(58, 53, 48, 0.25)";
|
|
23
|
368 ctx.fillRect(0, L.top - 2, L.w, 2);
|
|
17
|
369 // each counter takes at least the width of its widest usual value, so
|
|
|
370 // the next one does not move while the numbers change
|
|
|
371 var ic = L.coinIcon, x = ic.x - ic.size / 2;
|
|
23
|
372 [["coin_icon", game.coins], ["heart", game.hearts],
|
|
|
373 ["monster_icon", game.waves.shown() + "/" + game.waves.list.length]
|
|
|
374 ].forEach(function (c, i) {
|
|
17
|
375 var s = String(c[1]);
|
|
23
|
376 fit(ctx, c[0], x + ic.size / 2, ic.y, ic.size, ic.size);
|
|
|
377 number(ctx, s, x + ic.size + 6, ic.y, DIGIT, "left");
|
|
|
378 x += ic.size + 6 + Math.max(numberWidth(s, DIGIT), numberWidth(USUAL[i], DIGIT)) + 18;
|
|
17
|
379 });
|
|
|
380
|
|
|
381 var screen = screenName(game);
|
|
|
382 var list = buttons(game, L);
|
|
|
383 if (game.paused && !screen) {
|
|
|
384 ctx.fillStyle = "rgba(255, 255, 255, 0.18)";
|
|
|
385 ctx.fillRect(L.ox, L.oy, game.map.width * L.scale, game.map.height * L.scale);
|
|
|
386 }
|
|
|
387 if (screen) {
|
|
|
388 ctx.fillStyle = game.splash ? "rgba(246, 241, 230, 0.55)" : "rgba(40, 35, 30, 0.45)";
|
|
|
389 ctx.fillRect(0, 0, L.w, L.h);
|
|
|
390 var p = screenRects(screen, L).panel;
|
|
24
|
391 // the help drawing is shrunk a lot on small screens
|
|
|
392 ctx.imageSmoothingQuality = "high";
|
|
17
|
393 ctx.drawImage(A.img(screen), p.x, p.y, p.w, p.h);
|
|
24
|
394 ctx.imageSmoothingQuality = "low";
|
|
17
|
395 } else if (game.selected) {
|
|
|
396 var bub = list[list.length - 1].bubble;
|
|
|
397 ctx.drawImage(A.img("tower_popup"), bub.x, bub.y, bub.w, bub.h);
|
|
|
398 }
|
|
|
399 list.forEach(function (b) { drawButton(ctx, game, b, view); });
|
|
|
400
|
|
|
401 if (cfg.debug.show_stats && view.stats) {
|
|
|
402 var st = view.stats;
|
|
|
403 text(ctx, st.ms.toFixed(1) + " ms " + game.monsters.length + " m " +
|
|
|
404 game.towers.length + " t " + game.projectiles.length + " p seed " + game.seed,
|
|
|
405 8, L.h - 14, "left", 14);
|
|
|
406 }
|
|
|
407 }
|
|
|
408
|
|
|
409 return { layout: layout, hit: hit, draw: draw, BUBBLE_FLIP: BUBBLE_FLIP };
|
|
|
410 })();
|