From f17ea9158155cfbe487d46d2125560208c27ff48 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Fri, 2 Oct 2015 15:21:29 +0200 Subject: [PATCH] Cleaning Coin --- js/l3d/apps/prototype/Coin.js | 72 +++++++++++------------ js/l3d/apps/prototype/interactive/main.js | 4 +- js/l3d/apps/prototype/tutorial/main.js | 12 +--- 3 files changed, 40 insertions(+), 48 deletions(-) diff --git a/js/l3d/apps/prototype/Coin.js b/js/l3d/apps/prototype/Coin.js index 3d63287..82260ce 100644 --- a/js/l3d/apps/prototype/Coin.js +++ b/js/l3d/apps/prototype/Coin.js @@ -230,43 +230,43 @@ Coin.prototype.update = function() { }; Coin.prototype.get = function() { - if (!this.got) { - 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 === 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(); + if (this.got) { + return; } + 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); diff --git a/js/l3d/apps/prototype/interactive/main.js b/js/l3d/apps/prototype/interactive/main.js index 627acce..d4e0383 100644 --- a/js/l3d/apps/prototype/interactive/main.js +++ b/js/l3d/apps/prototype/interactive/main.js @@ -44,11 +44,11 @@ var nextPage = '/prototype/play'; Coin.onCoinGot = function(coin) { if (coin === 6) { setTimeout(function() { setNextButton(nextPage); }, 60*1000); + } else if (coin === 8) { + setNextButton(nextPage); } }; -Coin.onLastCoin = function() { setNextButton(nextPage); }; - function main() { // Main container that holds everything diff --git a/js/l3d/apps/prototype/tutorial/main.js b/js/l3d/apps/prototype/tutorial/main.js index 1f28d22..73ea89f 100644 --- a/js/l3d/apps/prototype/tutorial/main.js +++ b/js/l3d/apps/prototype/tutorial/main.js @@ -23,11 +23,11 @@ var nextPage = '/before-begin'; Coin.onCoinGot = function(val) { if (val === 6) { setTimeout(function() {setNextButton(nextPage); }, 60*1000); + } else if (val === 8) { + setNextButton(nextPage); } }; -Coin.onLastCoin = function() { setNextButton(nextPage); }; - window.onbeforeunload = function() { if (!($('#next').is(":visible"))) { @@ -82,14 +82,6 @@ function main() { // Log fps setInterval(function() {logfps(stats.getFps());}, 500); - Coin.onLastCoin = function() { - Coin.blink(); - $('#next').click(function() { - window.location = '/before-begin'; - }); - $('#next').show(); - }; - } function initThreeElements() {