Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 150 bytes modified

beta.r3js.org
-=yb4f310 2018-03-13 14:49:00 +01:00
parent 5b06f6af59
commit 29ea731772
1 changed files with 44 additions and 43 deletions

View File

@ -7,8 +7,8 @@ if (this.parentEntity === data.entity) {
/** /**
* Defines * Defines
*/ */
GameLib.CustomCode.BODY_TYPE_HEAD = 0x1; GameLib.CustomCode.BODY_TYPE_NORMAL = 0x1;
GameLib.CustomCode.BODY_TYPE_TAIL = 0x2; GameLib.CustomCode.BODY_TYPE_TAIL = 0x2;
GameLib.CustomCode.GRID_WIDTH = 11; GameLib.CustomCode.GRID_WIDTH = 11;
GameLib.CustomCode.GRID_HEIGHT = 11; GameLib.CustomCode.GRID_HEIGHT = 11;
@ -37,7 +37,7 @@ this.geometryBody = GameLib.EntityManager.Instance.findComponentById('8f5q7k5ozp
/** /**
* Images * Images
*/ */
this.imageEnd = GameLib.EntityManager.Instance.findComponentById('swkla3wpp'); this.imageBreadEnd = GameLib.EntityManager.Instance.findComponentById('swkla3wpp');
this.imageBreadPatty = GameLib.EntityManager.Instance.findComponentById('01r51k9ptr'); this.imageBreadPatty = GameLib.EntityManager.Instance.findComponentById('01r51k9ptr');
this.imageBreadCorner = GameLib.EntityManager.Instance.findComponentById('iljpuouaok'); this.imageBreadCorner = GameLib.EntityManager.Instance.findComponentById('iljpuouaok');
this.imagePatty = GameLib.EntityManager.Instance.findComponentById('4lf0fw24su'); this.imagePatty = GameLib.EntityManager.Instance.findComponentById('4lf0fw24su');
@ -56,8 +56,8 @@ this.speed = GameLib.CustomCode.SPEED_INITIAL;
this.advanceTime = 0; this.advanceTime = 0;
this.state = { this.state = {
direction : { direction : {
x : -1, x : 0,
y : 0 y : 1
}, },
rotation : 0 rotation : 0
}; };
@ -97,14 +97,15 @@ GameLib.CustomCode.prototype.createGameMesh = function(image) {
/** /**
* Create our objects * Create our objects
*/ */
this.meshEnd = this.createGameMesh(this.imageEnd); this.meshBreadEnd = this.createGameMesh(this.imageBreadEnd);
this.meshEnd.useQuaternion = false; this.meshBreadEnd.useQuaternion = false;
this.meshPatty = this.createGameMesh(this.imagePatty); this.meshPatty = this.createGameMesh(this.imagePatty);
this.meshBodyPatty = this.createGameMesh(this.imageBodyPatty);
this.meshBreadPatty = this.createGameMesh(this.imageBreadPatty);
this.meshBreadCorner = this.createGameMesh(this.imageBreadCorner);
GameLib.CustomCode.SnakeBody = function( GameLib.CustomCode.SnakeBody = function(
bodyType,
mesh, mesh,
position, position,
rotation rotation
@ -128,37 +129,13 @@ GameLib.CustomCode.SnakeBody = function(
this.position = position; this.position = position;
if (GameLib.Utils.UndefinedOrNull(rotation)) { if (GameLib.Utils.UndefinedOrNull(rotation)) {
rotation = Math.PI / 2; rotation = 0;
} }
this.rotation = rotation; this.rotation = rotation;
switch (this.bodyType) {
case GameLib.CustomCode.BODY_TYPE_HEAD :
break;
case GameLib.CustomCode.BODY_TYPE_TAIL :
this.rotation += Math.PI;
this.position.x += 1;
break;
default :
throw new Error('unreachable statement');
break;
}
this.applyToMesh(); this.applyToMesh();
}; };
/*
GameLib.CustomCode.SnakeBody.prototype.clone = function() {
return new GameLib.CustomCode.SnakeBody(
this.bodyType,
this.mesh,
{
x : this.position.x,
y : this.position.y
}
);
}
*/
GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function() { GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function() {
this.mesh.position.x = this.position.x + GameLib.CustomCode.GRID_OFFSET_X; this.mesh.position.x = this.position.x + GameLib.CustomCode.GRID_OFFSET_X;
@ -220,7 +197,7 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
body.position.x = position.x; body.position.x = position.x;
body.position.y = position.y; body.position.y = position.y;
body.rotation += this.state.rotation; //body.rotation += this.state.rotation;
position.x = tempPosition.x; position.x = tempPosition.x;
position.y = tempPosition.y; position.y = tempPosition.y;
@ -275,20 +252,44 @@ GameLib.Event.Subscribe(
this.state = { this.state = {
direction : { direction : {
x : -1, x : 0,
y : 0 y : 1
}, },
rotation : Math.PI / 2 rotation : 0
}; };
this.snake = [ this.snake = [
new GameLib.CustomCode.SnakeBody( new GameLib.CustomCode.SnakeBody(
GameLib.CustomCode.BODY_TYPE_HEAD, this.meshBreadEnd,
this.meshEnd {
x : 4,
y : 4
},
0
), ),
new GameLib.CustomCode.SnakeBody( new GameLib.CustomCode.SnakeBody(
GameLib.CustomCode.BODY_TYPE_TAIL, this.meshBreadPatty,
this.meshEnd {
x : 4,
y : 3
},
0
),
new GameLib.CustomCode.SnakeBody(
this.meshBreadPatty,
{
x : 4,
y : 2
},
0
),
new GameLib.CustomCode.SnakeBody(
this.meshBreadEnd,
{
x : 4,
y : 1
},
Math.PI
) )
]; ];