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
*/
GameLib.CustomCode.BODY_TYPE_HEAD = 0x1;
GameLib.CustomCode.BODY_TYPE_TAIL = 0x2;
GameLib.CustomCode.BODY_TYPE_NORMAL = 0x1;
GameLib.CustomCode.BODY_TYPE_TAIL = 0x2;
GameLib.CustomCode.GRID_WIDTH = 11;
GameLib.CustomCode.GRID_HEIGHT = 11;
@ -37,7 +37,7 @@ this.geometryBody = GameLib.EntityManager.Instance.findComponentById('8f5q7k5ozp
/**
* Images
*/
this.imageEnd = GameLib.EntityManager.Instance.findComponentById('swkla3wpp');
this.imageBreadEnd = GameLib.EntityManager.Instance.findComponentById('swkla3wpp');
this.imageBreadPatty = GameLib.EntityManager.Instance.findComponentById('01r51k9ptr');
this.imageBreadCorner = GameLib.EntityManager.Instance.findComponentById('iljpuouaok');
this.imagePatty = GameLib.EntityManager.Instance.findComponentById('4lf0fw24su');
@ -56,8 +56,8 @@ this.speed = GameLib.CustomCode.SPEED_INITIAL;
this.advanceTime = 0;
this.state = {
direction : {
x : -1,
y : 0
x : 0,
y : 1
},
rotation : 0
};
@ -97,14 +97,15 @@ GameLib.CustomCode.prototype.createGameMesh = function(image) {
/**
* Create our objects
*/
this.meshEnd = this.createGameMesh(this.imageEnd);
this.meshEnd.useQuaternion = false;
this.meshBreadEnd = this.createGameMesh(this.imageBreadEnd);
this.meshBreadEnd.useQuaternion = false;
this.meshPatty = this.createGameMesh(this.imagePatty);
this.meshBodyPatty = this.createGameMesh(this.imageBodyPatty);
this.meshPatty = this.createGameMesh(this.imagePatty);
this.meshBreadPatty = this.createGameMesh(this.imageBreadPatty);
this.meshBreadCorner = this.createGameMesh(this.imageBreadCorner);
GameLib.CustomCode.SnakeBody = function(
bodyType,
mesh,
position,
rotation
@ -128,37 +129,13 @@ GameLib.CustomCode.SnakeBody = function(
this.position = position;
if (GameLib.Utils.UndefinedOrNull(rotation)) {
rotation = Math.PI / 2;
rotation = 0;
}
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();
};
/*
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() {
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.y = position.y;
body.rotation += this.state.rotation;
//body.rotation += this.state.rotation;
position.x = tempPosition.x;
position.y = tempPosition.y;
@ -275,20 +252,44 @@ GameLib.Event.Subscribe(
this.state = {
direction : {
x : -1,
y : 0
x : 0,
y : 1
},
rotation : Math.PI / 2
rotation : 0
};
this.snake = [
new GameLib.CustomCode.SnakeBody(
GameLib.CustomCode.BODY_TYPE_HEAD,
this.meshEnd
this.meshBreadEnd,
{
x : 4,
y : 4
},
0
),
new GameLib.CustomCode.SnakeBody(
GameLib.CustomCode.BODY_TYPE_TAIL,
this.meshEnd
this.meshBreadPatty,
{
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
)
];