0b714ddd43eda90fa210a60108f592d79ece325e
1 package ru
.deadsoftware
.cavecraft
.game
;
3 import com
.badlogic
.gdx
.Input
;
4 import com
.badlogic
.gdx
.utils
.TimeUtils
;
5 import ru
.deadsoftware
.cavecraft
.GameScreen
;
7 public class GameInputHandler
{
9 private GameProc gameProc
;
11 public GameInputHandler(GameProc gameProc
) {
12 this.gameProc
= gameProc
;
15 public void keyDown(int keyCode
) {
16 if (gameProc
.ctrlMode
==0) {
17 if (keyCode
== Input
.Keys
.A
) {
18 gameProc
.player
.moveX
.add(-GamePhysics
.PL_SPEED
, 0);
19 gameProc
.player
.dir
= 0;
21 if (keyCode
== Input
.Keys
.D
) {
22 gameProc
.player
.moveX
.add(GamePhysics
.PL_SPEED
, 0);
23 gameProc
.player
.dir
= 1;
26 if (keyCode
== Input
.Keys
.A
) {
29 if (keyCode
== Input
.Keys
.D
) {
32 if (keyCode
== Input
.Keys
.W
) {
35 if (keyCode
== Input
.Keys
.S
) {
38 if (gameProc
.cursorX
< 0)
40 if (gameProc
.cursorX
>= gameProc
.world
.getWidth())
41 gameProc
.cursorX
= gameProc
.world
.getWidth()-1;
42 if (gameProc
.cursorY
< 0)
44 if (gameProc
.cursorY
>= gameProc
.world
.getHeight())
45 gameProc
.cursorY
= gameProc
.world
.getHeight()-1;
47 if (keyCode
== Input
.Keys
.ALT_LEFT
) {
49 gameProc
.cursorX
= (int)(gameProc
.player
.position
.x
/16);
50 gameProc
.cursorY
= (int)(gameProc
.player
.position
.y
/16);
51 if (gameProc
.ctrlMode
> 1) gameProc
.ctrlMode
= 0;
53 if (keyCode
== Input
.Keys
.SPACE
) {
54 if (gameProc
.player
.canJump
) {
55 gameProc
.player
.moveY
.add(0, -7);
56 } else if (!gameProc
.player
.flyMode
) {
57 gameProc
.player
.flyMode
= true;
58 gameProc
.player
.moveY
.setZero();
60 gameProc
.player
.moveY
.y
= -GamePhysics
.PL_SPEED
;
63 if (keyCode
== Input
.Keys
.CONTROL_LEFT
) {
64 gameProc
.player
.moveY
.y
= GamePhysics
.PL_SPEED
;
68 public void keyUp(int keyCode
) {
69 if (keyCode
== Input
.Keys
.A
|| keyCode
== Input
.Keys
.D
) {
70 gameProc
.player
.moveX
.x
= 0;
72 if (keyCode
== Input
.Keys
.SPACE
) {
73 if (gameProc
.player
.flyMode
) gameProc
.player
.moveY
.setZero();
75 if (keyCode
== Input
.Keys
.CONTROL_LEFT
) {
76 if (gameProc
.player
.flyMode
) gameProc
.player
.moveY
.setZero();
80 public void mouseMoved(int screenX
, int screenY
) {
83 public void touchDown(int screenX
, int screenY
, int button
) {
84 gameProc
.touchDownX
= screenX
;
85 gameProc
.touchDownY
= screenY
;
86 gameProc
.touchDownTime
= TimeUtils
.millis();
87 gameProc
.isTouchDown
= true;
90 public void touchUp(int screenX
, int screenY
, int button
) {
91 if (gameProc
.isTouchDown
) {
92 if (button
== Input
.Buttons
.RIGHT
){
93 gameProc
.world
.placeToForeground(gameProc
.cursorX
, gameProc
.cursorY
,
94 gameProc
.player
.inventory
[gameProc
.invSlot
]);
95 } else if (button
== Input
.Buttons
.LEFT
) {
96 if (gameProc
.world
.getForeMap(gameProc
.cursorX
, gameProc
.cursorY
) > 0) {
97 gameProc
.world
.placeToForeground(gameProc
.cursorX
, gameProc
.cursorY
, 0);
98 } else if (gameProc
.world
.getBackMap(gameProc
.cursorX
, gameProc
.cursorY
) > 0) {
99 gameProc
.world
.placeToBackground(gameProc
.cursorX
, gameProc
.cursorY
, 0);
103 gameProc
.isTouchDown
= false;
106 public void touchDragged(int screenX
, int screenY
) {
109 public void scrolled(int amount
) {
110 gameProc
.invSlot
+= amount
;
111 if (gameProc
.invSlot
< 0) gameProc
.invSlot
= 8;
112 if (gameProc
.invSlot
> 8) gameProc
.invSlot
= 0;