wobblyhead hg > minor_monsters
comparison game/js/input.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 | c1c7e4f54bf6 |
comparison
equal
deleted
inserted
replaced
| 12:dc314bfbb1cf | 13:8df95050fc8b |
|---|---|
| 98 // the play button starts the sound. switching sound on or off | 98 // the play button starts the sound. switching sound on or off |
| 99 // comes first, so the tap is heard when it goes on | 99 // comes first, so the tap is heard when it goes on |
| 100 if (b.id === "play") MM.audio.start(); | 100 if (b.id === "play") MM.audio.start(); |
| 101 if (b.id === "sound") MM.audio.toggle(); | 101 if (b.id === "sound") MM.audio.toggle(); |
| 102 MM.audio.play("button_tap"); | 102 MM.audio.play("button_tap"); |
| 103 // any other button cancels an armed sell | 103 // any other button cancels an armed sell, and any button outside |
| 104 // the tower menu closes it | |
| 104 if (b.id !== "sell") game.sellArmed = false; | 105 if (b.id !== "sell") game.sellArmed = false; |
| 106 if (b.id !== "sell" && b.id !== "upgrade") game.selected = null; | |
| 105 if (b.id === "play") app.play(); | 107 if (b.id === "play") app.play(); |
| 106 else if (b.id === "next") app.next(); | 108 else if (b.id === "next") app.next(); |
| 107 else if (b.id === "retry") app.retry(); | 109 else if (b.id === "retry") app.retry(); |
| 108 else if (b.id === "restart") app.restart(); | 110 else if (b.id === "restart") app.restart(); |
| 109 else if (b.id === "pause") game.togglePause(); | 111 else if (b.id === "pause") game.togglePause(); |
| 110 else if (b.id === "speed") game.speedIndex = (game.speedIndex + 1) % game.speeds.length; | 112 else if (b.id === "speed") game.speedIndex = (game.speedIndex + 1) % game.speeds.length; |
| 111 else if (b.id === "early") game.startEarly(); | 113 else if (b.id === "early") game.startEarly(); |
| 112 else if (b.id === "shop" && game.canAfford(MM.config.tower[b.tower].cost)) game.chooseShop(b.tower); | 114 else if (b.id === "shop" && !game.paused && game.canAfford(MM.config.tower[b.tower].cost)) game.chooseShop(b.tower); |
| 113 else if (b.id === "upgrade") game.upgrade(); | 115 else if (b.id === "upgrade") game.upgrade(); |
| 114 else if (b.id === "sell") game.sell(); | 116 else if (b.id === "sell") game.sell(); |
| 115 return null; | 117 return null; |
| 116 } | 118 } |
| 117 if (game.result || game.splash) return null; | 119 if (game.result || game.paused) return null; |
| 118 var m = mapPos(game, L, x, y); | 120 var m = mapPos(game, L, x, y); |
| 119 if (!m) return null; | 121 if (!m) { |
| 122 game.sellArmed = false; | |
| 123 game.selected = null; | |
| 124 return null; | |
| 125 } | |
| 120 var hitR = Math.max(MM.config.placement.footprint_radius, PREVIEW_HIT / L.scale); | 126 var hitR = Math.max(MM.config.placement.footprint_radius, PREVIEW_HIT / L.scale); |
| 121 var kind = game.pressMap(m.x, m.y, hitR); | 127 var kind = game.pressMap(m.x, m.y, hitR); |
| 122 if (!kind) return null; | 128 if (!kind) return null; |
| 123 var d = { game: game, onPreview: kind === "preview", moved: false, found: false, | 129 var d = { game: game, onPreview: kind === "preview", moved: false, found: false, |
| 124 sx: x, sy: y, dx: 0, dy: 0 }; | 130 sx: x, sy: y, dx: 0, dy: 0 }; |
| 148 | 154 |
| 149 // the pointer of a drag was released at css position x, y. a tap on the | 155 // the pointer of a drag was released at css position x, y. a tap on the |
| 150 // preview builds; a drag that never found a legal position is refused | 156 // preview builds; a drag that never found a legal position is refused |
| 151 function release(app, d, x, y) { | 157 function release(app, d, x, y) { |
| 152 var game = app.game(), L = app.layout(); | 158 var game = app.game(), L = app.layout(); |
| 153 if (game !== d.game || game.result) return; | 159 if (game !== d.game || game.result || game.paused) return; |
| 154 var ok = d.onPreview && !d.moved ? game.build() : d.found; | 160 var ok = d.onPreview && !d.moved ? game.build() : d.found; |
| 155 if (ok) return; | 161 if (ok) return; |
| 156 MM.audio.play("placement_refused"); | 162 MM.audio.play("placement_refused"); |
| 157 app.view.refused = { x: (x - L.ox) / L.scale, y: (y - L.oy) / L.scale, | 163 app.view.refused = { x: (x - L.ox) / L.scale, y: (y - L.oy) / L.scale, |
| 158 until: performance.now() + REFUSED_TIME }; | 164 until: performance.now() + REFUSED_TIME }; |
