diff --git a/.jshintrc b/.jshintrc index e4b8122..a320d44 100644 --- a/.jshintrc +++ b/.jshintrc @@ -88,6 +88,7 @@ "globals" : { "game": true, "jsfxr": true, - "Stats": true + "Stats": true, + "sonantx": true } } diff --git a/README.md b/README.md index 85cfc4d..1a399bd 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ You can try it [here](http://fewa.comformity.hu/) **Game sound inspired by:** [@jackrugile](https://twitter.com/jackrugile) (http://codepen.io/jackrugile/blog/arcade-audio-for-js13k-games) -**Game music** Sonant-X (https://github.com/nicolas-van/sonant-x) +**Game music:** Sonant-X (https://github.com/nicolas-van/sonant-x) by nicolas-van **Game random number utility inspired by:** # JS13KGames Boilerplate (https://github.com/ooflorent/js13k-boilerplate/blob/master/src/rng.js) diff --git a/app/index.html b/app/index.html index 6c8f2a4..1a833a0 100644 --- a/app/index.html +++ b/app/index.html @@ -45,6 +45,9 @@

Credits

(http://codepen.io/jackrugile/blog/arcade-audio-for-js13k-games)

+

Game music: Sonant-X (https://github.com/nicolas-van/sonant-x) by @nicolas-van +

+

Game random number utility inspired by: # JS13KGames Boilerplate (https://github.com/ooflorent/js13k-boilerplate/blob/master/src/rng.js)

diff --git a/app/scripts/core.js b/app/scripts/core.js index ff48310..5b6dab1 100644 --- a/app/scripts/core.js +++ b/app/scripts/core.js @@ -62,6 +62,12 @@ }, mute: function () { game.audio.mute = !game.audio.mute; + for (var track in game.music.pool) { + if (game.music.pool.hasOwnProperty(track)) { + var music = game.music.pool[track]; + music.volume(game.audio.mute ? 0 : 0.4); + } + } }, menu: function (resume) { game.paused = true; @@ -431,6 +437,12 @@ }, init: function () { + game.music.generate('main', function (music) { + music.loop = true; + music.volume(0.4); + music.start(); + }); + game.obj.extend(true, game, { ww: window.innerWidth, wh: window.innerHeight, @@ -496,15 +508,6 @@ game.stats(); game.menu(); - var audioCtx = new AudioContext(); - var songGen = new sonantx.MusicGenerator(song); - songGen.createAudioBuffer(function(buffer) { - var source = audioCtx.createBufferSource(); // Create Sound Source - source.buffer = buffer; // Add Buffered Data to Object - source.connect(audioCtx.destination); // Connect Sound Source to Output - source.start(); - }); - } }); diff --git a/app/scripts/music.js b/app/scripts/music.js index 42c5bc3..122074f 100644 --- a/app/scripts/music.js +++ b/app/scripts/music.js @@ -1,1175 +1,981 @@ (function () { "use strict"; - window.song = { - "songLen": 145, - "songData": [ - { - "osc1_oct": 9, - "osc1_det": 0, - "osc1_detune": 0, - "osc1_xenv": 0, - "osc1_vol": 161, - "osc1_waveform": 0, - "osc2_oct": 9, - "osc2_det": 0, - "osc2_detune": 4, - "osc2_xenv": 0, - "osc2_vol": 182, - "osc2_waveform": 0, - "noise_fader": 0, - "env_attack": 100, - "env_sustain": 1818, - "env_release": 18181, - "env_master": 192, - "fx_filter": 0, - "fx_freq": 0, - "fx_resonance": 254, - "fx_delay_time": 6, - "fx_delay_amt": 108, - "fx_pan_freq": 3, - "fx_pan_amt": 61, - "lfo_osc1_freq": 0, - "lfo_fx_freq": 0, - "lfo_freq": 3, - "lfo_amt": 94, - "lfo_waveform": 2, - "p": [ - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 0, - 2, - 3, - 4, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 5 - ], - "c": [ - { - "n": [ - 142, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 140, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 138, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - }, - { - "n": [ - 135, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 135, - 0, - 0, - 0, - 138, - 0, - 0, - 0 - ] - }, - { - "n": [ - 140, - 0, - 138, - 0, - 135, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 130, - 0, - 142, - 0, - 140, - 0, - 135, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 138, - 0, - 0, - 0 - ] - }, - { - "n": [ - 135, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 130, - 0, - 142, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 135, - 0, - 0, - 0, - 138, - 0, - 0, - 0 - ] - }, - { - "n": [ - 123, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - }, - { - "n": [ - 130, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - }, - { - "n": [ - 128, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - }, - { - "n": [ - 119, - 131, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 126, - 114, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - } - ] - }, - { - "osc1_oct": 8, - "osc1_det": 0, - "osc1_detune": 0, - "osc1_xenv": 0, - "osc1_vol": 0, - "osc1_waveform": 0, - "osc2_oct": 8, - "osc2_det": 0, - "osc2_detune": 0, - "osc2_xenv": 0, - "osc2_vol": 0, - "osc2_waveform": 0, - "noise_fader": 19, - "env_attack": 100, - "env_sustain": 0, - "env_release": 3636, - "env_master": 192, - "fx_filter": 1, - "fx_freq": 8100, - "fx_resonance": 156, - "fx_delay_time": 2, - "fx_delay_amt": 22, - "fx_pan_freq": 3, - "fx_pan_amt": 43, - "lfo_osc1_freq": 0, - "lfo_fx_freq": 0, - "lfo_freq": 0, - "lfo_amt": 0, - "lfo_waveform": 0, - "p": [ - 0, - 0, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2 - ], - "c": [ - { - "n": [ - 135, - 0, - 135, - 0, - 0, - 135, - 0, - 135, - 135, - 0, - 135, - 0, - 0, - 135, - 0, - 135, - 135, - 0, - 135, - 0, - 0, - 135, - 0, - 135, - 135, - 0, - 135, - 0, - 0, - 135, - 0, - 135 - ] - }, - { - "n": [ - 135, - 0, - 135, - 0, - 0, - 135, - 0, - 135, - 135, - 0, - 135, - 0, - 0, - 135, - 0, - 135, - 135, - 0, - 135, - 0, - 0, - 135, - 0, - 135, - 135, - 0, - 135, - 0, - 135, - 0, - 135, - 135 - ] + + game.music = { + generate: function (name, cb) { + var audioCtx = new AudioContext(); + var songGen = new sonantx.MusicGenerator(this.tracks[name]); + + songGen.createAudioBuffer(function (buffer) { + var source = audioCtx.createBufferSource(), + gainNode = audioCtx.createGain(); + + source.buffer = buffer; + source.connect(gainNode); + gainNode.connect(audioCtx.destination); + source.volume = function (vol) { + if (vol > -1) { + gainNode.gain.value = vol; + } else { + return gainNode.gain.value; } - ] - }, - { - "osc1_oct": 6, - "osc1_det": 0, - "osc1_detune": 0, - "osc1_xenv": 0, - "osc1_vol": 192, - "osc1_waveform": 1, - "osc2_oct": 8, - "osc2_det": 0, - "osc2_detune": 8, - "osc2_xenv": 0, - "osc2_vol": 82, - "osc2_waveform": 2, - "noise_fader": 0, - "env_attack": 100, - "env_sustain": 4545, - "env_release": 2727, - "env_master": 192, - "fx_filter": 3, - "fx_freq": 2700, - "fx_resonance": 85, - "fx_delay_time": 6, - "fx_delay_amt": 60, - "fx_pan_freq": 6, - "fx_pan_amt": 86, - "lfo_osc1_freq": 0, - "lfo_fx_freq": 1, - "lfo_freq": 7, - "lfo_amt": 106, - "lfo_waveform": 0, - "p": [ - 0, - 0, - 0, - 0, - 1, - 1, - 2, - 3, - 1, - 1, - 2, - 3, - 1, - 1, - 2, - 3, - 1, - 1, - 2, - 3, - 1, - 1, - 2, - 3 - ], - "c": [ + }; + this.pool[name] = source; + cb(source); + }.bind(this)); + }, + pool: {}, + tracks: { + main: { + "songLen": 198, + "songData": [ { - "n": [ - 135, - 135, - 147, - 135, - 0, - 135, - 147, - 135, - 135, - 135, - 147, - 135, - 0, - 135, - 147, - 135, - 135, - 135, - 147, - 135, - 0, - 135, - 147, - 135, - 135, - 135, - 147, - 135, - 0, - 135, - 147, - 135 + "osc1_oct": 9, + "osc1_det": 0, + "osc1_detune": 0, + "osc1_xenv": 0, + "osc1_vol": 161, + "osc1_waveform": 0, + "osc2_oct": 9, + "osc2_det": 0, + "osc2_detune": 4, + "osc2_xenv": 0, + "osc2_vol": 182, + "osc2_waveform": 0, + "noise_fader": 0, + "env_attack": 100, + "env_sustain": 1818, + "env_release": 18181, + "env_master": 192, + "fx_filter": 0, + "fx_freq": 0, + "fx_resonance": 254, + "fx_delay_time": 6, + "fx_delay_amt": 108, + "fx_pan_freq": 3, + "fx_pan_amt": 61, + "lfo_osc1_freq": 0, + "lfo_fx_freq": 0, + "lfo_freq": 3, + "lfo_amt": 94, + "lfo_waveform": 2, + "p": [ + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 0, + 2, + 3, + 4, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 1, + 2, + 1, + 2, + 3, + 4, + 5, + 6, + 5, + 6, + 7, + 8 + ], + "c": [ + { + "n": [ + 142, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 140, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 138, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] + }, + { + "n": [ + 135, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 135, + 0, + 0, + 0, + 138, + 0, + 0, + 0 + ] + }, + { + "n": [ + 140, + 0, + 138, + 0, + 135, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 130, + 0, + 142, + 0, + 140, + 0, + 135, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 138, + 0, + 0, + 0 + ] + }, + { + "n": [ + 135, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 130, + 0, + 142, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 135, + 0, + 0, + 0, + 138, + 0, + 0, + 0 + ] + }, + { + "n": [ + 123, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] + }, + { + "n": [ + 130, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] + }, + { + "n": [ + 128, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] + }, + { + "n": [ + 119, + 131, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 126, + 114, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] + } ] }, { - "n": [ - 140, - 140, - 152, - 140, - 0, - 140, - 152, - 140, - 140, - 140, - 152, - 140, - 0, - 140, - 152, - 140, - 140, - 140, - 152, - 140, - 0, - 140, - 152, - 140, - 140, - 140, - 152, - 140, - 0, - 140, - 152, - 142 + "osc1_oct": 8, + "osc1_det": 0, + "osc1_detune": 0, + "osc1_xenv": 0, + "osc1_vol": 0, + "osc1_waveform": 0, + "osc2_oct": 8, + "osc2_det": 0, + "osc2_detune": 0, + "osc2_xenv": 0, + "osc2_vol": 0, + "osc2_waveform": 0, + "noise_fader": 19, + "env_attack": 100, + "env_sustain": 0, + "env_release": 3636, + "env_master": 192, + "fx_filter": 1, + "fx_freq": 8100, + "fx_resonance": 156, + "fx_delay_time": 2, + "fx_delay_amt": 22, + "fx_pan_freq": 3, + "fx_pan_amt": 43, + "lfo_osc1_freq": 0, + "lfo_fx_freq": 0, + "lfo_freq": 0, + "lfo_amt": 0, + "lfo_waveform": 0, + "p": [ + 0, + 0, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2 + ], + "c": [ + { + "n": [ + 135, + 0, + 135, + 0, + 0, + 135, + 0, + 135, + 135, + 0, + 135, + 0, + 0, + 135, + 0, + 135, + 135, + 0, + 135, + 0, + 0, + 135, + 0, + 135, + 135, + 0, + 135, + 0, + 0, + 135, + 0, + 135 + ] + }, + { + "n": [ + 135, + 0, + 135, + 0, + 0, + 135, + 0, + 135, + 135, + 0, + 135, + 0, + 0, + 135, + 0, + 135, + 135, + 0, + 135, + 0, + 0, + 135, + 0, + 135, + 135, + 0, + 135, + 0, + 135, + 0, + 135, + 135 + ] + } ] }, { - "n": [ - 131, - 131, - 143, - 131, - 0, - 131, - 143, - 131, - 131, - 131, - 143, - 131, - 0, - 131, - 143, - 131, - 138, - 138, - 150, - 138, - 0, - 138, - 150, - 138, - 138, - 138, - 150, - 138, - 0, - 138, - 150, - 137 - ] - } - ] - }, - { - "osc1_oct": 7, - "osc1_det": 0, - "osc1_detune": 0, - "osc1_xenv": 0, - "osc1_vol": 187, - "osc1_waveform": 2, - "osc2_oct": 5, - "osc2_det": 0, - "osc2_detune": 2, - "osc2_xenv": 1, - "osc2_vol": 161, - "osc2_waveform": 2, - "noise_fader": 0, - "env_attack": 100, - "env_sustain": 1818, - "env_release": 2727, - "env_master": 123, - "fx_filter": 1, - "fx_freq": 1900, - "fx_resonance": 162, - "fx_delay_time": 2, - "fx_delay_amt": 153, - "fx_pan_freq": 6, - "fx_pan_amt": 61, - "lfo_osc1_freq": 0, - "lfo_fx_freq": 1, - "lfo_freq": 2, - "lfo_amt": 196, - "lfo_waveform": 3, - "p": [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 1, - 1, - 2, - 1, - 1, - 1, - 2, - 1, - 1, - 1, - 2, - 1, - 1, - 1, - 2, - 1, - 1, - 1, - 2, - 3 - ], - "c": [ - { - "n": [ - 135, - 135, - 138, - 135, - 142, - 135, - 140, - 138, - 135, - 135, - 138, - 135, - 142, - 135, - 140, - 138, - 135, - 135, - 138, - 135, - 142, - 135, - 140, - 138, - 135, - 135, - 138, - 135, - 142, - 135, - 140, - 138 + "osc1_oct": 6, + "osc1_det": 0, + "osc1_detune": 0, + "osc1_xenv": 0, + "osc1_vol": 192, + "osc1_waveform": 1, + "osc2_oct": 8, + "osc2_det": 0, + "osc2_detune": 8, + "osc2_xenv": 0, + "osc2_vol": 82, + "osc2_waveform": 2, + "noise_fader": 0, + "env_attack": 100, + "env_sustain": 4545, + "env_release": 2727, + "env_master": 192, + "fx_filter": 3, + "fx_freq": 2700, + "fx_resonance": 85, + "fx_delay_time": 6, + "fx_delay_amt": 60, + "fx_pan_freq": 6, + "fx_pan_amt": 86, + "lfo_osc1_freq": 0, + "lfo_fx_freq": 1, + "lfo_freq": 7, + "lfo_amt": 106, + "lfo_waveform": 0, + "p": [ + 0, + 0, + 0, + 0, + 1, + 1, + 2, + 3, + 1, + 1, + 2, + 3, + 1, + 1, + 2, + 3, + 1, + 1, + 2, + 3, + 1, + 1, + 2, + 3, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 2, + 3 + ], + "c": [ + { + "n": [ + 135, + 135, + 147, + 135, + 0, + 135, + 147, + 135, + 135, + 135, + 147, + 135, + 0, + 135, + 147, + 135, + 135, + 135, + 147, + 135, + 0, + 135, + 147, + 135, + 135, + 135, + 147, + 135, + 0, + 135, + 147, + 135 + ] + }, + { + "n": [ + 140, + 140, + 152, + 140, + 0, + 140, + 152, + 140, + 140, + 140, + 152, + 140, + 0, + 140, + 152, + 140, + 140, + 140, + 152, + 140, + 0, + 140, + 152, + 140, + 140, + 140, + 152, + 140, + 0, + 140, + 152, + 142 + ] + }, + { + "n": [ + 131, + 131, + 143, + 131, + 0, + 131, + 143, + 131, + 131, + 131, + 143, + 131, + 0, + 131, + 143, + 131, + 138, + 138, + 150, + 138, + 0, + 138, + 150, + 138, + 138, + 138, + 150, + 138, + 0, + 138, + 150, + 137 + ] + } ] }, { - "n": [ - 143, - 143, - 155, - 143, - 0, - 143, - 155, - 143, - 143, - 143, - 150, - 143, - 147, - 143, - 140, - 143, - 138, - 138, - 143, - 138, - 143, - 140, - 138, - 140, - 138, - 138, - 143, - 138, - 142, - 140, - 138, - 140 + "osc1_oct": 7, + "osc1_det": 0, + "osc1_detune": 0, + "osc1_xenv": 0, + "osc1_vol": 187, + "osc1_waveform": 2, + "osc2_oct": 5, + "osc2_det": 0, + "osc2_detune": 2, + "osc2_xenv": 1, + "osc2_vol": 161, + "osc2_waveform": 2, + "noise_fader": 0, + "env_attack": 100, + "env_sustain": 1818, + "env_release": 2727, + "env_master": 123, + "fx_filter": 1, + "fx_freq": 1900, + "fx_resonance": 162, + "fx_delay_time": 2, + "fx_delay_amt": 153, + "fx_pan_freq": 6, + "fx_pan_amt": 61, + "lfo_osc1_freq": 0, + "lfo_fx_freq": 1, + "lfo_freq": 2, + "lfo_amt": 196, + "lfo_waveform": 3, + "p": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 2, + 1, + 1, + 1, + 2, + 1, + 1, + 1, + 2, + 1, + 1, + 1, + 2, + 1, + 1, + 1, + 2, + 1, + 1, + 1, + 1, + 1, + 2, + 1, + 1, + 1, + 1, + 1, + 2 + ], + "c": [ + { + "n": [ + 135, + 135, + 138, + 135, + 142, + 135, + 140, + 138, + 135, + 135, + 138, + 135, + 142, + 135, + 140, + 138, + 135, + 135, + 138, + 135, + 142, + 135, + 140, + 138, + 135, + 135, + 138, + 135, + 142, + 135, + 140, + 138 + ] + }, + { + "n": [ + 143, + 143, + 155, + 143, + 0, + 143, + 155, + 143, + 143, + 143, + 150, + 143, + 147, + 143, + 140, + 143, + 138, + 138, + 143, + 138, + 143, + 140, + 138, + 140, + 138, + 138, + 143, + 138, + 142, + 140, + 138, + 140 + ] + } ] }, { - "n": [ - 135, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - } - ] - }, - { - "osc1_oct": 8, - "osc1_det": 0, - "osc1_detune": 0, - "osc1_xenv": 1, - "osc1_vol": 192, - "osc1_waveform": 0, - "osc2_oct": 7, - "osc2_det": 0, - "osc2_detune": 0, - "osc2_xenv": 1, - "osc2_vol": 70, - "osc2_waveform": 2, - "noise_fader": 8, - "env_attack": 100, - "env_sustain": 0, - "env_release": 9090, - "env_master": 164, - "fx_filter": 2, - "fx_freq": 5500, - "fx_resonance": 240, - "fx_delay_time": 6, - "fx_delay_amt": 51, - "fx_pan_freq": 3, - "fx_pan_amt": 66, - "lfo_osc1_freq": 0, - "lfo_fx_freq": 0, - "lfo_freq": 0, - "lfo_amt": 0, - "lfo_waveform": 0, - "p": [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1 - ], - "c": [ - { - "n": [ - 135, - 0, - 0, - 0, - 0, - 0, - 135, - 0, - 0, - 0, - 135, - 0, - 0, - 0, - 0, - 0, - 135, - 0, - 0, - 0, - 0, - 0, - 135, - 0, - 0, - 0, - 135, - 0, - 0, - 0, - 0, - 0 + "osc1_oct": 8, + "osc1_det": 0, + "osc1_detune": 0, + "osc1_xenv": 1, + "osc1_vol": 192, + "osc1_waveform": 0, + "osc2_oct": 7, + "osc2_det": 0, + "osc2_detune": 0, + "osc2_xenv": 1, + "osc2_vol": 70, + "osc2_waveform": 2, + "noise_fader": 8, + "env_attack": 100, + "env_sustain": 0, + "env_release": 9090, + "env_master": 164, + "fx_filter": 2, + "fx_freq": 5500, + "fx_resonance": 240, + "fx_delay_time": 6, + "fx_delay_amt": 51, + "fx_pan_freq": 3, + "fx_pan_amt": 66, + "lfo_osc1_freq": 0, + "lfo_fx_freq": 0, + "lfo_freq": 0, + "lfo_amt": 0, + "lfo_waveform": 0, + "p": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ], + "c": [ + { + "n": [ + 135, + 0, + 0, + 0, + 0, + 0, + 135, + 0, + 0, + 0, + 135, + 0, + 0, + 0, + 0, + 0, + 135, + 0, + 0, + 0, + 0, + 0, + 135, + 0, + 0, + 0, + 135, + 0, + 0, + 0, + 0, + 0 + ] + } ] } - ] - }, - { - "osc1_oct": 7, - "osc1_det": 0, - "osc1_detune": 0, - "osc1_xenv": 0, - "osc1_vol": 192, - "osc1_waveform": 2, - "osc2_oct": 8, - "osc2_det": 0, - "osc2_detune": 6, - "osc2_xenv": 0, - "osc2_vol": 184, - "osc2_waveform": 2, - "noise_fader": 21, - "env_attack": 40000, - "env_sustain": 25454, - "env_release": 90909, - "env_master": 77, - "fx_filter": 2, - "fx_freq": 7100, - "fx_resonance": 188, - "fx_delay_time": 8, - "fx_delay_amt": 147, - "fx_pan_freq": 4, - "fx_pan_amt": 69, - "lfo_osc1_freq": 0, - "lfo_fx_freq": 1, - "lfo_freq": 7, - "lfo_amt": 176, - "lfo_waveform": 1, - "p": [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 2, - 3, - 4, - 1, - 2, - 3, - 4, - 1, - 2, - 3, - 4, - 1, - 2, - 3, - 4, - 5 ], - "c": [ - { - "n": [ - 135, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - }, - { - "n": [ - 142, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - }, - { - "n": [ - 128, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - }, - { - "n": [ - 143, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 138, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - }, - { - "n": [ - 135, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - } - ] + "rowLen": 6615, + "endPattern": 41 } - ], - "rowLen": 6615, - "endPattern": 30 + } }; })(); diff --git a/dist/index.html b/dist/index.html index 8f95ea7..8ccd266 100644 --- a/dist/index.html +++ b/dist/index.html @@ -1 +1 @@ -FEWA
LEVEL: SCORE:

Controls

Swap/Move elements: Click highlighted column to select an element and click to drop to another column

Pause: P, Mute: M,
Stop bg anim: B
(because of performance issues on some devices)

Credits

Created by: Zoltan Pasztor & Csaba Tuncsik

Audio Processing: [JSFXR](https://github.com/mneubrand/jsfxr) by [@markusneubrand](https://twitter.com/markusneubrand)

Game sound inspired by: [@jackrugile](https://twitter.com/jackrugile) (http://codepen.io/jackrugile/blog/arcade-audio-for-js13k-games)

Game random number utility inspired by: # JS13KGames Boilerplate (https://github.com/ooflorent/js13k-boilerplate/blob/master/src/rng.js)

FEWA

  • RESUME
  • NEW GAME
  • HELP
  • CREDITS
\ No newline at end of file +FEWA
LEVEL: SCORE:

Controls

Swap/Move elements: Click highlighted column to select an element and click to drop to another column

Pause: P, Mute: M,
Stop bg anim: B
(because of performance issues on some devices)

Credits

Created by: Zoltan Pasztor & Csaba Tuncsik

Audio Processing: [JSFXR](https://github.com/mneubrand/jsfxr) by [@markusneubrand](https://twitter.com/markusneubrand)

Game sound inspired by: [@jackrugile](https://twitter.com/jackrugile) (http://codepen.io/jackrugile/blog/arcade-audio-for-js13k-games)

Game music: Sonant-X (https://github.com/nicolas-van/sonant-x) by @nicolas-van

Game random number utility inspired by: # JS13KGames Boilerplate (https://github.com/ooflorent/js13k-boilerplate/blob/master/src/rng.js)

FEWA

  • RESUME
  • NEW GAME
  • HELP
  • CREDITS
\ No newline at end of file diff --git a/dist/inlined-compressed.zip b/dist/inlined-compressed.zip index 4b7117a..8e7578d 100644 Binary files a/dist/inlined-compressed.zip and b/dist/inlined-compressed.zip differ diff --git a/dist/j-0a2ea4c1de.js b/dist/j-0a2ea4c1de.js new file mode 100644 index 0000000..045f5d4 --- /dev/null +++ b/dist/j-0a2ea4c1de.js @@ -0,0 +1,3 @@ +!function(){"use strict";function e(){this.setSettings=function(e){for(var t=0;24>t;t++)this[String.fromCharCode(97+t)]=e[t]||0;this.c<.01&&(this.c=.01);var i=this.b+this.c+this.e;if(.18>i){var r=.18/i;this.b*=r,this.c*=r,this.e*=r}}}function t(){this._params=new e;var t,i,r,o,n,s,a,c,l,h,u,f;this.reset=function(){var e=this._params;o=100/(e.f*e.f+.001),n=100/(e.g*e.g+.001),s=1-e.h*e.h*e.h*.01,a=-e.i*e.i*e.i*1e-6,e.a||(u=.5-e.n/2,f=5e-5*-e.o),c=1+e.l*e.l*(e.l>0?-.9:10),l=0,h=1==e.m?0:(1-e.m)*(1-e.m)*2e4+32},this.totalReset=function(){this.reset();var e=this._params;return t=e.b*e.b*1e5,i=e.c*e.c*1e5,r=e.e*e.e*1e5+12,3*((t+i+r)/3|0)},this.synthWave=function(e,d){var m=this._params,p=1!=m.s||m.v,v=m.v*m.v*.1,g=1+3e-4*m.w,b=m.s*m.s*m.s*.1,y=1+1e-4*m.t,w=1!=m.s,k=m.x*m.x,x=m.g,_=m.q||m.r,A=m.r*m.r*m.r*.2,W=m.q*m.q*(m.q<0?-1020:1020),R=m.p?((1-m.p)*(1-m.p)*2e4|0)+32:0,T=m.d,E=m.j/2,C=m.k*m.k*.01,H=m.a,I=t,S=1/t,M=1/i,q=1/r,B=5/(1+m.u*m.u*20)*(.01+b);B>.8&&(B=.8),B=1-B;for(var D,F,L,G,P,j,O=!1,K=0,z=0,U=0,N=0,V=0,X=0,J=0,Q=0,Y=0,Z=0,$=new Array(1024),ee=new Array(32),te=$.length;te--;)$[te]=0;for(var te=ee.length;te--;)ee[te]=2*Math.random()-1;for(var te=0;d>te;te++){if(O)return te;if(R&&++Y>=R&&(Y=0,this.reset()),h&&++l>=h&&(h=0,o*=c),s+=a,o*=s,o>n&&(o=n,x>0&&(O=!0)),F=o,E>0&&(Z+=C,F*=1+Math.sin(Z)*E),F|=0,8>F&&(F=8),H||(u+=f,0>u?u=0:u>.5&&(u=.5)),++z>I)switch(z=0,++K){case 1:I=i;break;case 2:I=r}switch(K){case 0:U=z*S;break;case 1:U=1+2*(1-z*M)*T;break;case 2:U=1-z*q;break;case 3:U=0,O=!0}_&&(W+=A,L=0|W,0>L?L=-L:L>1023&&(L=1023)),p&&g&&(v*=g,1e-5>v?v=1e-5:v>.1&&(v=.1)),j=0;for(var ie=8;ie--;){if(J++,J>=F&&(J%=F,3==H))for(var re=ee.length;re--;)ee[re]=2*Math.random()-1;switch(H){case 0:P=u>J/F?.5:-.5;break;case 1:P=1-J/F*2;break;case 2:G=J/F,G=6.28318531*(G>.5?G-1:G),P=1.27323954*G+.405284735*G*G*(0>G?1:-1),P=.225*((0>P?-1:1)*P*P-P)+P;break;case 3:P=ee[Math.abs(32*J/F|0)]}p&&(D=X,b*=y,0>b?b=0:b>.1&&(b=.1),w?(V+=(P-X)*b,V*=B):(X=P,V=0),X+=V,N+=X-D,N*=1-v,P=N),_&&($[Q%1024]=P,P+=$[(Q-L+1024)%1024],Q++),j+=P}j*=.125*U*k,e[te]=j>=1?32767:-1>=j?-32768:32767*j|0}return d}}for(var i={},r=0,o=["webkit","moz","o","ms"],n=0;nl;++l)if(e=arguments[l],null!==e)for(t in e)o=c[t],n=e[t],c!==n&&(u&&n&&(i(n)||(s=Array.isArray(n)))?(s?(s=!1,a=o&&Array.isArray(o)?o:[]):a=o&&i(o)?o:{},c[t]=r(u,a,n)):void 0!==n&&(c[t]=n));return c}}()},i.obj.extend(!0,i,{vendor:{prefixes:["","ms","webkit","moz","o"],get:function(e){var t,i;for(i=0;io;o+=1)i="undefined"==typeof t?[]:t,r.push(i);return r},move:function(e,t,i){e[t]=e.splice(i,1,e[t])[0]},loop:function(e,t,i){for(var r=e.length,o=0;r>o;o+=1)t.call(i||null,e[o],o)}},rand:{intg:function(e){return Math.random()*(e||268435455)|0},flot:function(){return Math.random()},bool:function(){return Math.random()>.5},range:function(e,t){return i.rand.intg(t-e)+e},rangef:function(e,t){return i.rand.flot()*(t-e)+e},select:function(e){return e[i.rand.range(0,e.length)]}},PI2:2*Math.PI,RAD:Math.PI/180,DEG:180/Math.PI,noop:function(){},line:function(e,t,i,r,o,n,s){e.strokeStyle=n,e.lineWidth=s,e.beginPath(),e.moveTo(t,i),e.lineTo(r,o),e.stroke()},rect:function(e,t,r,o,n,s,a,c,l,h){t+=c,o-=2*c,r+=c,n-=2*c,e.beginPath(),e.strokeStyle=a,e.lineWidth=c,e.moveTo(t+s,r),e.lineTo(t+o-s,r),e.quadraticCurveTo(t+o,r,t+o,r+s),e.lineTo(t+o,r+n-s),e.quadraticCurveTo(t+o,r+n,t+o-s,r+n),e.lineTo(t+s,r+n),e.quadraticCurveTo(t,r+n,t,r+n-s),e.lineTo(t,r+s),e.quadraticCurveTo(t,r,t+s,r),e.closePath(),e.stroke(),l&&(e.fillStyle=l,e.fill()),h&&i.rect(e,t-c,r-c,o+2*c,n+2*c,1.2*s,h,c/2)},sine:function(e,t,i,r,o,n,s){var a=(t+r)/2,c=(i+o)/2;e.strokeStyle=n,e.lineWidth=s,e.beginPath(),e.moveTo(t,i),e.bezierCurveTo(t,i,a/2,1.5*c,a,c),e.bezierCurveTo(1.5*a,c/2,r,o,r,o),e.stroke()}}),i.obj.extend(!0,i,{columns:8,gap:2,speed:.1,gravity:.3,moveBg:!0,rumble:{decay:.4},starAmount:Math.floor(window.innerWidth/window.innerHeight*100),starColors:["#ffffff","#ffe9c4","#d4fbff"],elements:{FIRE:{color:"#ff3824",latency:50,against:{FIRE:20,EARTH:2,WATER:1,AIR:5},bricks:{empty:{energy:10},filled:{energy:20},special:{energy:40}},desc:"The Fire element, most effective against fire bricks, but least effective against water bricks.",spec:"Fire special brick explodes the whole column of bricks."},EARTH:{color:"#44db5e",latency:80,against:{FIRE:5,EARTH:20,WATER:2,AIR:1},bricks:{empty:{energy:10},filled:{energy:20},special:{energy:40}},desc:"The Earth element, most effective against earth bricks, but least effective against air bricks.",spec:"Earth special brick explodes surrounding bricks."},WATER:{color:"#54c7fc",latency:70,against:{FIRE:1,EARTH:2,WATER:20,AIR:5},bricks:{empty:{energy:10},filled:{energy:20},special:{energy:40}},desc:"The Water element, most effective against water bricks, but least effective against fire bricks.",spec:"Water special brick explodes the whole row of bricks."},AIR:{color:"#ffcd00",latency:60,against:{FIRE:5,EARTH:1,WATER:2,AIR:20},bricks:{empty:{energy:10},filled:{energy:20},special:{energy:40}},desc:"The Air element, most effective against air bricks, but least effective against earth bricks.",spec:"Air special brick explodes all the weak(stroked) air bricks."}}}),i.sprite={items:{},create:function(e,t,i,r){if(!this.get(e)){var o=document.createElement("canvas");o.width=t,o.height=i;var n=o.getContext("2d");n.save(),r(n),n.restore(),this.set(e,o)}return this.get(e)},set:function(e,t){this.items[e]=t},get:function(e){return this.items[e]},factory:function(){var e=i.brickWidth/10,t=i.brickWidth/2,r=i.brickHeight/2,o=i.brickWidth/10,n=e,s="rgba(255,255,255,0.8)",a="rgba(255,255,0,0.5)";this.create("AIR",i.brickWidth,i.brickWidth,function(e){var t=(i.brickWidth-2*o)/4;i.rect(e,0,0,i.brickWidth,i.brickWidth,n,i.elements.AIR.color,o,null,s),e.lineWidth=o,e.strokeStyle=i.elements.AIR.color,e.translate(o,0);for(var r=0;3>r;r++)e.beginPath(),e.moveTo(t,o),e.lineTo(t,i.brickWidth-o),e.stroke(),e.translate(t,0)}),this.create("AIR-SHOT",i.brickWidth,i.brickHeight,function(r){i.rect(r,t-e,0,2*e,i.brickHeight,2,i.elements.AIR.color,o,i.elements.AIR.color,a)}),this.create("AIR-BRICK-empty",i.brickWidth,i.brickHeight,function(e){i.rect(e,0,0,i.brickWidth,i.brickHeight,n,i.elements.AIR.color,o,null,s)}),this.create("AIR-BRICK-filled",i.brickWidth,i.brickHeight,function(e){i.rect(e,0,0,i.brickWidth,i.brickHeight,n,i.elements.AIR.color,o,i.elements.AIR.color,s)}),this.create("AIR-BRICK-special",i.brickWidth,i.brickHeight,function(e){e.fillStyle=i.elements.AIR.color,e.fillRect(t-r/2,o,r,i.brickHeight-2*o),i.rect(e,0,0,i.brickWidth,i.brickHeight,n,i.elements.AIR.color,o,null,s)}),this.create("EARTH",i.brickWidth,i.brickWidth,function(e){var t=(i.brickWidth-2*o)/4;i.rect(e,0,0,i.brickWidth,i.brickWidth,n,i.elements.EARTH.color,o,null,s),e.lineWidth=o,e.strokeStyle=i.elements.EARTH.color,e.translate(0,o);for(var r=0;3>r;r++)e.beginPath(),e.moveTo(o,t),e.lineTo(i.brickWidth-o,t),e.stroke(),e.translate(0,t)}),this.create("EARTH-SHOT",i.brickWidth,i.brickHeight,function(r){i.rect(r,t-e,0,2*e,i.brickHeight,2,i.elements.EARTH.color,o,i.elements.EARTH.color,a)}),this.create("EARTH-BRICK-empty",i.brickWidth,i.brickHeight,function(e){i.rect(e,0,0,i.brickWidth,i.brickHeight,n,i.elements.EARTH.color,o,null,s)}),this.create("EARTH-BRICK-filled",i.brickWidth,i.brickHeight,function(e){i.rect(e,0,0,i.brickWidth,i.brickHeight,n,i.elements.EARTH.color,o,i.elements.EARTH.color,s)}),this.create("EARTH-BRICK-special",i.brickWidth,i.brickHeight,function(e){e.fillStyle=i.elements.EARTH.color,e.fillRect(t-r/2,o,r,i.brickHeight-2*o),i.rect(e,0,0,i.brickWidth,i.brickHeight,n,i.elements.EARTH.color,o,null,s)}),this.create("WATER",i.brickWidth,i.brickWidth,function(e){var t=(i.brickWidth-2*o)/4;i.rect(e,0,0,i.brickWidth,i.brickWidth,n,i.elements.WATER.color,o,null,s),e.lineWidth=o,e.strokeStyle=i.elements.WATER.color,e.translate(0,o);for(var r=0;3>r;r++)i.sine(e,o,t,i.brickWidth-o,t),e.translate(0,t)}),this.create("WATER-SHOT",i.brickWidth,i.brickHeight,function(r){i.rect(r,t-e,0,2*e,i.brickHeight,2,i.elements.WATER.color,o,i.elements.WATER.color,a)}),this.create("WATER-BRICK-empty",i.brickWidth,i.brickHeight,function(e){i.rect(e,0,0,i.brickWidth,i.brickHeight,n,i.elements.WATER.color,o,null,s)}),this.create("WATER-BRICK-filled",i.brickWidth,i.brickHeight,function(e){i.rect(e,0,0,i.brickWidth,i.brickHeight,n,i.elements.WATER.color,o,i.elements.WATER.color,s)}),this.create("WATER-BRICK-special",i.brickWidth,i.brickHeight,function(e){i.line(e,2*o,r,i.brickWidth-2*o,r,i.elements.WATER.color,o),i.rect(e,0,0,i.brickWidth,i.brickHeight,n,i.elements.WATER.color,o,null,s)}),this.create("FIRE",i.brickWidth,i.brickWidth,function(e){var t=(i.brickWidth-2*o)/4;i.rect(e,0,0,i.brickWidth,i.brickWidth,n,i.elements.FIRE.color,o,null,s),e.lineWidth=o,e.strokeStyle=i.elements.FIRE.color,e.translate(-o,0),e.translate(i.brickWidth/2,i.brickWidth/2),e.rotate(90*i.RAD),e.translate(-i.brickWidth/2,-i.brickWidth/2);for(var r=0;3>r;r++)i.sine(e,o,t,i.brickWidth-o,t),e.translate(0,t)}),this.create("FIRE-SHOT",i.brickWidth,i.brickHeight,function(r){i.rect(r,t-e,0,2*e,i.brickHeight,2,i.elements.FIRE.color,o,i.elements.FIRE.color,a)}),this.create("FIRE-BRICK-empty",i.brickWidth,i.brickHeight,function(e){i.rect(e,0,0,i.brickWidth,i.brickHeight,n,i.elements.FIRE.color,o,null,s)}),this.create("FIRE-BRICK-filled",i.brickWidth,i.brickHeight,function(e){i.rect(e,0,0,i.brickWidth,i.brickHeight,n,i.elements.FIRE.color,o,i.elements.FIRE.color,s)}),this.create("FIRE-BRICK-special",i.brickWidth,i.brickHeight,function(e){i.line(e,t,2*o,t,i.brickHeight-2*o,i.elements.FIRE.color,o),i.rect(e,0,0,i.brickWidth,i.brickHeight,n,i.elements.FIRE.color,o,null,s)}),["#ffffff","#ed8500","#ffff00"].forEach(function(e){this.create("explosion"+e,i.brickWidth,i.brickHeight,function(t){i.rect(t,0,0,i.brickWidth,i.brickHeight,0,e,0,e)})},this)}};var s=new t;window.jsfxr=function(e){s._params.setSettings(e);var t=s.totalReset(),i=new Uint8Array(4*((t+1)/2|0)+44),r=2*s.synthWave(new Uint16Array(i.buffer,44),t),o=new Uint32Array(i.buffer,0,44);o[0]=1179011410,o[1]=r+36,o[2]=1163280727,o[3]=544501094,o[4]=16,o[5]=65537,o[6]=44100,o[7]=88200,o[8]=1048578,o[9]=1635017060,o[10]=r,r+=44;for(var n=0,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c="data:audio/wav;base64,";r>n;n+=3){var l=i[n]<<16|i[n+1]<<8|i[n+2];c+=a[l>>18]+a[l>>12&63]+a[l>>6&63]+a[63&l]}return c};var a;!function(){function e(e){return Math.sin(6.283184*e)}function t(t){return e(t)<0?-1:1}function i(e){return e%1-.5}function r(e){var t=e%1*4;return 2>t?t-1:3-t}function o(e){return.00390625*Math.pow(1.059463094,e-128)}function n(e,t){setTimeout(function(){var i=new Uint8Array(e*l*2),r=i.length-2,o=function(){for(var e=new Date,n=0;r>=0;)if(i[r]=0,i[r+1]=128,r-=2,n+=1,n%1e3===0&&new Date-e>h)return void setTimeout(o,0);setTimeout(function(){t(i)},0)};setTimeout(o,0)},0)}function s(e,t,i,r,o){var n=i.fx_delay_time*r>>1,s=i.fx_delay_amt/255,a=0,c=function(){for(var i=new Date,r=0;t-n>a;){var l=4*a,u=4*(a+n),f=e[u]+(e[u+1]<<8)+(e[l+2]+(e[l+3]<<8)-32768)*s;if(e[u]=255&f,e[u+1]=f>>8&255,f=e[u+2]+(e[u+3]<<8)+(e[l]+(e[l+1]<<8)-32768)*s,e[u+2]=255&f,e[u+3]=f>>8&255,++a,r+=1,r%1e3===0&&new Date-i>h)return void setTimeout(c,0)}setTimeout(o,0)};setTimeout(c,0)}a={};var c=44100,l=2,h=33,u=null,f=[e,t,i,r];a.AudioGenerator=function(e){this.mixBuf=e,this.waveSize=e.length/l/2},a.AudioGenerator.prototype.getWave=function(){var e,t,i,r,o,n,s,a=this.mixBuf,c=this.waveSize,h=c*l*2;for(o=h-8,n=o-36,r=String.fromCharCode(82,73,70,70,255&o,o>>8&255,o>>16&255,o>>24&255,87,65,86,69,102,109,116,32,16,0,0,0,1,0,2,0,68,172,0,0,16,177,2,0,4,0,16,0,100,97,116,97,255&n,n>>8&255,n>>16&255,n>>24&255),e=0;h>e;){for(i="",t=0;256>t&&h>e;++t,e+=2)s=4*(a[e]+(a[e+1]<<8)-32768),s=-32768>s?-32768:s>32767?32767:s,i+=String.fromCharCode(255&s,s>>8&255);r+=i}return r},a.AudioGenerator.prototype.getAudio=function(){var e=this.getWave(),t=new Audio("data:audio/wav;base64,"+btoa(e));return t.preload="none",t.load(),t},a.AudioGenerator.prototype.getAudioBuffer=function(e){null===u&&(u=new AudioContext);var t=this.mixBuf,i=this.waveSize,r=u.createBuffer(l,this.waveSize,c),o=r.getChannelData(0),n=r.getChannelData(1),s=0,a=function(){for(var c=new Date,l=0;i>s;){var u=4*(t[4*s]+(t[4*s+1]<<8)-32768);if(u=-32768>u?-32768:u>32767?32767:u,o[s]=u/32768,u=4*(t[4*s+2]+(t[4*s+3]<<8)-32768),u=-32768>u?-32768:u>32767?32767:u,n[s]=u/32768,s+=1,l+=1,l%1e3===0&&new Date-c>h)return void setTimeout(a,0)}setTimeout(function(){e(r)},0)};setTimeout(a,0)},a.SoundGenerator=function(e,t){this.instr=e,this.rowLen=t||5605,this.osc_lfo=f[e.lfo_waveform],this.osc1=f[e.osc1_waveform],this.osc2=f[e.osc2_waveform],this.attack=e.env_attack,this.sustain=e.env_sustain,this.release=e.env_release,this.panFreq=Math.pow(2,e.fx_pan_freq-8)/this.rowLen,this.lfoFreq=Math.pow(2,e.lfo_freq-8)/this.rowLen},a.SoundGenerator.prototype.genSound=function(t,i,r){for(var n=(new Date,0),s=0,a=o(t+12*(this.instr.osc1_oct-8)+this.instr.osc1_det)*(1+8e-4*this.instr.osc1_detune),l=o(t+12*(this.instr.osc2_oct-8)+this.instr.osc2_det)*(1+8e-4*this.instr.osc2_detune),h=this.instr.fx_resonance/255,u=0,f=0,d=this.attack+this.sustain+this.release-1;d>=0;--d){var m=d+r,p=this.osc_lfo(m*this.lfoFreq)*this.instr.lfo_amt/512+.5,v=1;d=this.attack+this.sustain&&(v-=(d-this.attack-this.sustain)/this.release);var g=a;this.instr.lfo_osc1_freq&&(g+=p),this.instr.osc1_xenv&&(g*=v*v),n+=g;var b=this.osc1(n)*this.instr.osc1_vol;g=l,this.instr.osc2_xenv&&(g*=v*v),s+=g,b+=this.osc2(s)*this.instr.osc2_vol,this.instr.noise_fader&&(b+=(2*Math.random()-1)*this.instr.noise_fader*v),b*=v/255;var y=this.instr.fx_freq;this.instr.lfo_fx_freq&&(y*=p),y=1.5*Math.sin(3.141592*y/c),u+=y*f;var w=h*(b-f)-u;switch(f+=y*w,this.instr.fx_filter){case 1:b=w;break;case 2:b=u;break;case 3:b=f;break;case 4:b=u+w}if(g=e(m*this.panFreq)*this.instr.fx_pan_amt/512+.5,b*=39*this.instr.env_master,m=4*m,m+3>8&255,k=i[m+2]+(i[m+3]<<8)+b*g,i[m+2]=255&k,i[m+3]=k>>8&255}}},a.SoundGenerator.prototype.getAudioGenerator=function(e,t){var i=this.attack+this.sustain+this.release-1+32*this.rowLen,r=this;n(i,function(o){r.genSound(e,o,0),s(o,i,r.instr,r.rowLen,function(){t(new a.AudioGenerator(o))})})},a.SoundGenerator.prototype.createAudio=function(e,t){this.getAudioGenerator(e,function(e){t(e.getAudio())})},a.SoundGenerator.prototype.createAudioBuffer=function(e,t){this.getAudioGenerator(e,function(e){e.getAudioBuffer(t)})},a.MusicGenerator=function(e){this.song=e,this.waveSize=c*e.songLen},a.MusicGenerator.prototype.generateTrack=function(e,t,i){var r=this;n(this.waveSize,function(o){var n=r.waveSize,c=r.waveSize*l*2,u=r.song.rowLen,f=r.song.endPattern,d=new a.SoundGenerator(e,u),m=0,p=0,v=0,g=function(){for(var t=new Date;;)if(32!==v){if(p===f-1)return void setTimeout(b,0);var i=e.p[p];if(i){var r=e.c[i-1].n[v];r&&d.genSound(r,o,m)}if(m+=u,v+=1,new Date-t>h)return void setTimeout(g,0)}else v=0,p+=1},b=function(){s(o,n,e,u,w)},y=0,w=function(){for(var e=new Date,r=0;c>y;){var n=t[y]+(t[y+1]<<8)+o[y]+(o[y+1]<<8)-32768;if(t[y]=255&n,t[y+1]=n>>8&255,y+=2,r+=1,r%1e3===0&&new Date-e>h)return void setTimeout(w,0)}setTimeout(i,0)};setTimeout(g,0)})},a.MusicGenerator.prototype.getAudioGenerator=function(e){var t=this;n(this.waveSize,function(i){var r=0,o=function(){r-1?void(n.gain.value=e):n.gain.value},this.pool[e]=o,t(o)}.bind(this))},pool:{},tracks:{main:{songLen:198,songData:[{osc1_oct:9,osc1_det:0,osc1_detune:0,osc1_xenv:0,osc1_vol:161,osc1_waveform:0,osc2_oct:9,osc2_det:0,osc2_detune:4,osc2_xenv:0,osc2_vol:182,osc2_waveform:0,noise_fader:0,env_attack:100,env_sustain:1818,env_release:18181,env_master:192,fx_filter:0,fx_freq:0,fx_resonance:254,fx_delay_time:6,fx_delay_amt:108,fx_pan_freq:3,fx_pan_amt:61,lfo_osc1_freq:0,lfo_fx_freq:0,lfo_freq:3,lfo_amt:94,lfo_waveform:2,p:[1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,0,2,3,4,1,2,3,4,5,6,7,8,1,2,1,2,3,4,5,6,5,6,7,8],c:[{n:[142,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,140,0,0,0,0,0,0,0,138,0,0,0,0,0,0,0]},{n:[135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,135,0,0,0,138,0,0,0]},{n:[140,0,138,0,135,0,0,0,0,0,0,0,0,0,130,0,142,0,140,0,135,0,0,0,0,0,0,0,138,0,0,0]},{n:[135,0,0,0,0,0,0,0,0,0,0,0,0,0,130,0,142,0,0,0,0,0,0,0,135,0,0,0,138,0,0,0]},{n:[123,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},{n:[130,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},{n:[128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},{n:[119,131,0,0,0,0,0,0,0,0,0,0,0,0,0,0,126,114,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}]},{osc1_oct:8,osc1_det:0,osc1_detune:0,osc1_xenv:0,osc1_vol:0,osc1_waveform:0,osc2_oct:8,osc2_det:0,osc2_detune:0,osc2_xenv:0,osc2_vol:0,osc2_waveform:0,noise_fader:19,env_attack:100,env_sustain:0,env_release:3636,env_master:192,fx_filter:1,fx_freq:8100,fx_resonance:156,fx_delay_time:2,fx_delay_amt:22,fx_pan_freq:3,fx_pan_amt:43,lfo_osc1_freq:0,lfo_fx_freq:0,lfo_freq:0,lfo_amt:0,lfo_waveform:0,p:[0,0,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2],c:[{n:[135,0,135,0,0,135,0,135,135,0,135,0,0,135,0,135,135,0,135,0,0,135,0,135,135,0,135,0,0,135,0,135]},{n:[135,0,135,0,0,135,0,135,135,0,135,0,0,135,0,135,135,0,135,0,0,135,0,135,135,0,135,0,135,0,135,135]}]},{osc1_oct:6,osc1_det:0,osc1_detune:0,osc1_xenv:0,osc1_vol:192,osc1_waveform:1,osc2_oct:8,osc2_det:0,osc2_detune:8,osc2_xenv:0,osc2_vol:82,osc2_waveform:2,noise_fader:0,env_attack:100,env_sustain:4545,env_release:2727,env_master:192,fx_filter:3,fx_freq:2700,fx_resonance:85,fx_delay_time:6,fx_delay_amt:60,fx_pan_freq:6,fx_pan_amt:86,lfo_osc1_freq:0,lfo_fx_freq:1,lfo_freq:7,lfo_amt:106,lfo_waveform:0,p:[0,0,0,0,1,1,2,3,1,1,2,3,1,1,2,3,1,1,2,3,1,1,2,3,0,0,0,0,1,1,1,1,2,3],c:[{n:[135,135,147,135,0,135,147,135,135,135,147,135,0,135,147,135,135,135,147,135,0,135,147,135,135,135,147,135,0,135,147,135]},{n:[140,140,152,140,0,140,152,140,140,140,152,140,0,140,152,140,140,140,152,140,0,140,152,140,140,140,152,140,0,140,152,142]},{n:[131,131,143,131,0,131,143,131,131,131,143,131,0,131,143,131,138,138,150,138,0,138,150,138,138,138,150,138,0,138,150,137]}]},{osc1_oct:7,osc1_det:0,osc1_detune:0,osc1_xenv:0,osc1_vol:187,osc1_waveform:2,osc2_oct:5,osc2_det:0,osc2_detune:2,osc2_xenv:1,osc2_vol:161,osc2_waveform:2,noise_fader:0,env_attack:100,env_sustain:1818,env_release:2727,env_master:123,fx_filter:1,fx_freq:1900,fx_resonance:162,fx_delay_time:2,fx_delay_amt:153,fx_pan_freq:6,fx_pan_amt:61,lfo_osc1_freq:0,lfo_fx_freq:1,lfo_freq:2,lfo_amt:196,lfo_waveform:3,p:[0,0,0,0,0,0,0,0,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,1,1,2,1,1,1,1,1,2],c:[{n:[135,135,138,135,142,135,140,138,135,135,138,135,142,135,140,138,135,135,138,135,142,135,140,138,135,135,138,135,142,135,140,138]},{n:[143,143,155,143,0,143,155,143,143,143,150,143,147,143,140,143,138,138,143,138,143,140,138,140,138,138,143,138,142,140,138,140]}]},{osc1_oct:8,osc1_det:0,osc1_detune:0,osc1_xenv:1,osc1_vol:192,osc1_waveform:0,osc2_oct:7,osc2_det:0,osc2_detune:0,osc2_xenv:1,osc2_vol:70,osc2_waveform:2,noise_fader:8,env_attack:100,env_sustain:0,env_release:9090,env_master:164,fx_filter:2,fx_freq:5500,fx_resonance:240,fx_delay_time:6,fx_delay_amt:51,fx_pan_freq:3,fx_pan_amt:66,lfo_osc1_freq:0,lfo_fx_freq:0,lfo_freq:0,lfo_amt:0,lfo_waveform:0,p:[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1],c:[{n:[135,0,0,0,0,0,135,0,0,0,135,0,0,0,0,0,135,0,0,0,0,0,135,0,0,0,135,0,0,0,0,0]}]}],rowLen:6615,endPattern:41}}},i.fx={click:{count:4,params:[[2,,.06,,.61,.58,,.0092,-.0248,.0059,.9077,-1,-.855,,-1,,-.24,-.4599,.9991,-.647,-.5371,,-1,.33]]},hover:{count:4,params:[[2,.46,.01,.0058,,.29,,-.06,-.02,,,-.7,.5,,-1,,-.5125,-.2453,.4399,-.7,,.0058,-1,.51]]},select:{count:4,params:[[2,,.0138,,.86,.52,,.04,-.04,,,-1,,,-1,,-1,-.56,.63,-.4,.35,,-1,.16]]},move:{count:4,params:[[2,.18,.01,,.3702,.14,,-.0799,.26,.41,.67,-1,,,-1,,-.1999,-.3199,.46,-.0799,,,-1,.4]]},hit:{count:18,params:[[2,.16,.18,,,.4,,-.3199,-.4399,,,-1,,,-1,,-1,-1,.74,-1,,.54,-1,.55]]},explosion:{count:4,params:[[3,,.11,.81,.4543,.11,,-1,-1,,,.36,.21,.45,-.6599,,-.04,.72,.26,-.4399,,,-.64,.34]]},explosionBig:{count:4,params:[[3,,.87,,,.22,,,-.14,,,-1,,,-1,,.08,-.28,.44,-.3399,,,-1,.17]]},levelup:{count:1,params:[[3,.0061,.1462,.0048,.9138,.5027,,.065,,,.6737,.1527,,,-.9567,,.081,-.0307,.071,.0945,,2e-4,,.26]]},death:{count:1,params:[[0,1e-4,.7618,.1376,.81,.1,,.3358,3e-4,,,.3006,,,.048,.6803,-1,-.76,.9985,.6463,.3453,,-1,.27]]}},i.audio={sounds:{},references:[],mute:!1,play:function(e){if(!i.audio.mute){var t=i.audio.sounds[e];t=t.length>1?i.audio.sounds[e][i.rand.range(0,t.length)]:i.audio.sounds[e][0],t.pool[t.tick].play(),t.tickthis.maxDistance&&(this.distance=this.maxDistance,this.destroy())},i.particle.prototype.draw=function(){i.ctx.save(),i.ctx.globalAlpha=1-this.distance/this.maxDistance,i.entity.prototype.draw.call(this),i.ctx.restore()},i.explosion=function(e){i.entity.apply(this,arguments),this.distance=0,this.rotate=i.rand.range(0,360),this.rot=e.rot||i.rand.range(-5,5),this.delta=e.delta||.1,this.maxDistance=i.rand.range(8*this.delta,15*this.delta)},i.explosion.prototype=Object.create(i.entity.prototype),i.explosion.prototype.constructor=i.explosion,i.explosion.prototype.update=function(){this.distance+=this.delta,this.w+=this.delta,this.h+=this.delta,this.rotate+=this.rot,this.distance>this.maxDistance&&(this.distance=this.maxDistance,this.destroy())},i.explosion.prototype.draw=function(){i.ctx.save(),i.ctx.globalAlpha=1-this.distance/this.maxDistance,i.entity.prototype.draw.call(this),i.ctx.restore()},i.bullet=function(e){this.column=e.column,this.type=e.type,this.speed=5,this.width=i.brickWidth,this.height=i.brickHeight,this.x=this.column*this.width+i.gap*(this.column+1),this.y=i.stage.height-i.brickWidth,this.hw=this.width/2,this.hh=this.height/2,this.rad=1,this.removed=!1,this.power=100,this.sprite=i.sprite.get(this.type+"-SHOT")},i.bullet.prototype.destroy=function(){Array.prototype.push.apply(i.explosions,[new i.explosion({name:"explosion#ffffff",x:this.x+this.hw,y:this.y,w:this.power/4,h:this.power/4,col:"#ffffff",delta:2,rot:0}),new i.explosion({name:"explosion#ed8500",x:this.x+this.hw,y:this.y,w:this.power/7,h:this.power/7,col:"#ed8500",delta:1.5,rot:-5}),new i.explosion({name:"explosion#ffff00",x:this.x+this.hw,y:this.y,w:this.power/8,h:this.power/8,col:"#ffff00",delta:1,rot:4})]),this.removed=!0},i.bullet.prototype.update=function(){this.y-=this.speed*i.timer.delta,i.arr.loop(i.bricks[this.column],function(e,t){null!==e&&e.y>this.y-i.brickHeight&&(this.power=i.elements[this.type].against[e.type],this.type===e.type&&(i.rumble.level=1),e.hit(this.power,this.type),this.destroy())},this)},i.bullet.prototype.draw=function(){i.ctx.save(),i.ctx.translate(this.x,this.y),i.ctx.drawImage(this.sprite,0,0),i.ctx.restore()},i.tower=function(e){this.type=e.type,this.w=i.brickWidth,this.h=i.brickWidth,this.setColumn(e.column),this.y=i.stage.height-this.h,this.col=i.elements[this.type].color,this.hw=this.w/2,this.hh=this.h/2,this.rad=Math.round(this.w/10),this.removed=!1,this.sprite=i.sprite.get(this.type),this.shootDelay=this.latency=i.elements[this.type].latency},i.tower.prototype.setColumn=function(e){this.column=e,this.x=this.column*this.w+i.gap*(this.column+1)},i.tower.prototype.destroy=function(){this.removed=!0;var e,t,r=this.w/6,o=this.h/6;for(i.rumble.level=10,e=1;6>e;e++)for(t=1;6>t;t++)i.particles.push(new i.particle({name:"particle"+this.col,x:this.x+e*r,y:this.y+t*o,w:r,h:o,col:this.col,speed:i.rand.range(1,5),dist:100*i.rand.range(3,5)}));i.audio.play("explosion")},i.tower.prototype.shoot=function(){0!==i.s&&i.bullets.push(new i.bullet({column:this.column,type:this.type}))},i.tower.prototype.update=function(){this.shootDelay-=i.timer.delta,this.shootDelay<0&&(this.shoot(),this.shootDelay=this.latency)},i.tower.prototype.draw=function(){i.ctx.save(),i.ctx.translate(this.x,this.y),i.ctx.drawImage(this.sprite,0,0),i.ctx.restore()},i.brick=function(e){if(this.column=e.column,this.type=e.type,this.w=i.brickWidth,this.h=i.brickHeight,this.x=this.column*this.w+i.gap*(this.column+1),this.y=-this.h,this.hw=this.w/2,this.hh=this.h/2,this.rad=Math.round(this.w/10),this.removed=!1,this.col=i.elements[this.type].color,this.add=0,this.explode=i.noop,this.sprite=i.sprite.get(this.type+"-BRICK-"+e.item),this.val=this.energy=i.elements[this.type].bricks[e.item].energy,"special"===e.item)switch(e.type){case"FIRE":this.explode=function(){i.rumble.level=10,i.arr.loop(i.bricks[this.column],function(e,t){e&&!e.removed&&(e.hitType=e.type,e.destroy())}),i.audio.play("explosionBig")};break;case"EARTH":this.explode=function(){i.rumble.level=10;for(var e=0,t=i.columns;t>e;e+=1)i.arr.loop(i.bricks[e],function(e,t){e&&!e.removed&&e.row>=this.row-1&&e.row<=this.row+1&&e.column>=this.column-1&&e.column<=this.column+1&&(e.hitType=e.type,e.destroy())},this);i.audio.play("explosionBig")};break;case"WATER":this.explode=function(){i.rumble.level=10;for(var e=0,t=i.columns;t>e;e+=1)e!==this.column&&i.arr.loop(i.bricks[e],function(e,t){e&&!e.removed&&e.row===this.row&&(e.hitType=e.type,e.destroy())},this);i.audio.play("explosionBig")};break;case"AIR":this.explode=function(){i.rumble.level=10;for(var e=0,t=i.columns;t>e;e+=1)i.arr.loop(i.bricks[e],function(e,t){e&&!e.removed&&e.type===this.type&&(e.hitType=e.type,e.destroy())},this);i.audio.play("explosionBig")}}},i.brick.prototype.destroy=function(e){this.removed=!0,this.type===this.hitType&&(this.explode(),i.flash=8),i.rumble.level=5;for(var t=12,r=0,o=10;o>r;r+=1)i.particles.push(new i.particle({name:"particle"+this.col,x:this.x+this.w/2,y:this.y+this.h,w:this.w/t,h:this.h/(t/2),col:this.col,speed:i.rand.range(1,5),dist:100*i.rand.range(3,5)}));e||i.countScore(this.val),i.audio.play("explosion")},i.brick.prototype.hit=function(e,t){this.hitType=t,this.energy-=e,this.energy<=0&&!this.removed&&this.destroy(),i.audio.play("hit")},i.brick.prototype.update=function(){this.y+=i.timer.move+this.add,0===this.add?0!==i.s&&this.y>i.stage.height-this.h-i.brickWidth&&i.over():this.add-=i.gravity},i.brick.prototype.draw=function(){i.ctx.save(),i.ctx.translate(this.x,this.y),i.ctx.drawImage(this.sprite,0,0),i.ctx.restore()},i.star=function(e){this.x=i.rand.flot()*i.bgCtx.canvas.width,this.y=i.rand.flot()*i.bgCtx.canvas.height,this.brightness=15*e+i.rand.range(14*e,18*e)/100,this.radius=i.rand.flot()/e*4,this.color=i.starColors[i.rand.range(0,i.starColors.length)],this.draw()},i.star.prototype.draw=function(){i.bgCtx.save(),i.bgCtx.beginPath(),i.bgCtx.globalAlpha=this.brightness,i.bgCtx.fillStyle=this.color,i.bgCtx.arc(this.x,this.y,this.radius,0,i.PI2),i.bgCtx.fill(),i.bgCtx.closePath(),i.bgCtx.restore()},i.obj.extend(!0,i,{timer:{date:new Date,curr:null,timestamp:Date.now(),delta:1,msec:0,move:0,t:1e3/60,tick:function(){i.timer.curr=Date.now(),i.timer.d=i.timer.curr-i.timer.timestamp,i.timer.delta=i.timer.d/i.timer.t,i.timer.delta=i.timer.delta<0?.001:i.timer.delta,i.timer.delta=i.timer.delta>10?10:i.timer.delta,i.timer.msec+=i.timer.delta,i.timer.timestamp=i.timer.curr,i.timer.move=i.s*i.timer.delta}},emitter:{sum:0,row:0,emit:function(){if(i.emitter.sum>i.brickHeight+i.gap||0===i.emitter.sum){i.emitter.sum=0;for(var e,t,r,o=0,n=i.columns;n>o;o+=1)t=i.rand.select(i.elementTypes),r=i.rand.select(Object.keys(i.elements[t].bricks)),e=new i.brick({column:o,type:t,item:r}),e.row=i.emitter.row,i.bricks[o].unshift(e);i.emitter.row++,i.s+=.001}i.emitter.sum+=i.timer.move}},initBackground:function(){for(var e=null,t=0,r=i.bgs.length;r>t;t+=1){i.bgCtx.clearRect(0,0,i.bgCtx.canvas.width,i.bgCtx.canvas.height);for(var o=0,n=i.starAmount;n>o;o+=1)e=new i.star(i.bgs.length-t+1),e.draw();i.bgs[t].b.style.backgroundImage="url("+i.bg.toDataURL()+")"}},noBg:function(){i.moveBg=!i.moveBg},mute:function(){i.audio.mute=!i.audio.mute;for(var e in i.music.pool)if(i.music.pool.hasOwnProperty(e)){var t=i.music.pool[e];t.volume(i.audio.mute?0:.4)}},menu:function(e){i.paused=!0,e&&i.bricks&&(i.re.style.display="block"),i.mnu.style.display="block",i.msg.style.display="none"},newgame:function(){i.bricks=i.arr.create(i.columns),i.towers=[],i.bullets=[],i.particles=[],i.explosions=[],i.activeColumn=null,i.hoverColumn=null;var e=i.elementTypes.concat(i.arr.create(i.columns-4,0)).sort(function(){return.5-Math.random()});i.arr.loop(e,function(t,r){i.towers[r]=e[r]?new i.tower({column:r,type:e[r]}):!1}),i.score=0,i.s=i.speed,i.countScore(0),i.paused=!1,i.msg.style.display="none"},over:function(){var e=600;i.s=0,i.message("GAME OVER",0,"MAIN MENU"),i.audio.play("death"),i.towers.forEach(function(e,t){setTimeout(function(){e&&e.x&&e.destroy()},100*t)}),i.bricks.forEach(function(t){setTimeout(function(){t.forEach(function(e){e&&!e.removed&&(e.add=-.001)})},e),e+=100})},pause:function(){i.paused?(i.paused=!1,i.message()):(i.paused=!0,i.message("PAUSE")); + +},help:function(){if(!i.buildHelp){for(var e in i.elements)if(i.elements.hasOwnProperty(e)){var t=e,r=i.elements[e],o=i.dom.create("div"),n=i.dom.create("h2"),s=i.dom.create("p"),a=i.dom.create("p");n.innerHTML=t+"
",s.innerHTML=r.desc,a.innerHTML=r.spec,o.appendChild(n),s.insertBefore(i.sprite.get(t),s.firstChild),o.appendChild(s),a.insertBefore(i.sprite.get(t+"-BRICK-special"),a.firstChild),o.appendChild(a),i.hlp.appendChild(o)}i.buildHelp=!0}i.message(i.hlp,0,"MAIN MENU")},message:function(e,t,r){var o,n=i.msg.style;i.mnu.style.display="none",e?("object"==typeof e?(i.msg.innerHTML="",e.style.display="block",i.msg.appendChild(e)):i.msg.innerHTML=e,r&&(o=i.dom.create("em"),o.innerHTML=r,i.msg.appendChild(o)),n.opacity=0,n.display="block",n.marginTop=-i.msg.offsetHeight/2+"px",n.opacity=1):n.display="none",t&&setTimeout(function(){n.display="none"},t)},credits:function(){i.message(i.crd,0,"MAIN MENU")},controls:function(){window.addEventListener("keyup",function(e){switch(e.keyCode){case 27:i.menu(!0);break;case 80:i.pause();break;case 77:i.mute();break;case 66:i.noBg()}},!1),i.ng.addEventListener("click",function(){i.newgame(),i.audio.play("click"),i.mnu.style.display="none"},!1),i.hl.addEventListener("click",function(){i.help(),i.audio.play("click")},!1),i.re.addEventListener("click",function(){i.pause()},!1),["hlp","msg","crd"].forEach(function(e){i[e].addEventListener("click",function(){i.menu()},!1)}),i.cr.addEventListener("click",function(){i.credits(),i.audio.play("click")},!1),["ng","hl","cr","re"].forEach(function(e){i[e].addEventListener("mouseover",function(){i.audio.play("hover")},!1)}),i.cnt.addEventListener("mousemove",function(e){if(!i.paused&&i.s>0){var t=e.pageX-this.offsetLeft,r=Math.floor(t/(i.brickWidth+i.gap+i.gap/i.columns));i.hoverColumn=r}else i.hoverColumn=null},!1),i.cnt.addEventListener("click",function(e){if(!i.paused&&i.s>0){var t=e.pageX-this.offsetLeft,r=Math.floor(t/(i.brickWidth+i.gap+i.gap/i.columns));i.towers[r]&&!i.towers[r].removed?null===i.activeColumn?(i.activeColumn=r,i.audio.play("select")):(i.towers[i.activeColumn].setColumn(r),i.towers[r].setColumn(i.activeColumn),i.arr.move(i.towers,i.activeColumn,r),i.activeColumn=null,i.audio.play("move")):(null!==i.activeColumn&&(i.towers[i.activeColumn].setColumn(r),i.arr.move(i.towers,i.activeColumn,r),i.audio.play("move")),i.activeColumn=null)}else i.activeColumn=null},!1)},stats:function(){var e;"function"==typeof Stats?(e=new Stats,e.setMode(0),e.domElement.style.position="absolute",e.domElement.style.left="0px",e.domElement.style.top="0px",document.body.appendChild(e.domElement),i.stats=e):i.stats={begin:i.noop,end:i.noop}},countScore:function(e){i.score+=e,i.level=Math.ceil(i.s/.12),i.hud.score.innerHTML=i.score,i.hud.level.innerHTML=i.level,i.level>i.prevLevel&&(i.prevLevel=i.level,i.message("LEVEL UP",2e3),i.audio.play("levelup"))},update:function(){i.arr.loop(i.bricks,function(e,t){i.arr.loop(e,function(t,i){t&&(t.removed?e.splice(i,1):t.update())})}),i.arr.loop([i.towers,i.bullets,i.particles,i.explosions],function(e){i.arr.loop(e,function(t,i){t&&(t.removed?e.splice(i,1):t.update())})}),i.rumble.update()},updateBackground:function(){if(i.moveBg)for(var e=0,t=i.bgs.length;t>e;e+=1)i.bgs[e].c+=e+1,i.bgs[e].b.style.backgroundPosition="0px "+i.bgs[e].c/3+"px"},rumble:{update:function(){i.rumble.level>0?(i.rumble.level-=i.rumble.decay,i.rumble.level=i.rumble.level<0?0:i.rumble.level,i.rumble.x=i.rand.rangef(-i.rumble.level,i.rumble.level),i.rumble.y=i.rand.rangef(-i.rumble.level,i.rumble.level)):(i.rumble.x=0,i.rumble.y=0)},draw:function(){(0!==i.rumble.x||0!==i.rumble.y)&&(i.stage.style[i.transformName]="translate("+i.rumble.x+"px,"+i.rumble.y+"px)")}},draw:function(){i.ctx.save(),i.ctx.clearRect(0,0,i.ctx.canvas.width,i.ctx.canvas.height),i.arr.loop(i.bricks,function(e){i.arr.loop(e,function(e){e&&!e.removed&&e.draw()})}),i.arr.loop([i.towers,i.bullets,i.particles,i.explosions],function(e){i.arr.loop(e,function(e){e&&!e.removed&&e.draw()})}),i.drawFlash(),i.rumble.draw(),i.drawSelection()},drawSelection:function(){var e,t;if(null!==i.activeColumn&&(e=i.towers[i.activeColumn],e&&e.x&&(i.ctx.save(),i.ctx.translate(e.x,0),i.ctx.lineWidth=2,i.ctx.fillStyle=i.elements[e.type].color,i.ctx.globalAlpha=.2,i.ctx.fillRect(0,0,i.brickWidth,i.stage.height),i.ctx.restore())),null!==i.hoverColumn){e=i.towers[i.activeColumn],t=i.towers[i.hoverColumn];var r="#ffffff";t&&t.x&&(r=i.elements[t.type].color),e&&e.x&&(r=i.elements[e.type].color),i.ctx.save(),i.ctx.translate(i.gap+i.hoverColumn*(i.brickWidth+i.gap),0),i.ctx.lineWidth=2,i.ctx.fillStyle=r,i.ctx.globalAlpha=.2,i.ctx.fillRect(0,0,i.brickWidth,i.stage.height),i.ctx.restore()}},drawFlash:function(){i.flash>0&&(i.flash--,i.f.style.opacity=i.flash/10)},init:function(){i.music.generate("main",function(e){e.loop=!0,e.volume(.4),e.start()}),i.obj.extend(!0,i,{ww:window.innerWidth,wh:window.innerHeight,rumble:{body:i.dom.get("r")},hud:{level:i.dom.get("lv"),score:i.dom.get("sc")},cnt:i.dom.get("cnt"),msg:i.dom.get("msg"),mnu:i.dom.get("mnu"),hlp:i.dom.get("hlp"),crd:i.dom.get("crd"),re:i.dom.get("re"),ng:i.dom.get("ng"),hl:i.dom.get("hl"),cr:i.dom.get("cr"),f:i.dom.get("f"),stage:i.dom.get("c"),bg:i.dom.get("b"),bgs:[{b:i.dom.get("b1"),c:0},{b:i.dom.get("b2"),c:0},{b:i.dom.get("b3"),c:0}]}),i.stage.width=i.wh/2,i.stage.height=i.wh-30,i.cnt.style.width=i.stage.width+"px",i.cnt.style.height=i.wh+"px",i.bg.width=i.ww,i.bg.height=i.wh,i.brickWidth=i.stage.width/i.columns-i.gap-i.gap/i.columns,i.brickHeight=i.brickWidth/2+i.gap,i.obj.extend(!0,i,{ctx:i.stage.getContext("2d"),bgCtx:i.bg.getContext("2d"),elementTypes:Object.keys(i.elements),transformName:i.vendor.get("transform"),prevLevel:0,score:0,flash:0,paused:!0});for(var e=0;3>e;e++)i.bgs[e].width=i.ww,i.bgs[e].height=i.wh;i.sprite.factory(),i.initBackground(),i.controls(),i.stats(),i.menu()}}),i.init(),function l(){requestAnimationFrame(l,i.stage.canvas),i.timer.tick(),i.stats.begin(),i.updateBackground(),i.paused||(i.emitter.emit(),i.update(),i.draw()),i.stats.end()}()}(); \ No newline at end of file