wobblyhead hg > minor_monsters
comparison game/js/main.js @ 32:85d23328a215 0.10.0
added intro music, logic for browser audio triggering on splash screen
| author | ark |
|---|---|
| date | 2026-10-20 18:39 +0200 |
| parents | 75deda08db90 |
| children |
comparison
equal
deleted
inserted
replaced
| 31:d1ae50439686 | 32:85d23328a215 |
|---|---|
| 26 var seed = start.seed || (Math.random() * 4294967296) >>> 0; | 26 var seed = start.seed || (Math.random() * 4294967296) >>> 0; |
| 27 game = new MM.Game(m, seed, m === FIRST ? start.wave : 1); | 27 game = new MM.Game(m, seed, m === FIRST ? start.wave : 1); |
| 28 resize(); | 28 resize(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 // the splash screen over the paused first map | 31 // the splash screen over the paused first map, with the intro music. |
| 32 function splash() { | 32 // browsers start sound only in a user interaction, so on the first |
| 33 // splash screen, unless sound is switched off, a sound button covers | |
| 34 // the play button until it is tapped. sound is unlocked when the | |
| 35 // splash screen returns after a won game. | |
| 36 function splash(first) { | |
| 33 startMap(FIRST); | 37 startMap(FIRST); |
| 34 game.splash = true; | 38 game.splash = true; |
| 35 game.paused = true; | 39 game.paused = true; |
| 40 if (first && MM.audio.enabled()) game.askSound = true; | |
| 41 else MM.audio.playMusic("intro"); | |
| 42 } | |
| 43 | |
| 44 function startSound() { | |
| 45 MM.audio.start(); | |
| 46 game.askSound = false; | |
| 47 MM.audio.playMusic("intro"); | |
| 36 } | 48 } |
| 37 | 49 |
| 38 function play() { | 50 function play() { |
| 51 MM.audio.stopMusic(); | |
| 39 game.splash = false; | 52 game.splash = false; |
| 40 game.paused = false; | 53 game.paused = false; |
| 41 } | 54 } |
| 42 | 55 |
| 43 // canvas resolution follows the device pixel ratio | 56 // canvas resolution follows the device pixel ratio |
| 87 MM.input.attach({ | 100 MM.input.attach({ |
| 88 canvas: canvas, | 101 canvas: canvas, |
| 89 view: view, | 102 view: view, |
| 90 game: function () { return game; }, | 103 game: function () { return game; }, |
| 91 layout: function () { return L; }, | 104 layout: function () { return L; }, |
| 105 startSound: startSound, | |
| 92 play: play, | 106 play: play, |
| 93 next: function () { startMap(game.map.index + 1); }, | 107 next: function () { startMap(game.map.index + 1); }, |
| 94 retry: function () { startMap(FIRST); }, | 108 retry: function () { startMap(FIRST); }, |
| 95 restart: splash | 109 restart: function () { splash(false); } |
| 96 }); | 110 }); |
| 97 MM.assets.load(function (failed) { | 111 MM.assets.load(function (failed) { |
| 98 if (failed.length) console.error("images not loaded:", failed); | 112 if (failed.length) console.error("images not loaded:", failed); |
| 99 splash(); | 113 splash(true); |
| 100 requestAnimationFrame(frame); | 114 requestAnimationFrame(frame); |
| 101 }); | 115 }); |
| 102 })(); | 116 })(); |
