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 gameProc
.player
.canJump
) gameProc
.player
.moveY
.add(0, -8);
56 public void keyUp(int keyCode
) {
57 if (keyCode
== Input
.Keys
.A
|| keyCode
== Input
.Keys
.D
) {
58 gameProc
.player
.moveX
.x
= 0;
62 public void mouseMoved(int screenX
, int screenY
) {
65 public void touchDown(int screenX
, int screenY
, int button
) {
66 gameProc
.touchDownX
= screenX
;
67 gameProc
.touchDownY
= screenY
;
68 gameProc
.touchDownTime
= TimeUtils
.millis();
69 gameProc
.isTouchDown
= true;
72 public void touchUp(int screenX
, int screenY
, int button
) {
73 if (gameProc
.isTouchDown
) {
74 if (button
== Input
.Buttons
.RIGHT
){
75 gameProc
.world
.placeToForeground(gameProc
.cursorX
, gameProc
.cursorY
,
76 gameProc
.player
.inventory
[gameProc
.invSlot
]);
77 } else if (button
== Input
.Buttons
.LEFT
) {
78 if (gameProc
.world
.getForeMap(gameProc
.cursorX
, gameProc
.cursorY
) > 0) {
79 gameProc
.world
.placeToForeground(gameProc
.cursorX
, gameProc
.cursorY
, 0);
80 } else if (gameProc
.world
.getBackMap(gameProc
.cursorX
, gameProc
.cursorY
) > 0) {
81 gameProc
.world
.placeToBackground(gameProc
.cursorX
, gameProc
.cursorY
, 0);
85 gameProc
.isTouchDown
= false;
88 public void touchDragged(int screenX
, int screenY
) {
91 public void scrolled(int amount
) {
92 gameProc
.invSlot
+= amount
;
93 if (gameProc
.invSlot
< 0) gameProc
.invSlot
= 8;
94 if (gameProc
.invSlot
> 8) gameProc
.invSlot
= 0;