113 lines
3.0 KiB
JavaScript
113 lines
3.0 KiB
JavaScript
if (!this.entityLoaded) {
|
|
return;
|
|
}
|
|
|
|
if (!this.initialized) {
|
|
|
|
this.state = this.entityLoaded.state;
|
|
|
|
this.initialized = true;
|
|
}
|
|
|
|
if (this.state.turning) {
|
|
//console.warn('already turning - todo: store the input and play back');
|
|
//return;
|
|
}
|
|
|
|
if (data.keyCode === GameLib.System.Input.KEY_UP) {
|
|
|
|
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;
|
|
this.state.turning = true;
|
|
}
|
|
|
|
}
|
|
|
|
if (data.keyCode === GameLib.System.Input.KEY_DOWN) {
|
|
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;
|
|
this.state.turning = true;
|
|
}
|
|
}
|
|
|
|
if (data.keyCode === GameLib.System.Input.KEY_LEFT) {
|
|
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
|
|
) {
|
|
|
|
if (this.state.orientation === GameLib.CustomCode.ORIENTATION_DOWN) {
|
|
this.state.flip = true;
|
|
} else {
|
|
this.state.flip = false;
|
|
}
|
|
|
|
this.state.orientation = GameLib.CustomCode.ORIENTATION_LEFT;
|
|
this.state.turning = true;
|
|
}
|
|
}
|
|
|
|
if (data.keyCode === GameLib.System.Input.KEY_RIGHT) {
|
|
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
|
|
) {
|
|
|
|
if (this.state.orientation === GameLib.CustomCode.ORIENTATION_DOWN) {
|
|
this.state.flip = true;
|
|
} else {
|
|
this.state.flip = false;
|
|
}
|
|
|
|
this.state.orientation = GameLib.CustomCode.ORIENTATION_RIGHT;
|
|
this.state.turning = true;
|
|
}
|
|
}
|
|
|
|
//@ sourceURL=keyUp.js
|