Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
a working battle music implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoporto committed Nov 2, 2016
1 parent 0e11b7f commit 56addae
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
10 changes: 9 additions & 1 deletion src/battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ battle.action.skill = function(skill) {
actions.showText(skill)
}

battle.start = function(monsterlist) {
battle.start = function(monsterlist, musicBattle, musicHuzzah) {
battle.musicHuzzah = musicHuzzah
battle.musicBattle = musicBattle
battle.holdAtomStack = engine.atomStack
engine.atomStack = new Array();
battle.monster = [];
Expand All @@ -204,6 +206,7 @@ battle.start = function(monsterlist) {
battle.skills = resources.hms.Skills

battle.setOrderStack();
bgmusic.play(battle.musicBattle)
actions.fadeIn('blackFadeIn;doNotKeep')

}
Expand Down Expand Up @@ -265,6 +268,7 @@ battle.resolveIfSideDead = function() {
battle.order.pop();
}
battle.ended = true
bgmusic.play(battle.musicHuzzah)
actions.showText("You win!")
battle.end("win")
return true
Expand Down Expand Up @@ -541,6 +545,10 @@ battle.end = function(battleresult) {
engine.atomStack.push([function() {
engine.atomStack = battle.holdAtomStack
}, ''])
battle.holdAtomStack.push([function() {
bgmusic.popSong()
}, ''])

}

battle.isPartyAlive = function() {
Expand Down
35 changes: 25 additions & 10 deletions src/bgmusic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@

bgmusic = {
setup: function(){
this.songStack = [];
this.playing = '';
},
play: function(song) {
if(this.playing != song){
if(this.playing in resources.music){
resources.music[this.playing].pause();
}
this.playing = song;
resources.music[song].volume = 0.7
resources.music[song].currentTime = 0;
resources.music[song].play();
}
play: function(song, volume, currentTime) {
volume = (typeof volume === "undefined") ? 0.7 : volume;
currentTime = (typeof currentTime === "undefined") ? 0 : currentTime;
if(this.playing != song){
if(this.playing in resources.music){
resources.music[this.playing].pause();
}

this.playing = song;
resources.music[song].volume = volume;
resources.music[song].currentTime = currentTime;
resources.music[song].play();
}
},
pushSong: function(){
var song = this.playing;
this.songStack.push({ song: song,
volume: resources.music[song].volume,
currentTime: resources.music[song].currentTime,
});
},
popSong: function(){
var sp = this.songStack.pop();
this.play(sp.song, sp.volume, sp.currentTime)
}
}
4 changes: 3 additions & 1 deletion src/descriptors/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
},
"World": {
"initLevel": "playerhouse",
"initMusic": "opening"
"initMusic": "opening",
"battleMusic": "battle_1",
"battleVictoryMusic": "battle_win"
},
"itemsFile": "items.json"
}
15 changes: 14 additions & 1 deletion src/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,20 @@ engine.actions.subtractItem = function(param) {
}

engine.actions.battle = function(param) {
battle.start(param)
var monsterlist = [];
var musicBattle = resources.init['World']['battleMusic'];
var musicHuzzah = resources.init['World']['battleVictoryMusic'];
for(var i=0; i<param.length; i++){
if(param[i].indexOf("music:") == 0){
musicBattle = value.split('music:')[1];
} else if (param[i].indexOf("musicwin:") == 0) {
musicHuzzah = value.split('musicwin:')[1];
} else {
monsterlist.push(param[i]);
}
}
bgmusic.pushSong()
battle.start(monsterlist, musicBattle, musicHuzzah)
}

engine.actions.changeState = function(param) {
Expand Down
3 changes: 2 additions & 1 deletion src/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ resources.harvest = function(callback) {
}, true);
resources[resDict.to[0]][resDict.to[1]].addEventListener('loadeddata',loadeddata);
resources[resDict.to[0]][resDict.to[1]].src = resDict.from;
resources[resDict.to[0]][resDict.to[1]].load();
resources[resDict.to[0]][resDict.to[1]].preload = 'auto';
resources[resDict.to[0]][resDict.to[1]].load(); //triggers download for browsers that don't detect change of src
resDict.isScheduled = true;
}
};
Expand Down

0 comments on commit 56addae

Please sign in to comment.