From 600bc4b2cc52a0651a9701850087cf4d6f9a62e0 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 12 Mar 2018 20:54:46 +0100 Subject: [PATCH] Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 7 bytes modified --- 21g30t1e75.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/21g30t1e75.js b/21g30t1e75.js index c7123b6..c3c9375 100644 --- a/21g30t1e75.js +++ b/21g30t1e75.js @@ -94,9 +94,9 @@ this.meshBodyPatty = this.createGameMesh(this.imageBodyPatty); GameLib.CustomCode.SnakeBody = function( bodyType, + mesh, position, - direction, - mesh + direction ) { if (GameLib.Utils.UndefinedOrNull(position)) { position = { @@ -115,35 +115,36 @@ GameLib.CustomCode.SnakeBody = function( this.direction = direction; if (GameLib.Utils.UndefinedOrNull(bodyType)) { - bodyType = GameLib.CustomCode.BODY_TYPE_HEAD; + throw new Error('no body type specified'); } this.bodyType = bodyType; if (GameLib.Utils.UndefinedOrNull(mesh)) { - - switch (this.bodyType) { - case GameLib.CustomCode.BODY_TYPE_HEAD : - mesh = this.meshEnd; - break; - case GameLib.CustomCode.BODY_TYPE_TAIL : - mesh = this.meshEnd.clone(); - mesh.rotation.z = Math.PI; - mesh.updateInstance('rotation'); - position.x += 1; - default : - throw new Error('body type not specified and no mesh'); - break; - } - + throw new Error('no mesh specified'); } this.mesh = mesh; + switch (this.bodyType) { + case GameLib.CustomCode.BODY_TYPE_HEAD : + mesh = this.meshEnd; + break; + case GameLib.CustomCode.BODY_TYPE_TAIL : + mesh = this.meshEnd.clone(); + mesh.rotation.z = Math.PI; + mesh.updateInstance('rotation'); + position.x += 1; + default : + throw new Error('unreachable statement'); + break; + } + this.applyPositionToMesh(); }; GameLib.CustomCode.SnakeBody.prototype.clone = function() { return new GameLib.CustomCode.SnakeBody( this.bodyType, + this.mesh, { x : this.position.x, y : this.position.y @@ -151,8 +152,7 @@ GameLib.CustomCode.SnakeBody.prototype.clone = function() { { x : this.direction.x, y : this.direction.y - }, - this.mesh + } ); }