wobblyhead hg > minor_monsters
comparison game/js/input.js @ 6:910b26feca76
full game flow
| author | ark |
|---|---|
| date | 2026-10-19 01:05 +0200 |
| parents | 2d46729a022e |
| children | 2c4fed8baed9 |
comparison
equal
deleted
inserted
replaced
| 5:67bf3c505145 | 6:910b26feca76 |
|---|---|
| 7 | 7 |
| 8 // how close a tap must be to the placement preview to build, css pixels | 8 // how close a tap must be to the placement preview to build, css pixels |
| 9 var PREVIEW_HIT = 28; | 9 var PREVIEW_HIT = 28; |
| 10 var REFUSED_TIME = 500; | 10 var REFUSED_TIME = 500; |
| 11 | 11 |
| 12 // app: {canvas, game(), layout(), restart(), view} | 12 // app: {canvas, view, game(), layout(), and the screen actions play(), |
| 13 // next(), retry(), restart()} | |
| 13 function attach(app) { | 14 function attach(app) { |
| 14 var c = app.canvas; | 15 var c = app.canvas; |
| 15 c.addEventListener("pointerdown", function (e) { | 16 c.addEventListener("pointerdown", function (e) { |
| 16 e.preventDefault(); | 17 e.preventDefault(); |
| 17 MM.audio.unlock(); | 18 MM.audio.unlock(); |
| 32 | 33 |
| 33 function tap(app, x, y) { | 34 function tap(app, x, y) { |
| 34 var game = app.game(), L = app.layout(); | 35 var game = app.game(), L = app.layout(); |
| 35 var b = MM.ui.hit(game, L, x, y); | 36 var b = MM.ui.hit(game, L, x, y); |
| 36 if (b) { | 37 if (b) { |
| 38 // the play button starts the sound | |
| 39 if (b.id === "play") MM.audio.start(); | |
| 37 MM.audio.play("button_tap"); | 40 MM.audio.play("button_tap"); |
| 38 if (b.id === "restart") app.restart(); | 41 if (b.id === "play") app.play(); |
| 39 else if (b.id === "pause") game.paused = !game.paused; | 42 else if (b.id === "next") app.next(); |
| 43 else if (b.id === "retry") app.retry(); | |
| 44 else if (b.id === "restart") app.restart(); | |
| 45 else if (b.id === "pause") game.togglePause(); | |
| 40 else if (b.id === "speed") game.speedIndex = (game.speedIndex + 1) % game.speeds.length; | 46 else if (b.id === "speed") game.speedIndex = (game.speedIndex + 1) % game.speeds.length; |
| 41 else if (b.id === "early") game.startEarly(); | 47 else if (b.id === "early") game.startEarly(); |
| 42 else if (b.id === "shop" && game.canAfford(MM.config.tower[b.tower].cost)) game.chooseShop(b.tower); | 48 else if (b.id === "shop" && game.canAfford(MM.config.tower[b.tower].cost)) game.chooseShop(b.tower); |
| 49 else if (b.id === "upgrade") game.upgrade(); | |
| 50 else if (b.id === "sell") game.sell(); | |
| 43 return; | 51 return; |
| 44 } | 52 } |
| 45 if (game.result) return; | 53 if (game.result || game.splash) return; |
| 46 var mx = (x - L.ox) / L.scale, my = (y - L.oy) / L.scale; | 54 var mx = (x - L.ox) / L.scale, my = (y - L.oy) / L.scale; |
| 47 if (mx < 0 || my < 0 || mx > game.map.width || my > game.map.height) return; | 55 if (mx < 0 || my < 0 || mx > game.map.width || my > game.map.height) return; |
| 48 var hitR = Math.max(MM.config.placement.footprint_radius, PREVIEW_HIT / L.scale); | 56 var hitR = Math.max(MM.config.placement.footprint_radius, PREVIEW_HIT / L.scale); |
| 49 if (!game.tapMap(mx, my, hitR)) { | 57 if (!game.tapMap(mx, my, hitR)) { |
| 50 MM.audio.play("placement_refused"); | 58 MM.audio.play("placement_refused"); |
