diff --git a/21g30t1e75.js b/21g30t1e75.js index 3a8ad83..1b206bd 100644 --- a/21g30t1e75.js +++ b/21g30t1e75.js @@ -885,6 +885,44 @@ GameLib.CustomCode.prototype.powerup = function(gameObject) { }.bind(this); +GameLib.CustomCode.prototype.createCorner = function(body, temp) { + + body.orientation = temp.orientation; + + body.applyToMesh(); + + body.orientation = backup.orientation; + + body.backupMesh = body.mesh; + + if (temp.orientation === GameLib.CustomCode.ORIENTATION_UP) { + body.backupMesh.position.y -= 0.5 * GameLib.CustomCode.BODY_SCALE_Y; + } + + if (temp.orientation === GameLib.CustomCode.ORIENTATION_DOWN) { + body.backupMesh.position.y += 0.5 * GameLib.CustomCode.BODY_SCALE_Y; + } + + if (temp.orientation === GameLib.CustomCode.ORIENTATION_LEFT) { + body.backupMesh.position.x += 0.5 * GameLib.CustomCode.BODY_SCALE_X; + } + + if (temp.orientation === GameLib.CustomCode.ORIENTATION_RIGHT) { + body.backupMesh.position.x -= 0.5 * GameLib.CustomCode.BODY_SCALE_X; + } + + body.mesh = this.createGameMesh(this.materialBreadCorner); + + body.mesh.position.z = 5; + + body.mesh.updateInstance('position'); + + body.mesh.visible = true; + + body.mesh.updateInstance('visible'); + +}.bind(this); + /** * Move the snake forward and do collision detection * @type {function(this:snakeEntityLoaded)} @@ -939,6 +977,11 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) { break; case GameLib.CustomCode.OBJECT_TYPE_FOOD : this.extend(gameObject, backup.position, backup.orientation); + + if (backup.orientation !== body.orientation) { + + } + break; case GameLib.CustomCode.OBJECT_TYPE_POWERUP: this.powerup(gameObject); @@ -955,11 +998,7 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) { } else { - if (this.state.eating === true) { - return; - } - - temp = { + temp = { position : { x : body.position.x, y : body.position.y @@ -967,8 +1006,17 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) { orientation : body.orientation, flip : body.flip } - + if (this.state.eating === true) { + + if ((body.orientation !== temp.orientation) && + (index === 1)) { + this.createCorner(body, temp); + } + + return; + } + /** * Create a new empty object at the current grid position (free it up) */ @@ -1009,44 +1057,10 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) { body.mesh.updateInstance('position'); } - if (body.orientation !== temp.orientation) { - - body.orientation = temp.orientation; - - body.applyToMesh(); - - body.orientation = backup.orientation; - - body.backupMesh = body.mesh; - - if (temp.orientation === GameLib.CustomCode.ORIENTATION_UP) { - body.backupMesh.position.y -= 0.5 * GameLib.CustomCode.BODY_SCALE_Y; - } - - if (temp.orientation === GameLib.CustomCode.ORIENTATION_DOWN) { - body.backupMesh.position.y += 0.5 * GameLib.CustomCode.BODY_SCALE_Y; - } - - if (temp.orientation === GameLib.CustomCode.ORIENTATION_LEFT) { - body.backupMesh.position.x += 0.5 * GameLib.CustomCode.BODY_SCALE_X; - } - - if (temp.orientation === GameLib.CustomCode.ORIENTATION_RIGHT) { - body.backupMesh.position.x -= 0.5 * GameLib.CustomCode.BODY_SCALE_X; - } - - - body.mesh = this.createGameMesh(this.materialBreadCorner); - - body.mesh.position.z = 5; - - body.mesh.updateInstance('position'); - - body.mesh.visible = true; - - body.mesh.updateInstance('visible'); - } - + if (body.orientation !== temp.orientation) { + this.createCorner(body, temp); + } + backup = temp; }