diff --git a/src/com/annimon/influencexxii/Pointer.java b/src/com/annimon/influencexxii/Pointer.java index ce62a6c..80e4fcd 100644 --- a/src/com/annimon/influencexxii/Pointer.java +++ b/src/com/annimon/influencexxii/Pointer.java @@ -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() {