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}}
|
* @type {{direction: {x: number, y: number}, orientation: number}}
|
||||||
*/
|
*/
|
||||||
this.state = {
|
this.state = {
|
||||||
orientation : 0
|
orientation : 0,
|
||||||
|
turning : false
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.createMaterial = function(image) {
|
GameLib.CustomCode.prototype.createMaterial = function(image) {
|
||||||
|
@ -125,13 +126,14 @@ this.meshPatty = this.createGameMesh(this.imagePatty);
|
||||||
* @param mesh
|
* @param mesh
|
||||||
* @param position
|
* @param position
|
||||||
* @param orientation
|
* @param orientation
|
||||||
|
* @param bodyType
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.CustomCode.SnakeBody = function(
|
GameLib.CustomCode.SnakeBody = function(
|
||||||
mesh,
|
mesh,
|
||||||
position,
|
position,
|
||||||
orientation,
|
orientation,
|
||||||
bodyType
|
bodyType
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(mesh)) {
|
if (GameLib.Utils.UndefinedOrNull(mesh)) {
|
||||||
|
@ -152,12 +154,13 @@ GameLib.CustomCode.SnakeBody = function(
|
||||||
}
|
}
|
||||||
this.orientation = orientation;
|
this.orientation = orientation;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(bodyType)) {
|
if (GameLib.Utils.UndefinedOrNull(bodyType)) {
|
||||||
bodyType = GameLib.CustomCode.BODY_TYPE_NORMAL;
|
bodyType = GameLib.CustomCode.BODY_TYPE_NORMAL;
|
||||||
}
|
}
|
||||||
this.orientation = orientation;
|
this.bodyType = bodyType;
|
||||||
|
|
||||||
|
this.backupMesh = null;
|
||||||
|
|
||||||
this.applyToMesh();
|
this.applyToMesh();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -209,7 +212,8 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
var backup = {
|
var backup = {
|
||||||
x : 0,
|
x : 0,
|
||||||
y : 0,
|
y : 0,
|
||||||
orientation : GameLib.CustomCode.ORIENTATION_UP
|
orientation : GameLib.CustomCode.ORIENTATION_UP,
|
||||||
|
bodyType : GameLib.CustomCode.BODY_TYPE_NORMAL
|
||||||
};
|
};
|
||||||
|
|
||||||
this.snake.map(
|
this.snake.map(
|
||||||
|
@ -219,27 +223,63 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
|
|
||||||
backup.x = body.position.x;
|
backup.x = body.position.x;
|
||||||
backup.y = body.position.y;
|
backup.y = body.position.y;
|
||||||
backup.orientation = body.orientation;
|
backup.orientation = body.orientation;
|
||||||
|
backup.bodyType = body.bodyType;
|
||||||
|
|
||||||
body.advance(
|
body.advance(
|
||||||
this.state.orientation
|
this.state.orientation
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} 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 = {
|
var temp = {
|
||||||
x : body.position.x,
|
x : body.position.x,
|
||||||
y : body.position.y,
|
y : body.position.y,
|
||||||
orientation : body.orientation
|
orientation : body.orientation,
|
||||||
|
bodyType : body.bodyType
|
||||||
};
|
};
|
||||||
|
|
||||||
body.position.x = backup.x;
|
body.position.x = backup.x;
|
||||||
body.position.y = backup.y;
|
body.position.y = backup.y;
|
||||||
body.orientation = backup.orientation;
|
body.orientation = backup.orientation;
|
||||||
|
body.bodyType = backup.bodyType;
|
||||||
|
|
||||||
backup.x = temp.x;
|
backup.x = temp.x;
|
||||||
backup.y = temp.y;
|
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();
|
body.applyToMesh();
|
||||||
|
@ -319,7 +359,8 @@ GameLib.Event.Subscribe(
|
||||||
x : 4,
|
x : 4,
|
||||||
y : 1
|
y : 1
|
||||||
},
|
},
|
||||||
0
|
0,
|
||||||
|
GameLib.CustomCode.BODY_TYPE_TAIL
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -328,14 +369,14 @@ GameLib.Event.Subscribe(
|
||||||
*
|
*
|
||||||
this.grid.map(
|
this.grid.map(
|
||||||
function(x) {
|
function(x) {
|
||||||
x.map(
|
x.map(
|
||||||
function(y) {
|
function(y) {
|
||||||
y.mesh.geometry = null;
|
y.mesh.geometry = null;
|
||||||
y.mesh.materials = null;
|
y.mesh.materials = null;
|
||||||
y.mesh.remove();
|
y.mesh.remove();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.initializeGrid();
|
this.initializeGrid();
|
||||||
|
|
Loading…
Reference in New Issue