1 package ru
.deadsoftware
.cavecraft
.game
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.Input
;
5 import com
.badlogic
.gdx
.math
.RandomXS128
;
6 import com
.badlogic
.gdx
.utils
.Array
;
7 import com
.badlogic
.gdx
.utils
.TimeUtils
;
8 import ru
.deadsoftware
.cavecraft
.*;
9 import ru
.deadsoftware
.cavecraft
.game
.mobs
.Human
;
10 import ru
.deadsoftware
.cavecraft
.game
.mobs
.Mob
;
11 import ru
.deadsoftware
.cavecraft
.game
.objects
.Player
;
13 public class GameProc
{
15 public static double RUN_TIME
= 0;
19 public Array
<Mob
> mobs
;
21 public GameWorld world
;
22 public GameRenderer renderer
;
23 public GamePhysics physics
;
25 public int cursorX
, cursorY
;
29 public boolean isTouchDown
= false;
30 public int touchDownX
, touchDownY
;
31 public int touchDownButton
;
32 public long touchDownTime
;
35 world
= new GameWorld(1024,256);
36 renderer
= new GameRenderer(this);
37 physics
= new GamePhysics(this);
38 player
= new Player(world
.getSpawnPoint());
39 mobs
= new Array
<Mob
>();
40 if (!CaveGame
.TOUCH
) ctrlMode
= 1;
43 public void resetRenderer() {
44 renderer
= new GameRenderer(this);
47 private boolean isAutoselectable(int x
, int y
) {
48 return (world
.getForeMap(x
,y
)>0 &&
49 Items
.BLOCKS
.getValueAt(world
.getForeMap(x
,y
)).collision
);
52 private void moveCursor() {
55 cursorX
= (int) (player
.position
.x
+ player
.texWidth
/ 2) / 16;
56 if (player
.dir
== 0) cursorX
--;
58 cursorY
= (int) (player
.position
.y
+ player
.texWidth
) / 16;
59 if (!isAutoselectable(cursorX
, cursorY
)) {
62 if (!isAutoselectable(cursorX
, cursorY
)) {
65 if (!isAutoselectable(cursorX
, cursorY
)) {
66 if (player
.dir
== 0) cursorX
++;
70 cursorX
= (int) (player
.position
.x
+ player
.texWidth
/ 2) / 16;
71 cursorY
= (int) (player
.position
.y
+ player
.height
+8)/16;
73 } else if (!CaveGame
.TOUCH
){
74 cursorX
= (int)(Gdx
.input
.getX()*
75 (renderer
.camera
.viewportWidth
/GameScreen
.getWidth())+renderer
.camera
.position
.x
)/16;
76 cursorY
= (int)(Gdx
.input
.getY()*
77 (renderer
.camera
.viewportHeight
/GameScreen
.getHeight())+renderer
.camera
.position
.y
)/16;
81 private void checkCursorBounds() {
82 if (cursorX
< 0) cursorX
= 0;
83 if (cursorX
>= world
.getWidth()) cursorX
= world
.getWidth()-1;
84 if (cursorY
< 0) cursorY
= 0;
85 if (cursorY
>= world
.getHeight()) cursorY
= world
.getHeight()-1;
86 if (cursorX
<(player
.position
.x
+player
.texWidth
/2)/16)
88 if (cursorX
>(player
.position
.x
+player
.texWidth
/2)/16)
92 public void update(float delta
) {
95 physics
.update(delta
);
99 if (isTouchDown
&& TimeUtils
.timeSinceMillis(touchDownTime
) > 500) {
100 if (touchDownButton
== Input
.Buttons
.RIGHT
) {
101 world
.placeToBackground(cursorX
, cursorY
,
102 player
.inventory
[invSlot
]);
103 } else if (touchDownButton
==Input
.Buttons
.LEFT
&&
104 touchDownY
< Assets
.invBar
.getRegionHeight() &&
105 touchDownX
>renderer
.camera
.viewportWidth
/2-Assets
.invBar
.getRegionWidth()/2 &&
106 touchDownX
<renderer
.camera
.viewportWidth
/2+Assets
.invBar
.getRegionWidth()/2) {
107 CaveGame
.STATE
= GameState
.GAME_CREATIVE_INV
;