r3-custom-code/306204wy29.js

125 lines
3.3 KiB
JavaScript
Raw Normal View History

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
) {
if (this.state.orientation === GameLib.CustomCode.ORIENTATION_RIGHT) {
this.state.flip = -4;
} 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