From 6f93f8973d37ddfa283ae2d7d045120b8c33f321 Mon Sep 17 00:00:00 2001
From: Thunraz <julian.dinges@gmail.com>
Date: Sat, 13 Sep 2014 03:42:34 +0200
Subject: [PATCH] Added shoot sound and explosion sound.

---
 assets/explosion.mp3 | Bin 0 -> 836 bytes
 assets/explosion.wav | Bin 0 -> 2219 bytes
 assets/shoot.mp3     | Bin 0 -> 764 bytes
 assets/shoot.wav     | Bin 0 -> 1782 bytes
 gulpfile.js          |   2 +-
 lib/enemy.js         |   1 +
 lib/explosion.js     |   1 +
 lib/main.js          |  43 +++++++++++++++++++++++++++++++++++++++++++
 lib/player.js        |   1 +
 9 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 assets/explosion.mp3
 create mode 100644 assets/explosion.wav
 create mode 100644 assets/shoot.mp3
 create mode 100644 assets/shoot.wav

diff --git a/assets/explosion.mp3 b/assets/explosion.mp3
new file mode 100644
index 0000000000000000000000000000000000000000..4af6b0baae84ae65fe39ac4e2675730f6c60028f
GIT binary patch
literal 836
zcmeZtF=k-^0i}@OU{@f`$H2hslUSB!YNltRXJ}vumV^-hA6p!Nb3OCY@_`(7Am#vS
zkzj~L0wqYG8yPG@0=tmGMI`V78T>~ASly)pcM`db|Boe(FmNldJrZ<aV7Ra(fpOW{
zhUPBoCZPv^9oqPtAN;6gXgsID!Yuzc;rIW4Dm?W+>L31p&3^u0>+*%wo;ynv4<9Yv
z6BA$tGKY`v0J8vNqXfg!6|I~b_`dJfvNRVka8Nh!Ul3E(z&Ok4%xs&5ZdWfonH)Sp
z&x7ys%gX5g|6iQT2>$g`PEq3X-cR8cf5GPP92DnaJS@OqJ#+S%HFNCWdTn<pVf)<7
zQu)eHCB$i~@9~gIxtO4%-|N<$bA9P%aQL>tYqiLA8Qy0+wJnWo@9lXSwg_a77_Y#w
z9}J#t8rjT@syef81W55b3Qy9yv*BW#QtZ}6E)!Ggum1o4D>Ue4?zUSDNiLmcQ!M9n
zXy_>$#5KzX{|b#xOUneABg1R3St-J>O^vBjOKr!7k_~I#E)luRu+~$jx@7v^pnK&@
zc^A~0FjPn$kIXv1WB%lB_2o|wZGQJ{SxD9OWntg9mF~B=4>CuI*W%j|MqdGj_PT&`
zF_u$!KRj1IQB*Ts@$$t>%)BOtc?=pD1XvT_xGQUAOg~^V;le)0_u)VG2#8D+63zaw
zOTOjdO97BM8sb_>8z)W-VAw0W|Ivn3Ubdob$6L?;|8b>5y7Oqj-oy`E=Kufa6zON%
z>!dto`v3obE-9re>Kt+W5E%b|%T}Qdj<YK!gUn&$tdN`$c$k4<!3ixUwwA@`I_8xh
nac^12mtMc(W9SZ-Z@=cL{(rbsPRqy9*VS0h(o)ZK6*>R_u-|2{

literal 0
HcmV?d00001

diff --git a/assets/explosion.wav b/assets/explosion.wav
new file mode 100644
index 0000000000000000000000000000000000000000..8f1ffacf4c2fcdc7217b8f16654b919f361d02b4
GIT binary patch
literal 2219
zcmb8vc}$aM90%~%xXu1yGPh}*8;205CNeb2HgU3X2vY&6fITRsQVuBvT4<riODQca
zl)_s|VQ3FpN@<}WZcJ=4MmXdcaugXJ7=jA}-AptA9f_MW?0rjHkR!y;oA-I|<9UAH
z_l-Og5@J9B05$*<oSe?wy8{4#E$}4S1=!{-018NqXU6m4b3%m`6B-=oMa}IKT}+fP
z2XIQTh%B~>c`}iu%{x(t6@h8lWL7<%g46PS*+lvkLzSu;L%T}O4-yF|8hveaR;|8R
z^@AWQj^OTJSsEslRtRDvRpl3((1a=ynU{H5D^an%iWM^MFXGO8rR@7~y*ZX8xRGRG
zgchC%voLdlcmhyX6j!Iwb4ik#c6`IR*klGjGt+f8j#Pw|7%x>6OHElk9|lzevMf&t
zo^A5701+7yCh1Oyg0);VkB+VUu_;xpjg5}#2x4LDB$~cMVG2T2pI@Cem*Hn63dckB
zRIlArWwe|j!?(n!$dd|dCbe~2<ZaUB>w|u&lw0M1G>W1((G4Ty>-ya&h9nR@5pjfb
zs#TN{DPZ?s;hy2#$istEYS|4T&U{gpRp6&2Qu;a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i-p^V2S%B+u
MmX_y`=j6=C|6Z6^Pyhe`

literal 0
HcmV?d00001

diff --git a/assets/shoot.mp3 b/assets/shoot.mp3
new file mode 100644
index 0000000000000000000000000000000000000000..3b091df2202be2173c39f443d0e2439e84222cdf
GIT binary patch
literal 764
zcmeZtF=k-^0i}@OU{@f`$H2hslUSB!YNltRXJ}vumV^-hA6p!Nb3OCY@_`(72xhv#
zkcI*pP{2$Suo)GcK>^QDz<(5g)m<uZCy~qe|5)M(1J?zndyx(T3{2iHSrk}~@M#nt
zdH6^EYZF8Bz8Hb>_WwT=UewR||3`+!eo8qDv!wI<|5a0S)XYzX1^ehd__F`&|4*wy
z=I{&5c+bGtD8SI}`}C}<r_B!?X0h((<6$YHygH5xGp+QB#kqw(Dyq$Qn49FxttZkk
zTTGC{oi8(c|J%P@^H&(m*zkNQ$Q*X=2)Q?mhZq<NWaIw_X(=sEa&~IcU_8QpK_e+n
z`~UB>l`#=7_NkoIa8pwG9ULnf`-G>?>;LAd;P9$iy5`3j9$An%B0QFIPZ%Uze3+N`
z<m?V85lhyJmH$6UrPRG)vTKIYA+LyB(c2dsPp1_nUEQdVBB?y_=6`D?*P|Ybbvz#~
zK6rS6i){wT964SKyDN;&5)1(>)7t0waR0rxXH~b5&Q)KzqR@=BeyR=z3IZIgO^pc~
zc>kXYVft^8(f_T~Y03P5$0v!D%kBUF<Hx}WkU1)%zurBHYzknCvSD-jl2WkoORfFK
zPKz5WH3b7-bgC&>|NsA|Bg&~+VV9(gg0GFZhr{aspZEV)(QEIi*YR=mbv4$r1cwhW
RnR+lDU|_J+GhIa{005=LJmmlY

literal 0
HcmV?d00001

diff --git a/assets/shoot.wav b/assets/shoot.wav
new file mode 100644
index 0000000000000000000000000000000000000000..f2886e2dca6b765c383deb5c976efd350e01b49a
GIT binary patch
literal 1782
zcmXw4OK%(36;?Jym)&&Vb+=h|)do$`ECM8MA{4PBSt2P?6v-LR>%QOf;>?g74mqMk
zTXk&N7E+^df(8j%0|B}zP;^_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R$zJfouFNe;cB%Q)nbj+pkt
z=?L@-i5b(C<SC{&m_g!GHVskaolC|?GDS0Y>145=jEv|zLlL=C0E!te;JjK=gmsNm
zH<D^Ios@V}N~)F_@)uzMc;kC@*&vWqoX5oB4Duii94rj(J8aemoT|WbMitlqum-6K
zgyk>=^P^}Q7QV*k8e{A;Fr5a#=O9o^8o+uDV2EX^-Jud0o<gY#4G1$O#zL$$VvBVe
zM5{stB;_+6LVh`Q!&LMLiKixr3lkw_v*DNtr`T$MG9H6cVy%-hwpS<SR8~uAO2#FR
zTx{8+oG(;7Gj&!mr3fOJP!%JYrNkqdHWV9_+L4QVLeVUbvwUf)c}k0PEmh1a$`h7y
zmI`BM#V91|QZY75xCBUQ5CRIdi^(iww5*nFuJTeAWFZJ<3HHM%V<updB$hE$C^D47
zJTV1CN-B!OAT1yx)Y#Utgc~ZjrXVyS^N10FXEGQ9#YlvpCKQGW5g?EUg#^%2PlO=S
z$bbnABV;hr(x6zS36E8xh{z})G50wa5yu)EqHJ5G;weojlh7!IXc`-saAhkqj+qpg
zQN=lhiC|D$4O>4EOj9YOv`>PNb{x6jTnc7=hEZWrTrn=Rv@KS`0vY83Q@c}ZS)`3B
zESTa<T3c8rqxJw3Zx<8xxP5Dc&HDDYSN5g$maS=*_3ZQPN$!LD9B;S1{)6mc|2OwB
I8~8!~2m76GYybcN

literal 0
HcmV?d00001

diff --git a/gulpfile.js b/gulpfile.js
index 4dda7f8..9653cf2 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -25,7 +25,7 @@ gulp.task('minify', function() {
 });
 
 gulp.task('zip', ['minify'], function() {
-    return gulp.src(['g.js', 'index.html', 'assets/*.png'], { base: './' })
+    return gulp.src(['g.js', 'index.html', 'assets/*.png', 'assets/*.mp3'], { base: './' })
         .pipe(zip('AquaticBeastForce.zip'))
         .pipe(filesize())
         .pipe(gulp.dest('dist'));
diff --git a/lib/enemy.js b/lib/enemy.js
index 591298f..e37b030 100644
--- a/lib/enemy.js
+++ b/lib/enemy.js
@@ -31,6 +31,7 @@ Enemy.prototype.update = function(controls, deltaT) {
             if(this.shootTimer <= 0.0) {
                 new Projectile(this.x, this.y, this.rotation, true);
                 this.shootTimer += 0.5;
+                playSound(shootSound);
             }
 
             this.shootTimer -= deltaT;
diff --git a/lib/explosion.js b/lib/explosion.js
index 0fa3952..e0956b5 100644
--- a/lib/explosion.js
+++ b/lib/explosion.js
@@ -5,6 +5,7 @@ var Explosion = function(x, y) {
     this.frameTimer = 1/12;
 
     backgroundLayer.push(this);
+    playSound(explosionSound);
 }
 
 Explosion.prototype.update = function(controls, deltaT) {
diff --git a/lib/main.js b/lib/main.js
index 759a153..1c18734 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -9,6 +9,16 @@ var healthTimer = 0;
 var gameOverTimer = 0.5;
 var enemyCountdown = 10;
 
+var shootSound;
+var explosionSound;
+var audioContext;
+
+try {
+    window.AudioContext = window.AudioContext || window.webkitAudioContext;
+    var audioContext = new AudioContext();
+    loadSounds();
+} catch(e) {}
+
 entities.push(player);
 placeRandomEnemy();
 
@@ -73,4 +83,37 @@ function resetGame() {
 
     entities.push(player);
     placeRandomEnemy();
+}
+
+function loadSounds() {
+    var shootRequest = new XMLHttpRequest();
+    shootRequest.open('GET', 'assets/shoot.mp3', true);
+    shootRequest.responseType = 'arraybuffer';
+
+    // Decode asynchronously
+    shootRequest.onload = function() {
+        audioContext.decodeAudioData(shootRequest.response, function(buffer) {
+            shootSound = buffer;
+        }, function() { });
+    }
+    shootRequest.send();
+
+    var explosionRequest = new XMLHttpRequest();
+    explosionRequest.open('GET', 'assets/explosion.mp3', true);
+    explosionRequest.responseType = 'arraybuffer';
+
+    // Decode asynchronously
+    explosionRequest.onload = function() {
+        audioContext.decodeAudioData(explosionRequest.response, function(buffer) {
+            explosionSound = buffer;
+        }, function() { });
+    }
+    explosionRequest.send();
+}
+
+function playSound(buffer) {
+    var source = audioContext.createBufferSource();
+    source.buffer = buffer;
+    source.connect(audioContext.destination);
+    source.start(0);
 }
\ No newline at end of file
diff --git a/lib/player.js b/lib/player.js
index 97c2aba..ccbdb4b 100644
--- a/lib/player.js
+++ b/lib/player.js
@@ -89,6 +89,7 @@ Player.prototype.shoot = function(deltaT) {
 
         // Shoot maybe?
         new Projectile(this.x, this.y, this.rotation, false);
+        playSound(shootSound);
 
         this.shots--;
     }