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 (gameProc
.ctrlMode
==0) {
16 if (keyCode
== Input
.Keys
.A
) {
17 gameProc
.player
.moveX
.add(-GamePhysics
.PL_SPEED
, 0);
18 gameProc
.player
.dir
= 0;
20 if (keyCode
== Input
.Keys
.D
) {
21 gameProc
.player
.moveX
.add(GamePhysics
.PL_SPEED
, 0);
22 gameProc
.player
.dir
= 1;
25 if (keyCode
== Input
.Keys
.A
) {
28 if (keyCode
== Input
.Keys
.D
) {
31 if (keyCode
== Input
.Keys
.W
) {
34 if (keyCode
== Input
.Keys
.S
) {
37 if (gameProc
.cursorX
< 0)
39 if (gameProc
.cursorX
>= gameProc
.world
.getWidth())
40 gameProc
.cursorX
= gameProc
.world
.getWidth()-1;
41 if (gameProc
.cursorY
< 0)
43 if (gameProc
.cursorY
>= gameProc
.world
.getHeight())
44 gameProc
.cursorY
= gameProc
.world
.getHeight()-1;
46 if (keyCode
== Input
.Keys
.ALT_LEFT
) {
48 gameProc
.cursorX
= (int)(gameProc
.player
.position
.x
/16);
49 gameProc
.cursorY
= (int)(gameProc
.player
.position
.y
/16);
50 if (gameProc
.ctrlMode
> 1) gameProc
.ctrlMode
= 0;
52 if (keyCode
== Input
.Keys
.SPACE
) {
53 if (gameProc
.player
.canJump
) {
54 gameProc
.player
.moveY
.add(0, -8);
55 } else if (!gameProc
.player
.flyMode
) {
56 gameProc
.player
.flyMode
= true;
57 gameProc
.player
.moveY
.setZero();
59 gameProc
.player
.moveY
.y
= -GamePhysics
.PL_SPEED
;
62 if (keyCode
== Input
.Keys
.CONTROL_LEFT
) {
63 gameProc
.player
.moveY
.y
= GamePhysics
.PL_SPEED
;
67 public void keyUp(int keyCode
) {
68 if (keyCode
== Input
.Keys
.A
|| keyCode
== Input
.Keys
.D
) {
69 gameProc
.player
.moveX
.x
= 0;
71 if (keyCode
== Input
.Keys
.SPACE
) {
72 if (gameProc
.player
.flyMode
) gameProc
.player
.moveY
.setZero();
74 if (keyCode
== Input
.Keys
.CONTROL_LEFT
) {
75 if (gameProc
.player
.flyMode
) gameProc
.player
.moveY
.setZero();
79 public void mouseMoved(int screenX
, int screenY
) {
82 public void touchDown(int screenX
, int screenY
, int button
) {
83 gameProc
.touchDownX
= screenX
;
84 gameProc
.touchDownY
= screenY
;
85 gameProc
.touchDownTime
= TimeUtils
.millis();
86 gameProc
.isTouchDown
= true;
89 public void touchUp(int screenX
, int screenY
, int button
) {
90 if (gameProc
.isTouchDown
) {
91 if (button
== Input
.Buttons
.RIGHT
){
92 gameProc
.world
.placeToForeground(gameProc
.cursorX
, gameProc
.cursorY
,
93 gameProc
.player
.inventory
[gameProc
.invSlot
]);
94 } else if (button
== Input
.Buttons
.LEFT
) {
95 if (gameProc
.world
.getForeMap(gameProc
.cursorX
, gameProc
.cursorY
) > 0) {
96 gameProc
.world
.placeToForeground(gameProc
.cursorX
, gameProc
.cursorY
, 0);
97 } else if (gameProc
.world
.getBackMap(gameProc
.cursorX
, gameProc
.cursorY
) > 0) {
98 gameProc
.world
.placeToBackground(gameProc
.cursorX
, gameProc
.cursorY
, 0);
102 gameProc
.isTouchDown
= false;
105 public void touchDragged(int screenX
, int screenY
) {
108 public void scrolled(int amount
) {
109 gameProc
.invSlot
+= amount
;
110 if (gameProc
.invSlot
< 0) gameProc
.invSlot
= 8;
111 if (gameProc
.invSlot
> 8) gameProc
.invSlot
= 0;