Skip to content

Commit

Permalink
Changed to using SoundJS for music instead of akhibara, speedup
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Mar 14, 2012
1 parent dfa258b commit b6aa199
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 21 deletions.
1 change: 1 addition & 0 deletions index.ejs
Expand Up @@ -14,6 +14,7 @@
<script type="text/javascript" src="akihabara/help.js"></script>
<script type="text/javascript" src="akihabara/tool.js"></script>
<script type="text/javascript" src="akihabara/gamecycle.js"></script>
<script type="text/javascript" src="sound/sound.js"></script>
<style>BODY { -webkit-user-select:none; margin:0px}</style>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />

Expand Down
47 changes: 35 additions & 12 deletions public/game.js
Expand Up @@ -48,19 +48,39 @@ gbox.onLoad(function () {

// Now let's load some audio samples...
var audioserver = "resources/audio/";
gbox.addAudio("eat", [audioserver+"eat.mp3",audioserver+"eat.ogg"],{channel:"sfx"});
gbox.addAudio("eatghost", [audioserver+"laser.mp3",audioserver+"laser.ogg"],{channel:"sfx"});
gbox.addAudio("powerpill", [audioserver+"powerup3.mp3",audioserver+"powerup3.ogg"],{channel:"sfx"});
gbox.addAudio("die", [audioserver+"die.mp3",audioserver+"die.ogg"],{channel:"sfx"});
gbox.addAudio("bonus", [audioserver+"coin.mp3",audioserver+"coin.ogg"],{channel:"sfx"});
gbox.addAudio("default-menu-option", [audioserver+"select.mp3",audioserver+"select.ogg"],{channel:"sfx"});
gbox.addAudio("default-menu-confirm", [audioserver+"start.mp3",audioserver+"start.ogg"],{channel:"sfx"});
gbox.addAudio("ingame", [audioserver+"capman-ingame.mp3",audioserver+"capman-ingame.ogg"],{channel:"bgmusic",loop:true});

// The loadAll function loads all the resources and triggers the main game loop
gbox.loadAll(go);
// Start the game
gbox.go();
// determine browser
var filetype;
var agent = navigator.userAgent.toLowerCase();
// adjust for browser
if(agent.indexOf("chrome") > -1){
filetype = ".mp3";
} else if(agent.indexOf("opera") > -1) {
filetype = ".ogg";
} else if(agent.indexOf("firefox") > -1) {
filetype = ".ogg";
} else if(agent.indexOf("safari") > -1) {
filetype = ".mp3";
} else if(agent.indexOf("msie") > -1) {
filetype = ".mp3";
}

// Load all the audio using SoundJS
SoundJS.onLoadQueueComplete = function() {
// The loadAll function loads all the resources and triggers the main game loop
gbox.loadAll(go);
// Start the game
gbox.go();
};

// Batch the audio
SoundJS.addBatch([
{name:"eat", src:(audioserver + "eat" + filetype), instances:20},
{name:"eatghost", src:(audioserver + "laser" + filetype), instances:1},
{name:"powerpill", src:(audioserver + "powerup3" + filetype), instances:1},
{name:"die", src:(audioserver + "die" + filetype), instances:1},
{name:"music", src:(audioserver + "capman-ingame" + filetype), instances:1}]);
}, false);

