|
@@ -1,4 +1,4 @@
|
|
|
-function SoundSafari(beatInfo) {
|
|
|
+function SoundSafari(beatInfo, endless) {
|
|
|
var canvas = Game.canvas;
|
|
|
var ctx = Game.context;
|
|
|
|
|
@@ -36,16 +36,26 @@ function SoundSafari(beatInfo) {
|
|
|
events: [
|
|
|
{name: 'ready', from: 'loading', to: 'waiting'},
|
|
|
{name: 'play', from: 'waiting', to: 'playing'},
|
|
|
- {name: 'point', from: 'playing', to: 'waiting'}
|
|
|
+ {name: 'point', from: 'playing', to: 'waiting'},
|
|
|
+ {name: 'win', from: 'waiting', to: 'ending'},
|
|
|
+ {name: 'end', from: 'ending', to: 'done'}
|
|
|
],
|
|
|
callbacks: {
|
|
|
onready: function() {
|
|
|
reset();
|
|
|
},
|
|
|
+ onend: function() {
|
|
|
+ Game.sceneManager.pop();
|
|
|
+ },
|
|
|
onpoint: function() {
|
|
|
++points;
|
|
|
soundManager.play('get');
|
|
|
- switchBeat(points % beats.length);
|
|
|
+ if(!endless && points >= beats.length) {
|
|
|
+ state.win();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ switchBeat(points % beats.length);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -223,7 +233,7 @@ function SoundSafari(beatInfo) {
|
|
|
var a = 0.9;
|
|
|
this.alpha = Math.min(1, activeTarget.shimmerFactor * (this.alpha * (1-a) + newAlpha * a));
|
|
|
}
|
|
|
- else if(state.current == 'waiting') {
|
|
|
+ else if(state.current == 'waiting' || state.current == 'ending') {
|
|
|
this.alpha = this.alpha * 0.95;
|
|
|
}
|
|
|
};
|
|
@@ -329,7 +339,7 @@ function SoundSafari(beatInfo) {
|
|
|
function switchBeat(index) {
|
|
|
var currentBeat = beats[index];
|
|
|
currentBeats.push(currentBeat);
|
|
|
- if(currentBeats.length > 4) {
|
|
|
+ if(currentBeats.length > Math.min(4, beats.length)) {
|
|
|
currentBeats.splice(0, 1);
|
|
|
}
|
|
|
|
|
@@ -378,14 +388,22 @@ function SoundSafari(beatInfo) {
|
|
|
if(state.current == 'loading') return;
|
|
|
var delta = dt * 1000;
|
|
|
|
|
|
- currentBeats.map(function(beat) {
|
|
|
+ for(var i = currentBeats.length-1; i >= 0; --i) {
|
|
|
+ var beat = currentBeats[i];
|
|
|
if(gameTime + delta > nextPlayTime(beat.info.duration)) {
|
|
|
+ if(state.current == 'ending' && i == 0) {
|
|
|
+ currentBeats.splice(0, 1);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
if(beat == activeTarget.beat && state.current == 'waiting') {
|
|
|
state.play();
|
|
|
}
|
|
|
beat.sound.play();
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
+ if(currentBeats.length == 0 && state.can('end')) {
|
|
|
+ state.end();
|
|
|
+ }
|
|
|
|
|
|
if(37 in Game.keysDown) {
|
|
|
player.x -= player.dx * dt;
|