Update: CC - Snake FS - Key Up (306204wy29.js) 1351 bytes modified
parent
2b325df5d1
commit
ba85f03469
|
@ -10,49 +10,81 @@ if (!this.initialized) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.keyCode === GameLib.System.Input.KEY_UP) {
|
if (data.keyCode === GameLib.System.Input.KEY_UP) {
|
||||||
if (this.state.direction.y === -1) {
|
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state.direction.y === 1) {
|
if (
|
||||||
return;
|
this.state.orientation === GameLib.CustomCode.ORIENTATION_LEFT ||
|
||||||
|
this.state.orientation === GameLib.CustomCode.ORIENTATION_RIGHT
|
||||||
|
) {
|
||||||
|
this.state.orientation = GameLib.CustomCode.ORIENTATION_UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (data.keyCode === GameLib.System.Input.KEY_DOWN) {
|
if (data.keyCode === GameLib.System.Input.KEY_DOWN) {
|
||||||
if (this.state.direction.y === 1) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
this.state.direction.y = -1;
|
|
||||||
this.state.direction.x = 0;
|
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 (data.keyCode === GameLib.System.Input.KEY_LEFT) {
|
||||||
if (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;
|
return;
|
||||||
}
|
}
|
||||||
this.state.direction.y = 0;
|
|
||||||
this.state.direction.x = -1;
|
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 (data.keyCode === GameLib.System.Input.KEY_RIGHT) {
|
||||||
if (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;
|
return;
|
||||||
}
|
}
|
||||||
this.state.direction.y = 0;
|
|
||||||
this.state.direction.x = 1;
|
if (
|
||||||
|
this.state.orientation === GameLib.CustomCode.ORIENTATION_UP ||
|
||||||
|
this.state.orientation === GameLib.CustomCode.ORIENTATION_DOWN
|
||||||
|
) {
|
||||||
|
this.state.orientation = GameLib.CustomCode.ORIENTATION_RIGHT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue