r3-custom-code/306204wy29.js

132 lines
3.2 KiB
JavaScript

if (!this.entityLoaded) {
return;
}
if (!this.initialized) {
this.state = this.entityLoaded.state;
this.initialized = true;
}
R3.Event.Emit(
R3.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 === R3.System.Input.KEY_UP) {
if (
this.state.orientation === R3.CustomCode.ORIENTATION_UP ||
this.state.orientation === R3.CustomCode.ORIENTATION_DOWN
) {
/**
* The snake is moving up or down - do nothing
*/
return;
}
if (
this.state.orientation === R3.CustomCode.ORIENTATION_LEFT ||
this.state.orientation === R3.CustomCode.ORIENTATION_RIGHT
) {
if (this.state.orientation === R3.CustomCode.ORIENTATION_RIGHT) {
this.state.flip = 0;
} else {
this.state.flip = -1;
}
this.state.orientation = R3.CustomCode.ORIENTATION_UP;
this.state.turning = true;
}
}
if (data.keyCode === R3.System.Input.KEY_DOWN) {
if (
this.state.orientation === R3.CustomCode.ORIENTATION_UP ||
this.state.orientation === R3.CustomCode.ORIENTATION_DOWN
) {
/**
* The snake is moving up or down - do nothing
*/
return;
}
if (
this.state.orientation === R3.CustomCode.ORIENTATION_LEFT ||
this.state.orientation === R3.CustomCode.ORIENTATION_RIGHT
) {
if (this.state.orientation === R3.CustomCode.ORIENTATION_RIGHT) {
this.state.flip = -1;
} else {
this.state.flip = 0;
}
this.state.orientation = R3.CustomCode.ORIENTATION_DOWN;
this.state.turning = true;
}
}
if (data.keyCode === R3.System.Input.KEY_LEFT) {
if (
this.state.orientation === R3.CustomCode.ORIENTATION_LEFT ||
this.state.orientation === R3.CustomCode.ORIENTATION_RIGHT
) {
/**
* The snake is moving up or down - do nothing
*/
return;
}
if (
this.state.orientation === R3.CustomCode.ORIENTATION_UP ||
this.state.orientation === R3.CustomCode.ORIENTATION_DOWN
) {
if (this.state.orientation === R3.CustomCode.ORIENTATION_DOWN) {
this.state.flip = -1;
} else {
this.state.flip = 0;
}
this.state.orientation = R3.CustomCode.ORIENTATION_LEFT;
this.state.turning = true;
}
}
if (data.keyCode === R3.System.Input.KEY_RIGHT) {
if (
this.state.orientation === R3.CustomCode.ORIENTATION_LEFT ||
this.state.orientation === R3.CustomCode.ORIENTATION_RIGHT
) {
/**
* The snake is moving up or down - do nothing
*/
return;
}
if (
this.state.orientation === R3.CustomCode.ORIENTATION_UP ||
this.state.orientation === R3.CustomCode.ORIENTATION_DOWN
) {
if (this.state.orientation === R3.CustomCode.ORIENTATION_UP) {
this.state.flip = -1;
} else {
this.state.flip = 0;
}
this.state.orientation = R3.CustomCode.ORIENTATION_RIGHT;
this.state.turning = true;
}
}
//@ sourceURL=keyUp.js