Cleaning Coin

This commit is contained in:
Thomas FORGIONE 2015-10-02 15:21:29 +02:00
parent 0e3eae5ff1
commit f17ea91581
3 changed files with 40 additions and 48 deletions

View File

@ -230,43 +230,43 @@ Coin.prototype.update = function() {
}; };
Coin.prototype.get = function() { Coin.prototype.get = function() {
if (!this.got) { if (this.got) {
this.got = true; return;
if (typeof Coin.onCoinGot === 'function') {
Coin.onCoinGot(Coin.total + 1);
}
// Call the callback if any
if (this.callback)
this.callback();
this.mesh.material.transparent = true;
this.mesh.material.opacity = 1;
Coin.sounds[Coin.total ++].play();
if (Coin.total === 8) {
if (typeof Coin.onLastCoin === 'function') {
Coin.onLastCoin();
}
// You got the last coin
var music = document.getElementById('music');
if (music !== null) {
var wasPlaying = !music.paused;
music.pause();
setTimeout(function() {
Coin.lastSound.play();
setTimeout(function() {
if (wasPlaying) {
music.play();
}
}, Coin.lastSound.duration*1000);
}, Coin.nextSound.duration*1000);
}
}
Coin.set();
} }
this.got = true;
if (typeof Coin.onCoinGot === 'function') {
Coin.onCoinGot(Coin.total + 1);
}
// Call the callback if any
if (this.callback)
this.callback();
this.mesh.material.transparent = true;
this.mesh.material.opacity = 1;
Coin.sounds[Coin.total ++].play();
if (Coin.total === Coin.max) {
// You got the last coin
var music = document.getElementById('music');
if (music !== null) {
var wasPlaying = !music.paused;
music.pause();
setTimeout(function() {
Coin.lastSound.play();
setTimeout(function() {
if (wasPlaying) {
music.play();
}
}, Coin.lastSound.duration*1000);
}, Coin.nextSound.duration*1000);
}
}
Coin.set();
}; };
Coin.lastSound = new Audio('/static/data/music/starappears' + Coin.extension); Coin.lastSound = new Audio('/static/data/music/starappears' + Coin.extension);

View File

@ -44,11 +44,11 @@ var nextPage = '/prototype/play';
Coin.onCoinGot = function(coin) { Coin.onCoinGot = function(coin) {
if (coin === 6) { if (coin === 6) {
setTimeout(function() { setNextButton(nextPage); }, 60*1000); setTimeout(function() { setNextButton(nextPage); }, 60*1000);
} else if (coin === 8) {
setNextButton(nextPage);
} }
}; };
Coin.onLastCoin = function() { setNextButton(nextPage); };
function main() { function main() {
// Main container that holds everything // Main container that holds everything

View File

@ -23,11 +23,11 @@ var nextPage = '/before-begin';
Coin.onCoinGot = function(val) { Coin.onCoinGot = function(val) {
if (val === 6) { if (val === 6) {
setTimeout(function() {setNextButton(nextPage); }, 60*1000); setTimeout(function() {setNextButton(nextPage); }, 60*1000);
} else if (val === 8) {
setNextButton(nextPage);
} }
}; };
Coin.onLastCoin = function() { setNextButton(nextPage); };
window.onbeforeunload = function() { window.onbeforeunload = function() {
if (!($('#next').is(":visible"))) { if (!($('#next').is(":visible"))) {
@ -82,14 +82,6 @@ function main() {
// Log fps // Log fps
setInterval(function() {logfps(stats.getFps());}, 500); setInterval(function() {logfps(stats.getFps());}, 500);
Coin.onLastCoin = function() {
Coin.blink();
$('#next').click(function() {
window.location = '/before-begin';
});
$('#next').show();
};
} }
function initThreeElements() { function initThreeElements() {