Change direction keys processing
This commit is contained in:
parent
6d0bd30bbe
commit
873e458a66
@ -1,6 +1,7 @@
|
|||||||
package com.annimon.influencexxii;
|
package com.annimon.influencexxii;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Input.Keys;
|
||||||
import com.badlogic.gdx.Input.Peripheral;
|
import com.badlogic.gdx.Input.Peripheral;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
|
|
||||||
@ -39,12 +40,6 @@ public class Pointer {
|
|||||||
screenHeight = height;
|
screenHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(int horizontal, int vertical) {
|
|
||||||
x += horizontal * screenWidth / 50f;
|
|
||||||
y += vertical * screenHeight / 50f;
|
|
||||||
validatePosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fire() {
|
public void fire() {
|
||||||
if (mode == READY) {
|
if (mode == READY) {
|
||||||
enemies.killEnemy(x, y);
|
enemies.killEnemy(x, y);
|
||||||
@ -58,9 +53,24 @@ public class Pointer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void control() {
|
private void control() {
|
||||||
|
controlByKeyboard();
|
||||||
if (isAccelerometerSupports) {
|
if (isAccelerometerSupports) {
|
||||||
controlByAccelerometer();
|
controlByAccelerometer();
|
||||||
}
|
}
|
||||||
|
validatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void controlByKeyboard() {
|
||||||
|
int horizontal = 0;
|
||||||
|
if (Gdx.input.isKeyPressed(Keys.DPAD_LEFT)) horizontal--;
|
||||||
|
else if (Gdx.input.isKeyPressed(Keys.DPAD_RIGHT)) horizontal++;
|
||||||
|
|
||||||
|
int vertical = 0;
|
||||||
|
if (Gdx.input.isKeyPressed(Keys.DPAD_DOWN)) vertical--;
|
||||||
|
else if (Gdx.input.isKeyPressed(Keys.DPAD_UP)) vertical++;
|
||||||
|
|
||||||
|
x += horizontal * screenWidth / 100f;
|
||||||
|
y += vertical * screenHeight / 100f;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void controlByAccelerometer() {
|
private void controlByAccelerometer() {
|
||||||
@ -76,7 +86,6 @@ public class Pointer {
|
|||||||
|
|
||||||
x += ax * screenWidth / 500f;
|
x += ax * screenWidth / 500f;
|
||||||
y += ay * screenHeight / 500f;
|
y += ay * screenHeight / 500f;
|
||||||
validatePosition();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validatePosition() {
|
private void validatePosition() {
|
||||||
|
Loading…
Reference in New Issue
Block a user