Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 1545 bytes modified
parent
af97520e3f
commit
4853591f23
|
@ -68,7 +68,8 @@ this.advanceTime = 0;
|
|||
* @type {{direction: {x: number, y: number}, orientation: number}}
|
||||
*/
|
||||
this.state = {
|
||||
orientation : 0
|
||||
orientation : 0,
|
||||
turning : false
|
||||
};
|
||||
|
||||
GameLib.CustomCode.prototype.createMaterial = function(image) {
|
||||
|
@ -125,13 +126,14 @@ this.meshPatty = this.createGameMesh(this.imagePatty);
|
|||
* @param mesh
|
||||
* @param position
|
||||
* @param orientation
|
||||
* @param bodyType
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.CustomCode.SnakeBody = function(
|
||||
mesh,
|
||||
position,
|
||||
orientation,
|
||||
bodyType
|
||||
bodyType
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(mesh)) {
|
||||
|
@ -152,12 +154,13 @@ GameLib.CustomCode.SnakeBody = function(
|
|||
}
|
||||
this.orientation = orientation;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(bodyType)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(bodyType)) {
|
||||
bodyType = GameLib.CustomCode.BODY_TYPE_NORMAL;
|
||||
}
|
||||
this.orientation = orientation;
|
||||
this.bodyType = bodyType;
|
||||
|
||||
|
||||
this.backupMesh = null;
|
||||
|
||||
this.applyToMesh();
|
||||
};
|
||||
|
||||
|
@ -209,7 +212,8 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
|||
var backup = {
|
||||
x : 0,
|
||||
y : 0,
|
||||
orientation : GameLib.CustomCode.ORIENTATION_UP
|
||||
orientation : GameLib.CustomCode.ORIENTATION_UP,
|
||||
bodyType : GameLib.CustomCode.BODY_TYPE_NORMAL
|
||||
};
|
||||
|
||||
this.snake.map(
|
||||
|
@ -219,27 +223,63 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
|||
|
||||
backup.x = body.position.x;
|
||||
backup.y = body.position.y;
|
||||
backup.orientation = body.orientation;
|
||||
|
||||
backup.orientation = body.orientation;
|
||||
backup.bodyType = body.bodyType;
|
||||
|
||||
body.advance(
|
||||
this.state.orientation
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
if (
|
||||
index === 1 &&
|
||||
this.state.turning &&
|
||||
body.bodyType !== GameLib.CustomCode.BODY_TYPE_TAIL
|
||||
) {
|
||||
|
||||
body.backupMesh = body.mesh;
|
||||
|
||||
body.mesh = this.meshBreadCorner.clone();
|
||||
|
||||
body.bodyType = GameLib.CustomCode.BODY_TYPE_CORNER;
|
||||
|
||||
this.state.turning = false;
|
||||
}
|
||||
|
||||
var temp = {
|
||||
x : body.position.x,
|
||||
y : body.position.y,
|
||||
orientation : body.orientation
|
||||
orientation : body.orientation,
|
||||
bodyType : body.bodyType
|
||||
};
|
||||
|
||||
body.position.x = backup.x;
|
||||
body.position.y = backup.y;
|
||||
body.orientation = backup.orientation;
|
||||
body.orientation = backup.orientation;
|
||||
body.bodyType = backup.bodyType;
|
||||
|
||||
backup.x = temp.x;
|
||||
backup.y = temp.y;
|
||||
backup.orientation = temp.orientation;
|
||||
backup.orientation = temp.orientation;
|
||||
backup.bodyType = temp.bodyType
|
||||
|
||||
if (
|
||||
index === (this.snake.length - 1) &&
|
||||
body.bodyType === GameLib.CustomCode.BODY_TYPE_CORNER
|
||||
) {
|
||||
// body.bodyType = GameLib.CustomCode.BODY_TYPE_TAIL;
|
||||
//
|
||||
// body.mesh.geometry = null;
|
||||
//
|
||||
// body.mesh.materials = null;
|
||||
//
|
||||
// body.mesh.remove();
|
||||
//
|
||||
// body.mesh = body.backupMesh;
|
||||
//
|
||||
// body.backupMesh = null;
|
||||
}
|
||||
}
|
||||
|
||||
body.applyToMesh();
|
||||
|
@ -319,7 +359,8 @@ GameLib.Event.Subscribe(
|
|||
x : 4,
|
||||
y : 1
|
||||
},
|
||||
0
|
||||
0,
|
||||
GameLib.CustomCode.BODY_TYPE_TAIL
|
||||
)
|
||||
];
|
||||
|
||||
|
@ -328,14 +369,14 @@ GameLib.Event.Subscribe(
|
|||
*
|
||||
this.grid.map(
|
||||
function(x) {
|
||||
x.map(
|
||||
function(y) {
|
||||
y.mesh.geometry = null;
|
||||
y.mesh.materials = null;
|
||||
y.mesh.remove();
|
||||
}
|
||||
);
|
||||
}
|
||||
x.map(
|
||||
function(y) {
|
||||
y.mesh.geometry = null;
|
||||
y.mesh.materials = null;
|
||||
y.mesh.remove();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
this.initializeGrid();
|
||||
|
|
Loading…
Reference in New Issue