Change direction keys processing

This commit is contained in:
Victor 2014-01-15 12:42:33 +02:00
parent 6d0bd30bbe
commit 873e458a66

View File

@ -1,6 +1,7 @@
package com.annimon.influencexxii;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Input.Peripheral;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
@ -39,12 +40,6 @@ public class Pointer {
screenHeight = height;
}
public void update(int horizontal, int vertical) {
x += horizontal * screenWidth / 50f;
y += vertical * screenHeight / 50f;
validatePosition();
}
public void fire() {
if (mode == READY) {
enemies.killEnemy(x, y);
@ -58,9 +53,24 @@ public class Pointer {
}
private void control() {
controlByKeyboard();
if (isAccelerometerSupports) {
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() {
@ -76,7 +86,6 @@ public class Pointer {
x += ax * screenWidth / 500f;
y += ay * screenHeight / 500f;
validatePosition();
}
private void validatePosition() {