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-19 10:11:03 +01:00
|
|
|
console.warn('already turning - todo: store the input and play back');
|
|
|
|
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
|
|
|
|
) {
|
2018-03-19 08:42:04 +01:00
|
|
|
if (this.state.orientation === GameLib.CustomCode.ORIENTATION_RIGHT) {
|
2018-03-19 11:17:04 +01:00
|
|
|
this.state.flip = 0;
|
2018-03-19 09:28:34 +01:00
|
|
|
} else {
|
2018-03-19 09:36:38 +01:00
|
|
|
this.state.flip = -1;
|
2018-03-19 08:42:04 +01:00
|
|
|
}
|
|
|
|
|
2018-03-14 11:53:45 +01:00
|
|
|
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
|
|
|
|
) {
|
2018-03-19 08:40:36 +01:00
|
|
|
if (this.state.orientation === GameLib.CustomCode.ORIENTATION_RIGHT) {
|
2018-03-19 09:41:23 +01:00
|
|
|
this.state.flip = -1;
|
2018-03-19 08:40:36 +01:00
|
|
|
} else {
|
2018-03-19 09:36:38 +01:00
|
|
|
this.state.flip = 0;
|
2018-03-19 08:40:36 +01:00
|
|
|
}
|
|
|
|
|
2018-03-14 11:53:45 +01:00
|
|
|
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
|
|
|
|
) {
|
2018-03-19 08:38:06 +01:00
|
|
|
|
2018-03-19 08:30:00 +01:00
|
|
|
if (this.state.orientation === GameLib.CustomCode.ORIENTATION_DOWN) {
|
2018-03-19 09:40:27 +01:00
|
|
|
this.state.flip = -1;
|
2018-03-19 08:30:00 +01:00
|
|
|
} else {
|
2018-03-19 09:36:38 +01:00
|
|
|
this.state.flip = 0;
|
2018-03-19 08:30:00 +01:00
|
|
|
}
|
|
|
|
|
2018-03-14 11:53:45 +01:00
|
|
|
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
|
|
|
|
) {
|
2018-03-19 08:38:06 +01:00
|
|
|
|
2018-03-19 08:39:34 +01:00
|
|
|
if (this.state.orientation === GameLib.CustomCode.ORIENTATION_UP) {
|
2018-03-19 11:22:12 +01:00
|
|
|
this.state.flip = -1;
|
2018-03-19 08:38:06 +01:00
|
|
|
} else {
|
2018-03-19 09:36:38 +01:00
|
|
|
this.state.flip = 0;
|
2018-03-19 08:38:06 +01:00
|
|
|
}
|
|
|
|
|
2018-03-14 11:53:45 +01:00
|
|
|
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
|