2018-03-13 12:55:11 +01:00
|
|
|
if (!this.entityLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.initialized) {
|
2018-03-13 13:50:39 +01:00
|
|
|
|
|
|
|
this.state = this.entityLoaded.state;
|
|
|
|
|
2018-03-13 12:55:11 +01:00
|
|
|
this.initialized = true;
|
|
|
|
}
|
|
|
|
|
2018-03-13 13:09:46 +01:00
|
|
|
if (data.keyCode === GameLib.System.Input.KEY_UP) {
|
2018-03-13 13:50:39 +01:00
|
|
|
if (this.state.direction.y === -1) {
|
2018-03-13 13:21:18 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-03-13 13:48:57 +01:00
|
|
|
|
2018-03-13 13:50:39 +01:00
|
|
|
if (this.state.direction.y === 1) {
|
2018-03-13 13:48:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-13 13:50:39 +01:00
|
|
|
if (this.state.direction.x === 1) {
|
|
|
|
this.state.direction.y = 1;
|
|
|
|
this.state.rotation += Math.PI / 2;
|
2018-03-13 13:48:57 +01:00
|
|
|
}
|
|
|
|
|
2018-03-13 13:50:39 +01:00
|
|
|
if (this.state.direction.x === -1) {
|
|
|
|
this.state.direction.y = 1;
|
|
|
|
this.state.rotation -= Math.PI / 2;
|
2018-03-13 13:48:57 +01:00
|
|
|
}
|
|
|
|
|
2018-03-13 13:50:39 +01:00
|
|
|
this.state.direction.x = 0;
|
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-13 13:50:39 +01:00
|
|
|
if (this.state.direction.y === 1) {
|
2018-03-13 13:21:18 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-03-13 13:50:39 +01:00
|
|
|
this.state.direction.y = -1;
|
|
|
|
this.state.direction.x = 0;
|
2018-03-13 13:13:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data.keyCode === GameLib.System.Input.KEY_LEFT) {
|
2018-03-13 13:50:39 +01:00
|
|
|
if (this.state.direction.x === 1) {
|
2018-03-13 13:21:18 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-03-13 13:50:39 +01:00
|
|
|
this.state.direction.y = 0;
|
|
|
|
this.state.direction.x = -1;
|
2018-03-13 13:13:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data.keyCode === GameLib.System.Input.KEY_RIGHT) {
|
2018-03-13 13:50:39 +01:00
|
|
|
if (this.state.direction.x === -1) {
|
2018-03-13 13:21:18 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-03-13 13:50:39 +01:00
|
|
|
this.state.direction.y = 0;
|
|
|
|
this.state.direction.x = 1;
|
2018-03-13 13:13:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-13 12:55:11 +01:00
|
|
|
console.log(data);
|
|
|
|
|
2018-03-13 13:09:46 +01:00
|
|
|
//@ sourceURL=keyUp.js
|