Update: CC - SnailRunner - Before Render (94xi7aitax.js) 1610 bytes modified
parent
43769c4544
commit
f97b60de78
|
@ -14,95 +14,20 @@ if (!this.initialized) {
|
|||
|
||||
this.time = 0;
|
||||
|
||||
this.clouds = [];
|
||||
|
||||
this.spawnCloud = function() {
|
||||
|
||||
var cloud = this.cloud.clone();
|
||||
|
||||
this.cloud.position.x = -155;
|
||||
this.cloud.position.z = (Math.random() * 25) - 12.5;
|
||||
this.cloud.updateInstance('position');
|
||||
|
||||
this.clouds.push(cloud);
|
||||
}
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
var diff = data.delta * this.entityLoaded.speed;
|
||||
|
||||
var cloudInfo = this.clouds.reduce(
|
||||
function(result, cloud) {
|
||||
cloud.position.x += diff;
|
||||
cloud.updateInstance('position');
|
||||
|
||||
if (cloud.position.x > 48) {
|
||||
result.dead.push(cloud);
|
||||
} else {
|
||||
result.alive.push(cloud);
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
{
|
||||
alive : [],
|
||||
dead : []
|
||||
}
|
||||
);
|
||||
this.advanceClouds(diff);
|
||||
|
||||
this.clouds = cloudInfo.alive;
|
||||
this.advanceRoadSections(diff);
|
||||
|
||||
cloudInfo.dead.map(
|
||||
function(deadCloud) {
|
||||
deadCloud.geometry = null;
|
||||
deadCloud.materials = null;
|
||||
deadCloud.remove();
|
||||
}
|
||||
)
|
||||
this.advanceCamera(data.delta);
|
||||
|
||||
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 > 48) {
|
||||
section.left.position.x -= 204;
|
||||
section.road.position.x -= 204;
|
||||
section.right.position.x -= 204;
|
||||
}
|
||||
|
||||
section.left.updateInstance('position');
|
||||
section.road.updateInstance('position');
|
||||
section.right.updateInstance('position');
|
||||
}
|
||||
);
|
||||
|
||||
//return;
|
||||
|
||||
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 * this.entityLoaded.speed;
|
||||
this.time += diff;
|
||||
|
||||
if (this.time > 0.5) {
|
||||
this.spawnCloud();
|
||||
|
|
Loading…
Reference in New Issue