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
&&
24 gameProc
.player
.canJump
) gameProc
.player
.moveY
.add(0,-8);
27 public void keyUp(int keyCode
) {
28 if (keyCode
== Input
.Keys
.RIGHT
|| keyCode
== Input
.Keys
.LEFT
) {
29 gameProc
.player
.moveX
.x
= 0;
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)
38 if (gameProc
.cursorX
>= gameProc
.world
.getWidth())
39 gameProc
.cursorX
= gameProc
.world
.getWidth()-1;
40 if (gameProc
.cursorY
< 0)
42 if (gameProc
.cursorY
>= gameProc
.world
.getHeight())
43 gameProc
.cursorY
= gameProc
.world
.getHeight()-1;
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;
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
, 1);
58 } else if (button
== Input
.Buttons
.LEFT
) {
59 if (gameProc
.world
.getForeMap(gameProc
.cursorX
, gameProc
.cursorY
) > 0) {
60 gameProc
.world
.placeToForeground(gameProc
.cursorX
, gameProc
.cursorY
, 0);
61 } else if (gameProc
.world
.getBackMap(gameProc
.cursorX
, gameProc
.cursorY
) > 0) {
62 gameProc
.world
.placeToBackground(gameProc
.cursorX
, gameProc
.cursorY
, 0);
66 gameProc
.isTouchDown
= false;
69 public void touchDragged(int screenX
, int screenY
) {
70 gameProc
.renderer
.camera
.position
.x
+= (gameProc
.touchDownX
-screenX
);
71 gameProc
.renderer
.camera
.position
.y
+= (gameProc
.touchDownY
-screenY
);
72 gameProc
.touchDownX
= screenX
;
73 gameProc
.touchDownY
= screenY
;
74 gameProc
.isTouchDown
= false;