// Start game function
Expand All @@ -72,6 +92,8 @@ var go = function() {

// Set method called each time we change the level
maingame.changeLevel = function(level) {
// start the music
SoundJS.play("music", null, 0.2, true);
// Reset local score
maingame.hud.setWidget("score",{widget:"label",font:"small",value:0, dx:240, dy:25, clear:true});
// Let's add the player
Expand Down Expand Up @@ -187,7 +209,8 @@ var go = function() {
client.dispatchCommand({type:'initialize'});
});
} else if(message['state'] == 'ghostdead') {
if(sound) gbox.hitAudio("eatghost");
// if(sound) gbox.hitAudio("eatghost");
if(sound) SoundJS.play('eatghost');
// Check if it's a remote ghost and if it is kill it
if(currentGhosts[message['id']] != null) {
currentGhosts[message['id']].kill();
Expand Down
2 changes: 1 addition & 1 deletion public/playerghost.js
Expand Up @@ -184,7 +184,7 @@ var createPlayerGhost = function() {

// And now, a custom method. This one will kill the player and will be called by ghosts, when colliding with capman.
kill:function() {
if(sound)gbox.hitAudio("die");
if(sound) SoundJS.play("die");
// Set status to eaten
this.status = 'eaten';
// Change tileset
Expand Down
6 changes: 3 additions & 3 deletions public/playermongoman.js
Expand Up @@ -88,14 +88,14 @@ var createPlayerMongoman = function() {
if(inmouth>7) {
if(inmouth == 9) {
this.scorecombo = 1;
if(sound) gbox.hitAudio("powerpill");
if(sound) SoundJS.play("powerpill");
if(gbox.getObject("ghosts","ghost1")) gbox.getObject("ghosts","ghost1").makeeatable();
if(gbox.getObject("ghosts","ghost2")) gbox.getObject("ghosts","ghost2").makeeatable();
if(gbox.getObject("ghosts","ghost3")) gbox.getObject("ghosts","ghost3").makeeatable();
if(gbox.getObject("ghosts","ghost4")) gbox.getObject("ghosts","ghost4").makeeatable();
if(gbox.getObject("player", "playerghost")) gbox.getObject("player","playerghost").makeeatable();
} else {
if(sound) gbox.hitAudio("eat");
if(sound) SoundJS.play("eat");
maingame.hud.addValue("score","value",10);
}

Expand All @@ -120,7 +120,7 @@ var createPlayerMongoman = function() {
client.dispatchCommand({type:'dead', score:maingame.hud.getNumberValue("score","value")});
// Animate death
this.killed = true;
if(sound) gbox.hitAudio("die");
if(sound) SoundJS.play("die");
maingame.playerDied({wait:50});
toys.generate.sparks.simple(this,"sparks",null,{tileset:this.tileset,frames:{speed:4,frames:[6,5,7,8,9,9,9,9]}});
}
Expand Down
10 changes: 5 additions & 5 deletions public/remoteplayer.js
Expand Up @@ -140,7 +140,7 @@ var createRemoteGhostPlayer = function(data) {
// Up the combo
mongoman.scorecombo++;
// Signal eaten a ghost
if(sound) gbox.hitAudio("eatghost");
if(sound) SoundJS.play("eatghost");
// Fire off I'm dead message
client.dispatchCommand({type:'ghostdead', id:this.conId});
// gbox.hitAudio("eatghost");
Expand All @@ -165,7 +165,7 @@ var createRemoteGhostPlayer = function(data) {

// And now, a custom method. This one will kill the player and will be called by ghosts, when colliding with capman.
kill:function() {
if(sound)gbox.hitAudio("die");
if(sound) SoundJS.play("die");
// Set status to eaten
this.status = 'eaten';
// Change tileset
Expand Down Expand Up @@ -251,14 +251,14 @@ var createRemoteMongoManPlayer = function(data) {
// Handle pills
if(inmouth>7) {
if(inmouth == 9) {
if(sound) gbox.hitAudio("powerpill");
if(sound) SoundJS.play("powerpill");
if(gbox.getObject("ghosts","ghost1")) gbox.getObject("ghosts","ghost1").makeeatable();
if(gbox.getObject("ghosts","ghost2")) gbox.getObject("ghosts","ghost2").makeeatable();
if(gbox.getObject("ghosts","ghost3")) gbox.getObject("ghosts","ghost3").makeeatable();
if(gbox.getObject("ghosts","ghost4")) gbox.getObject("ghosts","ghost4").makeeatable();
if(gbox.getObject("player", "playerghost")) gbox.getObject("player","playerghost").makeeatable();
} else {
if(sound) gbox.hitAudio("eat");
if(sound) SoundJS.play("eat");
}

var mouthx = help.xPixelToTileX(maze,this.x + this.hw);
Expand All @@ -279,7 +279,7 @@ var createRemoteMongoManPlayer = function(data) {
kill:function() {
if(!this.killed) {
this.killed = true;
if(sound) gbox.hitAudio("die");
if(sound) SoundJS.play("die");
maingame.playerDied({wait:50});
toys.generate.sparks.simple(this,"sparks",null,{tileset:this.tileset,frames:{speed:4,frames:[6,5,7,8,9,9,9,9]}});
}
Expand Down
43 changes: 43 additions & 0 deletions public/sound/sound.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b6aa199

Please sign in to comment.