2018-03-09 00:36:32 +01:00
|
|
|
if (data.entity === this.parentEntity) {
|
|
|
|
console.log('snail runner loaded');
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom Code Components
|
|
|
|
*/
|
|
|
|
this.beforeRender = GameLib.EntityManager.Instance.findComponentById('94xi7aitax');
|
|
|
|
this.mouseMove = GameLib.EntityManager.Instance.findComponentById('jz3qg0174l');
|
2018-03-09 14:49:40 +01:00
|
|
|
this.mouseDown = GameLib.EntityManager.Instance.findComponentById('8dntnb01wu');
|
2018-03-09 14:55:00 +01:00
|
|
|
this.mouseUp = GameLib.EntityManager.Instance.findComponentById('kx7drv1vqw');
|
|
|
|
this.keyDown = GameLib.EntityManager.Instance.findComponentById('ramgcjepp5');
|
|
|
|
this.keyUp = GameLib.EntityManager.Instance.findComponentById('4uie4sjqxd');
|
2018-03-09 00:36:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Meshes
|
|
|
|
*/
|
|
|
|
this.snail = GameLib.EntityManager.Instance.findComponentById('z2izbq1hcz');
|
|
|
|
this.cloud = GameLib.EntityManager.Instance.findComponentById('jbvm17iwfx');
|
|
|
|
this.solar = GameLib.EntityManager.Instance.findComponentById('lq5xyiu8n4');
|
2018-03-09 01:45:57 +01:00
|
|
|
this.treesLeft = GameLib.EntityManager.Instance.findComponentById('lq0rxnjq3n');
|
|
|
|
this.treesRight = GameLib.EntityManager.Instance.findComponentById('oag0yr1rav');
|
|
|
|
this.road = GameLib.EntityManager.Instance.findComponentById('4furha3wst');
|
|
|
|
|
|
|
|
/**
|
2018-03-09 15:14:42 +01:00
|
|
|
* Road Sections and Clouds
|
2018-03-09 01:45:57 +01:00
|
|
|
*/
|
2018-03-09 15:14:42 +01:00
|
|
|
this.sections = [];
|
|
|
|
this.clouds = [];
|
2018-03-09 01:45:57 +01:00
|
|
|
|
2018-03-09 02:47:05 +01:00
|
|
|
/**
|
|
|
|
* Camera
|
|
|
|
*/
|
|
|
|
this.camera = GameLib.EntityManager.Instance.findComponentById('hd8dsn7o4c');
|
|
|
|
|
2018-03-09 15:14:42 +01:00
|
|
|
GameLib.CustomCode.prototype.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);
|
|
|
|
}.bind(this)
|
|
|
|
|
|
|
|
GameLib.CustomCode.prototype.spawnRoadSections = function() {
|
2018-03-09 15:03:11 +01:00
|
|
|
|
2018-03-09 15:14:42 +01:00
|
|
|
var cloneLeft = this.treesLeft.clone();
|
|
|
|
var cloneRoad = this.road.clone();
|
|
|
|
var cloneRight = this.treesRight.clone();
|
|
|
|
|
|
|
|
for (var i = 0; i < 17; i++) {
|
|
|
|
|
|
|
|
this.sections.push({
|
|
|
|
left : cloneLeft,
|
|
|
|
road : cloneRoad,
|
|
|
|
right : cloneRight
|
|
|
|
})
|
|
|
|
|
|
|
|
cloneLeft = cloneLeft.clone();
|
|
|
|
cloneRoad = cloneRoad.clone();
|
|
|
|
cloneRight = cloneRight.clone();
|
|
|
|
}
|
2018-03-09 01:45:57 +01:00
|
|
|
|
|
|
|
this.sections.push({
|
|
|
|
left : cloneLeft,
|
|
|
|
road : cloneRoad,
|
|
|
|
right : cloneRight
|
|
|
|
})
|
2018-03-09 00:36:32 +01:00
|
|
|
|
2018-03-09 15:14:42 +01:00
|
|
|
}.bind(this)
|
2018-03-09 03:19:54 +01:00
|
|
|
|
2018-03-09 15:20:15 +01:00
|
|
|
GameLib.CustomCode.prototype.advanceClouds = function(diff) {
|
|
|
|
|
|
|
|
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.clouds = cloudInfo.alive;
|
|
|
|
|
|
|
|
cloudInfo.dead.map(
|
|
|
|
function(deadCloud) {
|
|
|
|
deadCloud.geometry = null;
|
|
|
|
deadCloud.materials = null;
|
|
|
|
deadCloud.remove();
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
GameLib.CustomCode.prototype.advanceRoadSections = function(diff) {
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
GameLib.CustomCode.prototype.advanceCamera = function(delta) {
|
|
|
|
var modified = false;
|
|
|
|
|
2018-03-09 15:37:10 +01:00
|
|
|
if ((this.camera.position.z - this.snail.position.z) > (0.05)) {
|
2018-03-09 15:34:36 +01:00
|
|
|
this.camera.position.z -= this.speed * delta;
|
2018-03-09 15:20:15 +01:00
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
|
2018-03-09 15:37:10 +01:00
|
|
|
if ((this.snail.position.z - this.camera.position.z) > (0.05)) {
|
2018-03-09 15:34:36 +01:00
|
|
|
this.camera.position.z += this.speed * delta;
|
2018-03-09 15:20:15 +01:00
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modified) {
|
|
|
|
this.camera.lookAt.x = this.snail.position.x;
|
|
|
|
this.camera.lookAt.y = this.snail.position.y;
|
|
|
|
this.camera.lookAt.z = this.snail.position.z;
|
2018-03-09 15:37:10 +01:00
|
|
|
|
|
|
|
this.camera.updateInstance('position');
|
2018-03-09 15:20:15 +01:00
|
|
|
this.camera.updateInstance('lookAt');
|
|
|
|
}
|
|
|
|
}.bind(this);
|
|
|
|
|
2018-03-09 15:25:55 +01:00
|
|
|
GameLib.CustomCode.prototype.adjustSpeed = function(delta) {
|
|
|
|
|
|
|
|
if (this.speedUp) {
|
|
|
|
this.speed += delta;
|
2018-03-09 15:28:41 +01:00
|
|
|
} else {
|
|
|
|
this.speed -= delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.speed < 0) {
|
|
|
|
this.speed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.speed > 50) {
|
|
|
|
this.speed = 50;
|
2018-03-09 15:25:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}.bind(this);
|
|
|
|
|
2018-03-09 15:48:20 +01:00
|
|
|
GameLib.CustomCode.prototype.adjustSnailPosition = function(delta) {
|
2018-03-09 15:31:33 +01:00
|
|
|
|
2018-03-09 15:48:20 +01:00
|
|
|
var diff = 0;
|
|
|
|
var modified = false;
|
|
|
|
|
|
|
|
if (this.movement.left) {
|
|
|
|
diff = data.delta * this.speed * 0.01;
|
|
|
|
this.snail.position.z -= diff;
|
|
|
|
this.movement.left = false;
|
|
|
|
modified = true;
|
2018-03-09 15:31:33 +01:00
|
|
|
}
|
2018-03-09 15:48:20 +01:00
|
|
|
|
|
|
|
if (this.movement.right) {
|
|
|
|
diff = data.delta * this.speed * 0.01;
|
|
|
|
this.snail.position.z += diff;
|
|
|
|
this.movement.right = false;
|
|
|
|
modified = true;
|
2018-03-09 15:31:33 +01:00
|
|
|
}
|
2018-03-09 15:48:20 +01:00
|
|
|
|
|
|
|
if (modified) {
|
|
|
|
if (this.snail.position.z < -4.8) {
|
|
|
|
this.snail.position.z = -4.8;
|
|
|
|
}
|
2018-03-09 15:31:33 +01:00
|
|
|
|
2018-03-09 15:48:20 +01:00
|
|
|
if (this.snail.position.z > 4.8) {
|
|
|
|
this.snail.position.z = 4.8;
|
|
|
|
}
|
2018-03-09 15:31:33 +01:00
|
|
|
|
2018-03-09 15:48:20 +01:00
|
|
|
this.solar.position.z = this.snail.position.z;
|
|
|
|
|
|
|
|
this.snail.updateInstance('position');
|
|
|
|
this.solar.updateInstance('position');
|
|
|
|
}
|
2018-03-09 15:31:33 +01:00
|
|
|
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
|
2018-03-09 15:10:16 +01:00
|
|
|
GameLib.Event.Subscribe(
|
|
|
|
GameLib.Event.GAME_START,
|
|
|
|
function() {
|
|
|
|
/**
|
|
|
|
* Game Variables
|
|
|
|
*/
|
|
|
|
this.snail.position.z = 0;
|
|
|
|
this.speed = 0;
|
|
|
|
this.speedUp = false;
|
|
|
|
|
2018-03-09 15:48:20 +01:00
|
|
|
this.movement = {
|
|
|
|
left : false,
|
|
|
|
right : false,
|
|
|
|
leftAmount : 0,
|
|
|
|
rightAmount : 0
|
|
|
|
};
|
|
|
|
|
2018-03-09 15:14:42 +01:00
|
|
|
this.clouds.map(
|
|
|
|
function(cloud) {
|
|
|
|
cloud.geometry = null;
|
|
|
|
cloud.materials = null;
|
|
|
|
cloud.remove();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.clouds = [];
|
|
|
|
|
2018-03-09 15:10:16 +01:00
|
|
|
/**
|
|
|
|
* Activate our custom code components
|
|
|
|
*/
|
|
|
|
this.beforeRender.entityLoaded = this;
|
|
|
|
this.mouseMove.entityLoaded = this;
|
|
|
|
this.mouseDown.entityLoaded = this;
|
|
|
|
this.mouseUp.entityLoaded = this;
|
|
|
|
this.keyDown.entityLoaded = this;
|
|
|
|
this.keyUp.entityLoaded = this;
|
|
|
|
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
2018-03-09 15:14:42 +01:00
|
|
|
this.spawnRoadSections();
|
2018-03-09 00:36:32 +01:00
|
|
|
|
2018-03-09 15:25:01 +01:00
|
|
|
GameLib.Event.Emit(GameLib.Event.GAME_LOADED);
|
|
|
|
|
2018-03-09 00:36:32 +01:00
|
|
|
//@ sourceURL=entityLoaded.js
|