Update: CC - Snake FS - Key Up (306204wy29.js) 104 bytes modified

beta.r3js.org
-=yb4f310 2018-03-13 13:50:39 +01:00
parent e596b1a02a
commit f70ecbd2db
1 changed files with 21 additions and 19 deletions

View File

@ -3,54 +3,56 @@ if (!this.entityLoaded) {
}
if (!this.initialized) {
this.direction = this.entityLoaded.direction;
this.state = this.entityLoaded.state;
this.initialized = true;
}
if (data.keyCode === GameLib.System.Input.KEY_UP) {
if (this.direction.y === -1) {
if (this.state.direction.y === -1) {
return;
}
if (this.direction.y === 1) {
if (this.state.direction.y === 1) {
return;
}
if (this.direction.x === 1) {
this.direction.y = 1;
this.rotation += Math.PI / 2;
if (this.state.direction.x === 1) {
this.state.direction.y = 1;
this.state.rotation += Math.PI / 2;
}
if (this.direction.x === -1) {
this.direction.y = 1;
this.rotation -= Math.PI / 2;
if (this.state.direction.x === -1) {
this.state.direction.y = 1;
this.state.rotation -= Math.PI / 2;
}
this.direction.x = 0;
this.state.direction.x = 0;
}
if (data.keyCode === GameLib.System.Input.KEY_DOWN) {
if (this.direction.y === 1) {
if (this.state.direction.y === 1) {
return;
}
this.direction.y = -1;
this.direction.x = 0;
this.state.direction.y = -1;
this.state.direction.x = 0;
}
if (data.keyCode === GameLib.System.Input.KEY_LEFT) {
if (this.direction.x === 1) {
if (this.state.direction.x === 1) {
return;
}
this.direction.y = 0;
this.direction.x = -1;
this.state.direction.y = 0;
this.state.direction.x = -1;
}
if (data.keyCode === GameLib.System.Input.KEY_RIGHT) {
if (this.direction.x === -1) {
if (this.state.direction.x === -1) {
return;
}
this.direction.y = 0;
this.direction.x = 1;
this.state.direction.y = 0;
this.state.direction.x = 1;
}