Update: CC - Snake FS - Key Up (306204wy29.js) 1351 bytes modified
parent
2b325df5d1
commit
ba85f03469
100
306204wy29.js
100
306204wy29.js
|
@ -1,58 +1,90 @@
|
|||
if (!this.entityLoaded) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.initialized) {
|
||||
|
||||
this.state = this.entityLoaded.state;
|
||||
this.state = this.entityLoaded.state;
|
||||
|
||||
this.initialized = true;
|
||||
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.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.direction.x === 1) {
|
||||
this.state.direction.y = 1;
|
||||
this.state.rotation += Math.PI / 2;
|
||||
}
|
||||
if (
|
||||
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;
|
||||
}
|
||||
|
||||
this.state.direction.x = 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue