got bullet sounds working. pretty hacky.

This commit is contained in:
Richard Harrington 2013-08-23 01:15:38 -04:00
parent 102a307af8
commit c385631f34
2 changed files with 33 additions and 7 deletions

View File

@ -10,7 +10,23 @@
<body>
<p>Hello World, Welcome to Robotwar.</p>
<canvas id="canvas" width="600" height="600"></canvas>
<audio id="shotSound" preload="auto">
<audio id="shotSound1" preload="auto">
<source src="audio/trprsht1.ogg" type="audio/ogg">
<source src="audio/trprsht1.mp3" type="audio/mp3">
</audio>
<audio id="shotSound2" preload="auto">
<source src="audio/trprsht1.ogg" type="audio/ogg">
<source src="audio/trprsht1.mp3" type="audio/mp3">
</audio>
<audio id="shotSound3" preload="auto">
<source src="audio/trprsht1.ogg" type="audio/ogg">
<source src="audio/trprsht1.mp3" type="audio/mp3">
</audio>
<audio id="shotSound4" preload="auto">
<source src="audio/trprsht1.ogg" type="audio/ogg">
<source src="audio/trprsht1.mp3" type="audio/mp3">
</audio>
<audio id="shotSound5" preload="auto">
<source src="audio/trprsht1.ogg" type="audio/ogg">
<source src="audio/trprsht1.mp3" type="audio/mp3">
</audio>

View File

@ -85,7 +85,7 @@
}
}
var Animation = function(el) {
var Animation = function(el, sounds, gameInfo) {
var width = parseInt(el.width);
var height = parseInt(el.height);
var roomForRobots = GAME_INFO.robotRadius * 2;
@ -120,6 +120,18 @@
ctx.lineWidth = gunDisplayWidth;
ctx.lineCap = 'square';
var nextSoundEl = (function() {
var i = 0;
return {
get: function() {
var el = sounds[i];
i = (i + 1) % 5;
return el;
}
}
})();
var drawCircle = function(x, y, r, color) {
ctx.fillStyle = color;
ctx.beginPath();
@ -164,7 +176,7 @@
console.log("last:", previousWorld.shells["next-id"]);
if (currentWorld.shells["next-id"] !== previousWorld.shells["next-id"]) {
shotSound.play();
nextSoundEl.get().play();
}
}
@ -197,11 +209,9 @@
var frameDuration = parseInt (1000 / FPS);
var canvasEl = $('#canvas')[0];
var soundEls = {
shotSound: $('#shotSound')[0]
}
var sounds = $('audio');
var animation = new Animation(canvasEl, soundEls, gameInfo);
var animation = new Animation(canvasEl, sounds, gameInfo);
// TODO: remove this tick loop entirely,
// and just have the animation loop calculate which