coins is now private

This commit is contained in:
Thomas FORGIONE 2015-06-03 10:06:55 +02:00
parent 49a26c60bc
commit c2c25a5588
7 changed files with 56 additions and 43 deletions

View File

@ -6,11 +6,12 @@ var TutoCamera = function() {
this.onWindowResize = arguments[6]; this.onWindowResize = arguments[6];
var scene = arguments[5]; var scene = arguments[5];
var container_size = arguments[7]; var container_size = arguments[7];
var coins = arguments[8];
if (arguments[8] === undefined) if (arguments[9] === undefined)
listenerTarget = document; listenerTarget = document;
else else
listenerTarget = arguments[8]; listenerTarget = arguments[9];
// Set Position // Set Position
this.theta = Math.PI; this.theta = Math.PI;
@ -63,7 +64,7 @@ var TutoCamera = function() {
this.resetElements = resetBobombElements(); this.resetElements = resetBobombElements();
// Create tutorial // Create tutorial
this.tutorial = new TutorialSteps(this, scene, this.onWindowResize, container_size); this.tutorial = new TutorialSteps(this, scene, coins, this.onWindowResize, container_size);
} }
TutoCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype); TutoCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
TutoCamera.prototype.constructor = TutoCamera; TutoCamera.prototype.constructor = TutoCamera;

View File

