DEADSOFTWARE

Change desktop controls
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / GameInputHandler.java
index 1273c05a7c6ebb97b0e3a17d6402b7a6ca7d788f..899fbba6f06578dd4ca66ec47162e596cdc3a231 100644 (file)
@@ -11,9 +11,28 @@ public class GameInputHandler {
         this.gameProc = gameProc;
     }
 
+    public void  keyDown(int keyCode) {
+        if (keyCode == Input.Keys.A) {
+            gameProc.player.moveX.add(-GamePhysics.PL_SPEED,0);
+            gameProc.player.dir = 0;
+        }
+        if (keyCode == Input.Keys.D) {
+            gameProc.player.moveX.add(GamePhysics.PL_SPEED,0);
+            gameProc.player.dir = 1;
+        }
+        if (keyCode == Input.Keys.SPACE &&
+                gameProc.player.canJump) gameProc.player.moveY.add(0,-8);
+    }
+
+    public void keyUp(int keyCode) {
+        if (keyCode == Input.Keys.A || keyCode == Input.Keys.D) {
+            gameProc.player.moveX.x = 0;
+        }
+    }
+
     public void mouseMoved(int screenX, int screenY) {
-        gameProc.cursorX = (int)((screenX+gameProc.renderer.camera.position.x)/32);
-        gameProc.cursorY = (int)((screenY+gameProc.renderer.camera.position.y)/32);
+        gameProc.cursorX = (int)((screenX+gameProc.renderer.camera.position.x)/16);
+        gameProc.cursorY = (int)((screenY+gameProc.renderer.camera.position.y)/16);
         if (gameProc.cursorX < 0)
             gameProc.cursorX = 0;
         if (gameProc.cursorX >= gameProc.world.getWidth())
@@ -26,21 +45,24 @@ public class GameInputHandler {
     }
 
     public void touchDown(int screenX, int screenY, int button) {
-        if (button == Input.Buttons.LEFT) {
-            if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY) > 0) {
-                gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 0);
-            } else if (gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY) > 0) {
-                gameProc.world.placeToBackground(gameProc.cursorX, gameProc.cursorY, 0);
-            }
-        } else {
-            gameProc.touchDownTime = TimeUtils.millis();
-            gameProc.isTouchDown = true;
-        }
+        gameProc.touchDownX = screenX;
+        gameProc.touchDownY = screenY;
+        gameProc.touchDownTime = TimeUtils.millis();
+        gameProc.isTouchDown = true;
     }
 
     public void touchUp(int screenX, int screenY, int button) {
-        if (gameProc.isTouchDown && button == Input.Buttons.RIGHT){
-                gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 1);
+        if (gameProc.isTouchDown) {
+            if (button == Input.Buttons.RIGHT){
+                gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY,
+                        gameProc.player.inventory[gameProc.invSlot]);
+            } else if (button == Input.Buttons.LEFT) {
+                if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY) > 0) {
+                    gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 0);
+                } else if (gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY) > 0) {
+                    gameProc.world.placeToBackground(gameProc.cursorX, gameProc.cursorY, 0);
+                }
+            }
         }
         gameProc.isTouchDown = false;
     }
@@ -48,4 +70,10 @@ public class GameInputHandler {
     public void touchDragged(int screenX, int screenY) {
     }
 
+    public void scrolled(int amount) {
+        gameProc.invSlot += amount;
+        if (gameProc.invSlot < 0) gameProc.invSlot = 8;
+        if (gameProc.invSlot > 8) gameProc.invSlot = 0;
+    }
+
 }