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
;
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;
19 if (keyCode
== Input
.Keys
.RIGHT
) {
20 gameProc
.player
.moveX
.add(GamePhysics
.PL_SPEED
,0);
21 gameProc
.player
.dir
= 1;
23 if (keyCode
== Input
.Keys
.UP
) gameProc
.player
.moveY
.add(0,-12);
26 public void keyUp(int keyCode
) {
27 if (keyCode
== Input
.Keys
.RIGHT
|| keyCode
== Input
.Keys
.LEFT
) {
28 gameProc
.player
.moveX
.x
= 0;
32 public void mouseMoved(int screenX
, int screenY
) {
33 gameProc
.cursorX
= (int)((screenX
+gameProc
.renderer
.camera
.position
.x
)/16);
34 gameProc
.cursorY
= (int)((screenY
+gameProc
.renderer
.camera
.position
.y
)/16);
35 if (gameProc
.cursorX
< 0)
37 if (gameProc
.cursorX
>= gameProc
.world
.getWidth())
38 gameProc
.cursorX
= gameProc
.world
.getWidth()-1;
39 if (gameProc
.cursorY
< 0)
41 if (gameProc
.cursorY
>= gameProc
.world
.getHeight())
42 gameProc
.cursorY
= gameProc
.world
.getHeight()-1;
46 public void touchDown(int screenX
, int screenY
, int button
) {
47 gameProc
.touchDownX
= screenX
;
48 gameProc
.touchDownY
= screenY
;
49 gameProc
.touchDownTime
= TimeUtils
.millis();
50 gameProc
.isTouchDown
= true;
53 public void touchUp(int screenX
, int screenY
, int button
) {
54 if (gameProc
.isTouchDown
) {
55 if (button
== Input
.Buttons
.RIGHT
){
56 gameProc
.world
.placeToForeground(gameProc
.cursorX
, gameProc
.cursorY
, 1);
57 } else if (button
== Input
.Buttons
.LEFT
) {
58 if (gameProc
.world
.getForeMap(gameProc
.cursorX
, gameProc
.cursorY
) > 0) {
59 gameProc
.world
.placeToForeground(gameProc
.cursorX
, gameProc
.cursorY
, 0);
60 } else if (gameProc
.world
.getBackMap(gameProc
.cursorX
, gameProc
.cursorY
) > 0) {
61 gameProc
.world
.placeToBackground(gameProc
.cursorX
, gameProc
.cursorY
, 0);
65 gameProc
.isTouchDown
= false;
68 public void touchDragged(int screenX
, int screenY
) {
69 gameProc
.renderer
.camera
.position
.x
+= (gameProc
.touchDownX
-screenX
);
70 gameProc
.renderer
.camera
.position
.y
+= (gameProc
.touchDownY
-screenY
);
71 gameProc
.touchDownX
= screenX
;
72 gameProc
.touchDownY
= screenY
;
73 gameProc
.isTouchDown
= false;