DEADSOFTWARE

Add inventory bar
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / GameInputHandler.java
1 package ru.deadsoftware.cavecraft.game;
3 import com.badlogic.gdx.Input;
4 import com.badlogic.gdx.utils.TimeUtils;
6 public class GameInputHandler {
8 private GameProc gameProc;
10 public GameInputHandler(GameProc gameProc) {
11 this.gameProc = gameProc;
12 }
14 public void keyDown(int keyCode) {
15 if (keyCode == Input.Keys.LEFT) {
16 gameProc.player.moveX.add(-GamePhysics.PL_SPEED,0);
17 gameProc.player.dir = 0;
18 }
19 if (keyCode == Input.Keys.RIGHT) {
20 gameProc.player.moveX.add(GamePhysics.PL_SPEED,0);
21 gameProc.player.dir = 1;
22 }
23 if (keyCode == Input.Keys.UP &&
24 gameProc.player.canJump) gameProc.player.moveY.add(0,-8);
25 }
27 public void keyUp(int keyCode) {
28 if (keyCode == Input.Keys.RIGHT || keyCode == Input.Keys.LEFT) {
29 gameProc.player.moveX.x = 0;
30 }
31 }
33 public void mouseMoved(int screenX, int screenY) {
34 gameProc.cursorX = (int)((screenX+gameProc.renderer.camera.position.x)/16);
35 gameProc.cursorY = (int)((screenY+gameProc.renderer.camera.position.y)/16);
36 if (gameProc.cursorX < 0)
37 gameProc.cursorX = 0;
38 if (gameProc.cursorX >= gameProc.world.getWidth())
39 gameProc.cursorX = gameProc.world.getWidth()-1;
40 if (gameProc.cursorY < 0)
41 gameProc.cursorY = 0;
42 if (gameProc.cursorY >= gameProc.world.getHeight())
43 gameProc.cursorY = gameProc.world.getHeight()-1;
45 }
47 public void touchDown(int screenX, int screenY, int button) {
48 gameProc.touchDownX = screenX;
49 gameProc.touchDownY = screenY;
50 gameProc.touchDownTime = TimeUtils.millis();
51 gameProc.isTouchDown = true;
52 }
54 public void touchUp(int screenX, int screenY, int button) {
55 if (gameProc.isTouchDown) {
56 if (button == Input.Buttons.RIGHT){
57 gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY,
58 gameProc.player.inventory[gameProc.invSlot]);
59 } else if (button == Input.Buttons.LEFT) {
60 if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY) > 0) {
61 gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 0);
62 } else if (gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY) > 0) {
63 gameProc.world.placeToBackground(gameProc.cursorX, gameProc.cursorY, 0);
64 }
65 }
66 }
67 gameProc.isTouchDown = false;
68 }
70 public void touchDragged(int screenX, int screenY) {
71 /*gameProc.renderer.camera.position.x += (gameProc.touchDownX-screenX);
72 gameProc.renderer.camera.position.y += (gameProc.touchDownY-screenY);
73 gameProc.touchDownX = screenX;
74 gameProc.touchDownY = screenY;
75 gameProc.isTouchDown = false;*/
76 }
78 public void scrolled(int amount) {
79 gameProc.invSlot += amount;
80 if (gameProc.invSlot < 0) gameProc.invSlot = 8;
81 if (gameProc.invSlot > 8) gameProc.invSlot = 0;
82 }
84 }