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; + } }