DEADSOFTWARE

Add input handling
[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 mouseMoved(int screenX, int screenY) {
15 gameProc.cursorX = (int)((screenX+gameProc.renderer.camera.position.x)/32);
16 gameProc.cursorY = (int)((screenY+gameProc.renderer.camera.position.y)/32);
17 if (gameProc.cursorX < 0)
18 gameProc.cursorX = 0;
19 if (gameProc.cursorX >= gameProc.world.getWidth())
20 gameProc.cursorX = gameProc.world.getWidth()-1;
21 if (gameProc.cursorY < 0)
22 gameProc.cursorY = 0;
23 if (gameProc.cursorY >= gameProc.world.getHeight())
24 gameProc.cursorY = gameProc.world.getHeight()-1;
26 }
28 public void touchDown(int screenX, int screenY, int button) {
29 if (button == Input.Buttons.LEFT) {
30 if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY) > 0) {
31 gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 0);
32 } else if (gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY) > 0) {
33 gameProc.world.placeToBackground(gameProc.cursorX, gameProc.cursorY, 0);
34 }
35 } else {
36 gameProc.touchDownTime = TimeUtils.millis();
37 gameProc.isTouchDown = true;
38 }
39 }
41 public void touchUp(int screenX, int screenY, int button) {
42 if (gameProc.isTouchDown && button == Input.Buttons.RIGHT){
43 gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 1);
44 }
45 gameProc.isTouchDown = false;
46 }
48 public void touchDragged(int screenX, int screenY) {
49 }
51 }