1 package ru
.deadsoftware
.cavecraft
.game
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.Input
;
5 import com
.badlogic
.gdx
.utils
.Array
;
6 import com
.badlogic
.gdx
.utils
.TimeUtils
;
7 import ru
.deadsoftware
.cavecraft
.*;
8 import ru
.deadsoftware
.cavecraft
.game
.mobs
.Mob
;
9 import ru
.deadsoftware
.cavecraft
.game
.mobs
.Pig
;
10 import ru
.deadsoftware
.cavecraft
.game
.objects
.Player
;
12 import java
.io
.Serializable
;
13 import java
.util
.ArrayList
;
15 public class GameProc
implements Serializable
{
17 public static double RUN_TIME
= 0;
21 public ArrayList
<Mob
> mobs
;
23 public transient GameWorld world
;
24 public transient GameRenderer renderer
;
25 public transient GamePhysics physics
;
27 public int cursorX
, cursorY
;
31 public boolean isTouchDown
, isKeyDown
;
32 public int touchDownX
, touchDownY
, keyDownCode
;
33 public int touchDownButton
;
34 public long touchDownTime
;
37 world
= new GameWorld();
38 world
.generate(1024,256);
39 player
= new Player(world
.getSpawnPoint());
40 mobs
= new ArrayList
<Mob
>();
41 for (int i
=0; i
<16; i
++) {
42 mobs
.add(new Pig(i
*256, 128&16, this));
44 physics
= new GamePhysics(this);
45 if (!CaveGame
.TOUCH
) ctrlMode
= 1;
47 renderer
= new GameRenderer(this,320,
48 320*((float)GameScreen
.getHeight()/GameScreen
.getWidth()));
50 renderer
= new GameRenderer(this,480,
51 480*((float)GameScreen
.getHeight()/GameScreen
.getWidth()));
56 public void resetRenderer() {
58 renderer
= new GameRenderer(this,320,
59 320*((float)GameScreen
.getHeight()/GameScreen
.getWidth()));
61 renderer
= new GameRenderer(this,480,
62 480*((float)GameScreen
.getHeight()/GameScreen
.getWidth()));
66 private boolean isAutoselectable(int x
, int y
) {
67 return (world
.getForeMap(x
,y
)>0 &&
68 Items
.BLOCKS
.getValueAt(world
.getForeMap(x
,y
)).collision
);
71 private void moveCursor() {
72 if (ctrlMode
== 0 && CaveGame
.TOUCH
) {
73 cursorX
= (int) (player
.position
.x
+ player
.texWidth
/ 2) / 16;
74 if (player
.dir
== 0) cursorX
--;
76 cursorY
= (int) (player
.position
.y
+ player
.texWidth
) / 16;
77 if (!isAutoselectable(cursorX
, cursorY
)) {
80 if (!isAutoselectable(cursorX
, cursorY
)) {
83 if (!isAutoselectable(cursorX
, cursorY
)) {
84 if (player
.dir
== 0) cursorX
++;
87 } else if (!CaveGame
.TOUCH
){
88 cursorX
= (int)(Gdx
.input
.getX()*
89 (renderer
.camera
.viewportWidth
/GameScreen
.getWidth())+renderer
.camera
.position
.x
)/16;
90 cursorY
= (int)(Gdx
.input
.getY()*
91 (renderer
.camera
.viewportHeight
/GameScreen
.getHeight())+renderer
.camera
.position
.y
)/16;
92 if ((Gdx
.input
.getX()*
93 (renderer
.camera
.viewportWidth
/GameScreen
.getWidth())+renderer
.camera
.position
.x
)<0)
98 private void checkCursorBounds() {
99 if (cursorY
< 0) cursorY
= 0;
100 if (cursorY
>= world
.getHeight()) cursorY
= world
.getHeight()-1;
102 if (cursorX
*16+8<player
.position
.x
+player
.texWidth
/2)
104 if (cursorX
*16+8>player
.position
.x
+player
.texWidth
/2)
109 public void update(float delta
) {
112 physics
.update(delta
);
116 if (isTouchDown
&& TimeUtils
.timeSinceMillis(touchDownTime
) > 500) {
117 if (touchDownButton
== Input
.Buttons
.RIGHT
) {
118 world
.placeToBackground(cursorX
, cursorY
,
119 player
.inventory
[invSlot
]);
120 } else if (touchDownButton
==Input
.Buttons
.LEFT
&&
121 touchDownY
< Assets
.invBar
.getRegionHeight() &&
122 touchDownX
>renderer
.camera
.viewportWidth
/2-Assets
.invBar
.getRegionWidth()/2 &&
123 touchDownX
<renderer
.camera
.viewportWidth
/2+Assets
.invBar
.getRegionWidth()/2) {
124 CaveGame
.STATE
= AppState
.GAME_CREATIVE_INV
;