Update: CC - Snake FS - Key Up (306204wy29.js) 1351 bytes modified

beta.r3js.org
-=yb4f310 2018-03-14 11:53:45 +01:00
parent 2b325df5d1
commit ba85f03469
1 changed files with 70 additions and 38 deletions

View File

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