2018-03-13 12:55:11 +01:00
|
|
|
if (!this.entityLoaded) {
|
2018-03-14 11:53:45 +01:00
|
|
|
return;
|
2018-03-13 12:55:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.initialized) {
|
2018-03-14 11:53:45 +01:00
|
|
|
|
|
|
|
this.state = this.entityLoaded.state;
|
|
|
|
|
|
|
|
this.initialized = true;
|
2018-03-13 12:55:11 +01:00
|
|
|
}
|
|
|
|
|
2018-03-15 13:07:28 +01:00
|
|
|
if (this.state.turning) {
|
2018-03-15 15:19:01 +01:00
|
|
|
//console.warn('already turning - todo: store the input and play back');
|
2018-03-15 15:26:30 +01:00
|
|
|
//return;
|
2018-03-15 13:07:28 +01:00
|
|
|
}
|
|
|
|
|
2018-03-13 13:09:46 +01:00
|
|
|
if (data.keyCode === GameLib.System.Input.KEY_UP) {
|
2018-03-14 11:53:45 +01:00
|
|
|
|
|
|
|
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;
|
2018-03-15 11:25:17 +01:00
|
|
|
this.state.turning = true;
|
2018-03-14 11:53:45 +01:00
|
|
|
}
|
|
|
|
|
2018-03-13 13:09:46 +01:00
|
|
|
}
|
|
|
|
|
2018-03-13 13:13:23 +01:00
|
|
|
if (data.keyCode === GameLib.System.Input.KEY_DOWN) {
|
2018-03-14 11:53:45 +01:00
|
|
|
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;
|
2018-03-15 11:25:17 +01:00
|
|
|
this.state.turning = true;
|
2018-03-14 11:53:45 +01:00
|
|
|
}
|
2018-03-13 13:13:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data.keyCode === GameLib.System.Input.KEY_LEFT) {
|
2018-03-14 11:53:45 +01:00
|
|
|
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;
|
2018-03-15 11:25:17 +01:00
|
|
|
this.state.turning = true;
|
2018-03-14 11:53:45 +01:00
|
|
|
}
|
2018-03-13 13:13:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data.keyCode === GameLib.System.Input.KEY_RIGHT) {
|
2018-03-14 11:53:45 +01:00
|
|
|
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;
|
2018-03-15 11:25:17 +01:00
|
|
|
this.state.turning = true;
|
2018-03-14 11:53:45 +01:00
|
|
|
}
|
2018-03-13 13:13:23 +01:00
|
|
|
}
|
|
|
|
|
2018-03-13 13:09:46 +01:00
|
|
|
//@ sourceURL=keyUp.js
|