132 lines
3.4 KiB
JavaScript
132 lines
3.4 KiB
JavaScript
if (!this.entityLoaded) {
|
|
return;
|
|
}
|
|
|
|
if (!this.initialized) {
|
|
|
|
this.state = this.entityLoaded.state;
|
|
|
|
this.initialized = true;
|
|
}
|
|
|
|
GameLib.Event.Emit(
|
|
GameLib.Event.PLAY_AUDIO,
|
|
{
|
|
name : 'Audio - Click'
|
|
}
|
|
);
|
|
|
|
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
|
|
) {
|
|
if (this.state.orientation === GameLib.CustomCode.ORIENTATION_RIGHT) {
|
|
this.state.flip = 0;
|
|
} else {
|
|
this.state.flip = -1;
|
|
}
|
|
|
|
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
|
|
) {
|
|
if (this.state.orientation === GameLib.CustomCode.ORIENTATION_RIGHT) {
|
|
this.state.flip = -1;
|
|
} else {
|
|
this.state.flip = 0;
|
|
}
|
|
|
|
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 = -1;
|
|
} else {
|
|
this.state.flip = 0;
|
|
}
|
|
|
|
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_UP) {
|
|
this.state.flip = -1;
|
|
} else {
|
|
this.state.flip = 0;
|
|
}
|
|
|
|
this.state.orientation = GameLib.CustomCode.ORIENTATION_RIGHT;
|
|
this.state.turning = true;
|
|
}
|
|
}
|
|
|
|
//@ sourceURL=keyUp.js
|