From ba85f03469ddedeaee4e372e1f7636086bbeba82 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Wed, 14 Mar 2018 11:53:45 +0100 Subject: [PATCH] Update: CC - Snake FS - Key Up (306204wy29.js) 1351 bytes modified --- 306204wy29.js | 108 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 70 insertions(+), 38 deletions(-) diff --git a/306204wy29.js b/306204wy29.js index 0d93190..b5164ac 100644 --- a/306204wy29.js +++ b/306204wy29.js @@ -1,58 +1,90 @@ if (!this.entityLoaded) { - return; + return; } if (!this.initialized) { - - this.state = this.entityLoaded.state; - - this.initialized = true; + + this.state = this.entityLoaded.state; + + this.initialized = true; } if (data.keyCode === GameLib.System.Input.KEY_UP) { - if (this.state.direction.y === -1) { - return; - } - - if (this.state.direction.y === 1) { - return; - } - - if (this.state.direction.x === 1) { - this.state.direction.y = 1; - this.state.rotation += Math.PI / 2; - } - if (this.state.direction.x === -1) { - this.state.direction.y = 1; - this.state.rotation -= Math.PI / 2; - } - - this.state.direction.x = 0; + if ( + this.state.orientation === GameLib.CustomCode.ORIENTATION_UP || + this.state.orientation === GameLib.CustomCode.ORIENTATION_DOWN + ) { + /** + * The snake is moving up or down - do nothing + */ + return; + } + + if ( + this.state.orientation === GameLib.CustomCode.ORIENTATION_LEFT || + this.state.orientation === GameLib.CustomCode.ORIENTATION_RIGHT + ) { + this.state.orientation = GameLib.CustomCode.ORIENTATION_UP; + } + } if (data.keyCode === GameLib.System.Input.KEY_DOWN) { - if (this.state.direction.y === 1) { - return; - } - this.state.direction.y = -1; - this.state.direction.x = 0; + if ( + this.state.orientation === GameLib.CustomCode.ORIENTATION_UP || + this.state.orientation === GameLib.CustomCode.ORIENTATION_DOWN + ) { + /** + * The snake is moving up or down - do nothing + */ + return; + } + + if ( + this.state.orientation === GameLib.CustomCode.ORIENTATION_LEFT || + this.state.orientation === GameLib.CustomCode.ORIENTATION_RIGHT + ) { + this.state.orientation = GameLib.CustomCode.ORIENTATION_DOWN; + } } if (data.keyCode === GameLib.System.Input.KEY_LEFT) { - if (this.state.direction.x === 1) { - return; - } - this.state.direction.y = 0; - this.state.direction.x = -1; + if ( + this.state.orientation === GameLib.CustomCode.ORIENTATION_LEFT || + this.state.orientation === GameLib.CustomCode.ORIENTATION_RIGHT + ) { + /** + * The snake is moving up or down - do nothing + */ + return; + } + + if ( + this.state.orientation === GameLib.CustomCode.ORIENTATION_UP || + this.state.orientation === GameLib.CustomCode.ORIENTATION_DOWN + ) { + this.state.orientation = GameLib.CustomCode.ORIENTATION_LEFT; + } } if (data.keyCode === GameLib.System.Input.KEY_RIGHT) { - if (this.state.direction.x === -1) { - return; - } - this.state.direction.y = 0; - this.state.direction.x = 1; + if ( + this.state.orientation === GameLib.CustomCode.ORIENTATION_LEFT || + this.state.orientation === GameLib.CustomCode.ORIENTATION_RIGHT + ) { + /** + * The snake is moving up or down - do nothing + */ + return; + } + + if ( + this.state.orientation === GameLib.CustomCode.ORIENTATION_UP || + this.state.orientation === GameLib.CustomCode.ORIENTATION_DOWN + ) { + this.state.orientation = GameLib.CustomCode.ORIENTATION_RIGHT; + } }