1 package ru
.deadsoftware
.cavecraft
.game
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.Input
;
5 import com
.badlogic
.gdx
.utils
.TimeUtils
;
6 import ru
.deadsoftware
.cavecraft
.CaveGame
;
7 import ru
.deadsoftware
.cavecraft
.GameScreen
;
8 import ru
.deadsoftware
.cavecraft
.game
.mobs
.Mob
;
9 import ru
.deadsoftware
.cavecraft
.game
.mobs
.Pig
;
10 import ru
.deadsoftware
.cavecraft
.game
.objects
.Player
;
11 import ru
.deadsoftware
.cavecraft
.misc
.AppState
;
12 import ru
.deadsoftware
.cavecraft
.misc
.Assets
;
14 import java
.io
.Serializable
;
15 import java
.util
.ArrayList
;
17 public class GameProc
implements Serializable
{
19 public static double RUN_TIME
= 0;
23 public ArrayList
<Mob
> mobs
;
25 public transient GameWorld world
;
26 public transient GameRenderer renderer
;
27 public transient GamePhysics physics
;
29 public int cursorX
, cursorY
;
32 public int creativeScroll
, maxCreativeScroll
;
34 public boolean isTouchDown
, isKeyDown
;
35 public int touchDownX
, touchDownY
, keyDownCode
;
36 public int touchDownButton
;
37 public long touchDownTime
;
40 world
= new GameWorld();
41 world
.generate(1024,256);
42 player
= new Player(world
.getSpawnPoint());
43 mobs
= new ArrayList
<Mob
>();
44 for (int i
=0; i
<16; i
++) {
45 mobs
.add(new Pig(i
*256, 196*16));
47 physics
= new GamePhysics(this);
49 renderer
= new GameRenderer(this,320,
50 320*((float)GameScreen
.getHeight()/GameScreen
.getWidth()));
53 renderer
= new GameRenderer(this,480,
54 480*((float)GameScreen
.getHeight()/GameScreen
.getWidth()));
56 maxCreativeScroll
= Items
.BLOCKS
.size
/8;
60 public void resetRenderer() {
62 renderer
= new GameRenderer(this,320,
63 320*((float)GameScreen
.getHeight()/GameScreen
.getWidth()));
65 renderer
= new GameRenderer(this,480,
66 480*((float)GameScreen
.getHeight()/GameScreen
.getWidth()));
70 private boolean isAutoselectable(int x
, int y
) {
71 return (world
.getForeMap(x
,y
)>0 &&
72 Items
.BLOCKS
.getValueAt(world
.getForeMap(x
,y
)).collision
);
75 private void moveCursor() {
76 if (ctrlMode
== 0 && CaveGame
.TOUCH
) {
77 cursorX
= (int) (player
.position
.x
+ player
.texWidth
/ 2) / 16;
78 if (player
.dir
== 0) cursorX
--;
80 cursorY
= (int) (player
.position
.y
+ player
.texWidth
) / 16;
81 if (!isAutoselectable(cursorX
, cursorY
)) {
84 if (!isAutoselectable(cursorX
, cursorY
)) {
87 if (!isAutoselectable(cursorX
, cursorY
)) {
88 if (player
.dir
== 0) cursorX
++;
91 } else if (!CaveGame
.TOUCH
){
92 cursorX
= (int)(Gdx
.input
.getX()*
93 (renderer
.camera
.viewportWidth
/GameScreen
.getWidth())+renderer
.camera
.position
.x
)/16;
94 cursorY
= (int)(Gdx
.input
.getY()*
95 (renderer
.camera
.viewportHeight
/GameScreen
.getHeight())+renderer
.camera
.position
.y
)/16;
96 if ((Gdx
.input
.getX()*
97 (renderer
.camera
.viewportWidth
/GameScreen
.getWidth())+renderer
.camera
.position
.x
)<0)
102 private void checkCursorBounds() {
103 if (cursorY
< 0) cursorY
= 0;
104 if (cursorY
>= world
.getHeight()) cursorY
= world
.getHeight()-1;
106 if (cursorX
*16+8<player
.position
.x
+player
.texWidth
/2)
108 if (cursorX
*16+8>player
.position
.x
+player
.texWidth
/2)
113 public void update(float delta
) {
116 physics
.update(delta
);
120 if (isTouchDown
&& TimeUtils
.timeSinceMillis(touchDownTime
) > 500) {
121 if (touchDownButton
== Input
.Buttons
.RIGHT
) {
122 world
.placeToBackground(cursorX
, cursorY
,
123 player
.inventory
[invSlot
]);
124 } else if (touchDownY
< Assets
.invBar
.getRegionHeight() &&
125 touchDownX
>renderer
.camera
.viewportWidth
/2-Assets
.invBar
.getRegionWidth()/2 &&
126 touchDownX
<renderer
.camera
.viewportWidth
/2+Assets
.invBar
.getRegionWidth()/2) {
127 CaveGame
.STATE
= AppState
.GAME_CREATIVE_INV
;