79 lines
1.6 KiB
JavaScript
79 lines
1.6 KiB
JavaScript
if (!this.entityLoaded) {
|
|
return;
|
|
}
|
|
|
|
if (!this.initialized) {
|
|
|
|
/**
|
|
* Meshes
|
|
*/
|
|
this.sections = this.entityLoaded.sections;
|
|
this.cloud = this.entityLoaded.cloud;
|
|
this.camera = this.entityLoaded.camera;
|
|
this.snail = this.entityLoaded.snail;
|
|
|
|
this.time = 0;
|
|
|
|
this.speed = 15;
|
|
|
|
this.spawnCloud = function() {
|
|
this.cloud.position.x = -155;
|
|
this.cloud.position.z = (Math.random() * 10) - 5;
|
|
this.cloud.updateInstance('position');
|
|
}
|
|
|
|
this.initialized = true;
|
|
}
|
|
|
|
var diff = data.delta * this.speed;
|
|
|
|
this.cloud.position.x += diff;
|
|
this.cloud.updateInstance('position');
|
|
|
|
this.sections.map(
|
|
function(section) {
|
|
section.left.position.x += diff;
|
|
section.road.position.x += diff;
|
|
section.right.position.x += diff;
|
|
|
|
if (section.left.position.x > 50) {
|
|
section.left.position.x -= 200;
|
|
section.road.position.x -= 200;
|
|
section.right.position.x -= 200;
|
|
}
|
|
|
|
section.left.updateInstance('position');
|
|
section.road.updateInstance('position');
|
|
section.right.updateInstance('position');
|
|
}
|
|
);
|
|
|
|
var modified = false;
|
|
|
|
if ((this.camera.position.z - this.snail.position.z) > 0.01) {
|
|
this.camera.position.z -= data.delta;
|
|
modified = true;
|
|
}
|
|
|
|
if ((this.snail.position.z - this.camera.position.z) > 0.01) {
|
|
this.camera.position.z += data.delta;
|
|
modified = true;
|
|
}
|
|
|
|
if (modified) {
|
|
this.camera.updateInstance('position');
|
|
|
|
this.camera.lookAt.x = this.snail.position.x;
|
|
this.camera.lookAt.y = this.snail.position.y;
|
|
this.camera.lookAt.z = this.snail.position.z;
|
|
this.camera.updateInstance('lookAt');
|
|
}
|
|
|
|
this.time += data.delta;
|
|
|
|
if (this.time > 5) {
|
|
this.spawnCloud();
|
|
this.time = 0;
|
|
}
|
|
|
|
//@ sourceURL=beforeRender.js
|