@ -34,7 +34,6 @@ Coin.prototype.addToScene = function(scene) {
Coin.prototype.update = function() { Coin.prototype.update = function() {
var self = this; var self = this;
console.log(this.ready, this.rotating);
if (this.ready && this.rotating) if (this.ready && this.rotating)
this.mesh.rotation.y += 0.1 this.mesh.rotation.y += 0.1
} }

View File

@ -1,11 +1,12 @@
var nextStep; var nextStep;
var TutorialSteps = function(tutoCamera, scene, onWindowResize, container_size) { var TutorialSteps = function(tutoCamera, scene, coins, onWindowResize, container_size) {
this.camera = tutoCamera; this.camera = tutoCamera;
this.step = 0; this.step = 0;
this.coins = 0; this.coinNumber = 0;
this.camera.allowed = {}; this.camera.allowed = {};
this.onWindowResize = onWindowResize; this.onWindowResize = onWindowResize;
this.container_size = container_size; this.container_size = container_size;
this.coins = coins;
this.instructions = [ this.instructions = [
{ {
@ -95,7 +96,7 @@ TutorialSteps.prototype.setCameras = function(cameras) {
TutorialSteps.prototype.nextStep = function() { TutorialSteps.prototype.nextStep = function() {
if (this.step < this.instructions.length) { if (this.step < this.instructions.length) {
this.alert(this.instructions[this.step].text, this.instructions[this.step].justclick); this.alert(this.instructions[this.step].text, this.instructions[this.step].justclick);
var callback = function() {self.coins++; self.nextStep();}; var callback = function() {self.coinNumber++; self.nextStep();};
var self = this; var self = this;
switch (this.step) { switch (this.step) {
case 0: break; case 0: break;
@ -103,24 +104,24 @@ TutorialSteps.prototype.nextStep = function() {
case 2: this.camera.allowed.keyboardRotate = true; break; case 2: this.camera.allowed.keyboardRotate = true; break;
case 3: case 3:
this.camera.allowed.keyboardRotate = true; this.camera.allowed.keyboardRotate = true;
coins.push(new Coin(0.4911245636058468,1.225621525492101,-5.11526684540265, callback)); this.coins.push(new Coin(0.4911245636058468,1.225621525492101,-5.11526684540265, callback));
coins[coins.length-1].addToScene(this.scene); this.coins[this.coins.length-1].addToScene(this.scene);
break; break;
case 4: case 4:
coins.push(new Coin(1.4074130964382279,0.6458319586843252,-6.75244526999632, callback)); this.coins.push(new Coin(1.4074130964382279,0.6458319586843252,-6.75244526999632, callback));
coins[coins.length-1].addToScene(this.scene); this.coins[this.coins.length-1].addToScene(this.scene);
coins.push(new Coin(-4.2701659473968965,0.6745750513698942,-0.484545726832743, callback)); this.coins.push(new Coin(-4.2701659473968965,0.6745750513698942,-0.484545726832743, callback));
coins[coins.length-1].addToScene(this.scene); this.coins[this.coins.length-1].addToScene(this.scene);
coins.push(new Coin(-4.336597108439718,0.4203578350484251,-8.447211342176862, callback)); this.coins.push(new Coin(-4.336597108439718,0.4203578350484251,-8.447211342176862, callback));
coins[coins.length-1].addToScene(this.scene); this.coins[this.coins.length-1].addToScene(this.scene);
break; break;
case 7: case 7:
this.camera.move(this.camera.resetElements); this.camera.move(this.camera.resetElements);
break; break;
case 8: case 8:
this.camera.allowed.keyboardTranslate = true; this.camera.allowed.keyboardTranslate = true;
coins.push(new Coin(2.7378029903574026,2.953347730618792,-11.550836282321221, callback)); this.coins.push(new Coin(2.7378029903574026,2.953347730618792,-11.550836282321221, callback));
coins[coins.length-1].addToScene(this.scene); this.coins[this.coins.length-1].addToScene(this.scene);
break; break;
case 12: case 12:
var cam = createPeachCameras(this.container_size.width(), this.container_size.height())[2]; var cam = createPeachCameras(this.container_size.width(), this.container_size.height())[2];
@ -138,12 +139,12 @@ TutorialSteps.prototype.nextStep = function() {
cams[i].addToScene(this.scene); cams[i].addToScene(this.scene);
} }
coins.push(new Coin(3.701112872561801,-0.4620393514856378,-3.3373375945128085, callback)); this.coins.push(new Coin(3.701112872561801,-0.4620393514856378,-3.3373375945128085, callback));
coins[coins.length-1].addToScene(this.scene); this.coins[this.coins.length-1].addToScene(this.scene);
coins.push(new Coin(6.694675339780243,-1.2480369397526456,-1.992336719279164, callback)); this.coins.push(new Coin(6.694675339780243,-1.2480369397526456,-1.992336719279164, callback));
coins[coins.length-1].addToScene(this.scene); this.coins[this.coins.length-1].addToScene(this.scene);
coins.push(new Coin(-2.458336118265302,-1.549510268763568,-11.186153614421212, callback)); this.coins.push(new Coin(-2.458336118265302,-1.549510268763568,-11.186153614421212, callback));
coins[coins.length-1].addToScene(this.scene); this.coins[this.coins.length-1].addToScene(this.scene);
} }
this.step++; this.step++;
} }
@ -160,7 +161,7 @@ TutorialSteps.prototype.nextAction = function() {
} }
TutorialSteps.prototype.tryFinish = function() { TutorialSteps.prototype.tryFinish = function() {
if (this.coins === 8) { if (this.coinNumber === 8) {
console.log("Finished"); console.log("Finished");
} }
} }

View File

@ -89,7 +89,7 @@ function resetPeachElements() {
}; };
} }
function initPeach(camera, scene, static_path) { function initPeach(camera, scene, static_path, coins) {
addLight(scene); addLight(scene);
var loader = new THREE.OBJMTLLoader(); var loader = new THREE.OBJMTLLoader();
@ -106,7 +106,6 @@ function initPeach(camera, scene, static_path) {
scene.add(camera); scene.add(camera);
Coin.init(0.001); Coin.init(0.001);
coins = [];
} }
function initZeldaScene(scene, collidableObjects, loader, static_path) { function initZeldaScene(scene, collidableObjects, loader, static_path) {
@ -400,7 +399,7 @@ function createBobombCameras(width, height) {
} }
function initBobomb(camera, scene, static_path) { function initBobomb(camera, scene, static_path, coins) {
addLight(scene); addLight(scene);
var loader = new THREE.OBJMTLLoader(); var loader = new THREE.OBJMTLLoader();
@ -417,7 +416,11 @@ function initBobomb(camera, scene, static_path) {
scene.add(camera); scene.add(camera);
Coin.init(); Coin.init();
coins = createBobombCoins(); var tmp = createBobombCoins();
for (var i in tmp) {
coins.push(tmp[i]);
}
var otherCams = createBobombCameras(container_size.width(), container_size.height()); var otherCams = createBobombCameras(container_size.width(), container_size.height());
var cameras = new CameraContainer(camera, otherCams); var cameras = new CameraContainer(camera, otherCams);
@ -487,7 +490,7 @@ function resetWhompElements() {
}; };
} }
function initWhomp(camera, scene, static_path) { function initWhomp(camera, scene, static_path, coins) {
addLight(scene); addLight(scene);
var loader = new THREE.OBJMTLLoader(); var loader = new THREE.OBJMTLLoader();
@ -504,7 +507,11 @@ function initWhomp(camera, scene, static_path) {
scene.add(camera); scene.add(camera);
Coin.init(0.01); Coin.init(0.01);
coins = createWhompCoins(); var tmp = createWhompCoins();
for (var i in tmp) {
coins.push(tmp[i]);
}
var otherCams = createWhompCameras(container_size.width(), container_size.height()); var otherCams = createWhompCameras(container_size.width(), container_size.height());
var cameras = new CameraContainer(camera, otherCams); var cameras = new CameraContainer(camera, otherCams);
@ -578,7 +585,7 @@ function resetMountainElements() {
} }
} }
function initMountain(camera, scene, static_path) { function initMountain(camera, scene, static_path, coins) {
addLight(scene); addLight(scene);
var loader = new THREE.OBJMTLLoader(); var loader = new THREE.OBJMTLLoader();
@ -595,7 +602,11 @@ function initMountain(camera, scene, static_path) {
scene.add(camera); scene.add(camera);
Coin.init(); Coin.init();
coins = createMountainCoins(); var tmp = createMountainCoins();
for (var i in tmp) {
coins.push(tmp[i]);
}
var otherCams = createMountainCameras(container_size.width(), container_size.height()); var otherCams = createMountainCameras(container_size.width(), container_size.height());
var cameras = new CameraContainer(camera, otherCams); var cameras = new CameraContainer(camera, otherCams);

View File

@ -78,9 +78,9 @@ function init() {
// Initialize pointer camera // Initialize pointer camera
var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.01, 100000, renderer, container); var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.01, 100000, renderer, container);
// cameras = initBobomb(camera1, scene, static_path); // cameras = initBobomb(camera1, scene, static_path, coins);
// cameras = initWhomp(camera1, scene, static_path); // cameras = initWhomp(camera1, scene, static_path, coins);
cameras = initMountain(camera1, scene, static_path); cameras = initMountain(camera1, scene, static_path, coins);
// Add listeners // Add listeners
initListeners(); initListeners();
@ -109,7 +109,7 @@ function initListeners() {
buttonManager = new ButtonManager(cameras, previewer); buttonManager = new ButtonManager(cameras, previewer);
// Camera selecter for hover and clicking recommendations // Camera selecter for hover and clicking recommendations
cameraSelecter = new CameraSelecter(renderer, scene, cameras, buttonManager); cameraSelecter = new CameraSelecter(renderer, scene, cameras, coins, buttonManager);
} }
function render() { function render() {

View File

@ -1,4 +1,4 @@
var CameraSelecter = function(renderer, scene, cameras, buttonManager) { var CameraSelecter = function(renderer, scene, cameras, coins, buttonManager) {
this.raycaster = new THREE.Raycaster(); this.raycaster = new THREE.Raycaster();
this.renderer = renderer; this.renderer = renderer;
this.mouse = {}; this.mouse = {};
@ -6,6 +6,7 @@ var CameraSelecter = function(renderer, scene, cameras, buttonManager) {
this.prev = {}; this.prev = {};
this.buttonManager = buttonManager; this.buttonManager = buttonManager;
this.scene = scene; this.scene = scene;
this.coins = coins;
} }
CameraSelecter.prototype.pointedCamera = function() { CameraSelecter.prototype.pointedCamera = function() {
@ -43,9 +44,9 @@ CameraSelecter.prototype.pointedCamera = function() {
// if (this.cameras.getById(intersects[bestIndex].object.parent.id) !== undefined) { // if (this.cameras.getById(intersects[bestIndex].object.parent.id) !== undefined) {
var obj = intersects[bestIndex].object; var obj = intersects[bestIndex].object;
for (var coin in coins) { for (var coin in this.coins) {
if (obj === coins[coin].mesh) { if (obj === this.coins[coin].mesh) {
return coins[coin]; return this.coins[coin];
} }
} }
this.currentPointedCamera = this.cameras.getByObject(intersects[bestIndex].object); this.currentPointedCamera = this.cameras.getByObject(intersects[bestIndex].object);
@ -103,7 +104,7 @@ CameraSelecter.prototype.click = function(event) {
} else if (newCamera instanceof Coin) { } else if (newCamera instanceof Coin) {
// Coin found, notify server // Coin found, notify server
var event = new BD.Event.CoinClicked(); var event = new BD.Event.CoinClicked();
event.coin_id = coins.indexOf(newCamera); event.coin_id = this.coins.indexOf(newCamera);
event.send(); event.send();
newCamera.get(); newCamera.get();
} }

View File

@ -77,7 +77,7 @@ function init() {
container.appendChild(renderer.domElement); container.appendChild(renderer.domElement);
// Initialize pointer camera // Initialize pointer camera
var camera1 = new TutoCamera(50, container_size.width() / container_size.height(), 0.01, 100000, renderer, scene, onWindowResize, container_size, container); var camera1 = new TutoCamera(50, container_size.width() / container_size.height(), 0.01, 100000, renderer, scene, onWindowResize, container_size, coins, container);
tutorial = camera1.tutorial; tutorial = camera1.tutorial;
cameras = new CameraContainer(camera1, []); cameras = new CameraContainer(camera1, []);
@ -114,7 +114,7 @@ function initListeners() {
buttonManager = new ButtonManager(cameras, previewer); buttonManager = new ButtonManager(cameras, previewer);
// Camera selecter for hover and clicking recommendations // Camera selecter for hover and clicking recommendations
cameraSelecter = new CameraSelecter(renderer, scene, cameras, buttonManager); cameraSelecter = new CameraSelecter(renderer, scene, cameras, coins, buttonManager);
} }