From eae9a7f6d2c2e4e64591538111aad999d273a7ed Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Tue, 13 Mar 2018 13:33:59 +0100 Subject: [PATCH] Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 136 bytes modified --- 21g30t1e75.js | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/21g30t1e75.js b/21g30t1e75.js index 3fd65a9..5734df3 100644 --- a/21g30t1e75.js +++ b/21g30t1e75.js @@ -104,16 +104,9 @@ this.meshBodyPatty = this.createGameMesh(this.imageBodyPatty); GameLib.CustomCode.SnakeBody = function( bodyType, mesh, - position -) { - if (GameLib.Utils.UndefinedOrNull(position)) { - position = { - x : Math.round(GameLib.CustomCode.GRID_WIDTH / 2), - y : Math.round(GameLib.CustomCode.GRID_HEIGHT / 2) - }; - } - this.position = position; - + position, + rotation +) { if (GameLib.Utils.UndefinedOrNull(bodyType)) { throw new Error('no body type specified'); } @@ -124,20 +117,32 @@ GameLib.CustomCode.SnakeBody = function( } this.mesh = mesh.clone(); + if (GameLib.Utils.UndefinedOrNull(position)) { + position = { + x : Math.round(GameLib.CustomCode.GRID_WIDTH / 2), + y : Math.round(GameLib.CustomCode.GRID_HEIGHT / 2) + }; + } + this.position = position; + + if (GameLib.Utils.UndefinedOrNull(rotation)) { + rotation = 0; + } + this.rotation = rotation; + switch (this.bodyType) { case GameLib.CustomCode.BODY_TYPE_HEAD : break; case GameLib.CustomCode.BODY_TYPE_TAIL : - this.mesh.rotation.z += Math.PI; - this.mesh.updateInstance('rotation'); + this.rotation += Math.PI; this.position.x += 1; break; default : throw new Error('unreachable statement'); break; } - - this.applyPositionToMesh(); + + this.applyToMesh(); }; GameLib.CustomCode.SnakeBody.prototype.clone = function() { @@ -152,13 +157,17 @@ GameLib.CustomCode.SnakeBody.prototype.clone = function() { } GameLib.CustomCode.SnakeBody.prototype.applyPositionToMesh = function() { + this.mesh.position.x = this.position.x + GameLib.CustomCode.GRID_OFFSET_X; this.mesh.position.y = this.position.y + GameLib.CustomCode.GRID_OFFSET_Y; + this.mesh.rotation.z = this.rotation; + /** * TODO: We don't update instance position - animation should do this */ this.mesh.updateInstance('position'); + this.mesh.updateInstance('rotation'); } GameLib.CustomCode.SnakeBody.prototype.advance = function(direction) {