60be6ebb4d395b1a46ac71b70dc43fad880db34f
1 package ru
.deadsoftware
.cavedroid
.game
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.utils
.Disposable
;
5 import ru
.deadsoftware
.cavedroid
.CaveGame
;
6 import ru
.deadsoftware
.cavedroid
.GameScreen
;
7 import ru
.deadsoftware
.cavedroid
.game
.mobs
.FallingGravel
;
8 import ru
.deadsoftware
.cavedroid
.game
.mobs
.FallingSand
;
9 import ru
.deadsoftware
.cavedroid
.game
.mobs
.Mob
;
10 import ru
.deadsoftware
.cavedroid
.game
.objects
.Drop
;
11 import ru
.deadsoftware
.cavedroid
.game
.objects
.Player
;
12 import ru
.deadsoftware
.cavedroid
.misc
.ControlMode
;
14 import java
.io
.Serializable
;
15 import java
.util
.ArrayList
;
17 public class GameProc
implements Serializable
, Disposable
{
19 static final int MAX_CREATIVE_SCROLL
= GameItems
.getItemsSize() / 8;
21 private static final int WORLD_WIDTH
= 1024;
22 private static final int WORLD_HEIGHT
= 256;
23 private static final int UPD_RANGE
= 16;
25 static boolean DO_UPD
= false;
26 static int UPD_X
= -1, UPD_Y
= -1;
28 private transient GameFluidsThread fluidThread
;
29 public transient GameWorld world
;
30 public transient GameRenderer renderer
;
31 public transient GameInput input
;
32 transient GamePhysics physics
;
34 public ControlMode controlMode
;
36 public ArrayList
<Mob
> mobs
;
37 ArrayList
<Drop
> drops
;
39 public void resetRenderer() {
40 int scale
= CaveGame
.TOUCH ?
320 : 480;
41 renderer
= new GameRenderer(scale
, scale
* GameScreen
.getHeight() / GameScreen
.getWidth());
44 public GameProc(int gameMode
) {
45 world
= new GameWorld(WORLD_WIDTH
, WORLD_HEIGHT
);
46 player
= new Player(gameMode
);
47 drops
= new ArrayList
<>();
48 mobs
= new ArrayList
<>();
49 physics
= new GamePhysics();
50 input
= new GameInput();
51 controlMode
= CaveGame
.TOUCH ? ControlMode
.WALK
: ControlMode
.CURSOR
;
56 private void startFluidThread() {
57 fluidThread
= new GameFluidsThread();
61 private void updateBlock(int x
, int y
) {
62 if (world
.getForeMap(x
, y
) == 10) {
63 if (!world
.hasForeAt(x
, y
+ 1) || !world
.getForeMapBlock(x
, y
+ 1).hasCollision()) {
64 world
.setForeMap(x
, y
, 0);
65 mobs
.add(new FallingSand(x
* 16, y
* 16));
66 updateBlock(x
, y
- 1);
70 if (world
.getForeMap(x
, y
) == 11) {
71 if (!world
.hasForeAt(x
, y
+ 1) || !world
.getForeMapBlock(x
, y
+ 1).hasCollision()) {
72 world
.setForeMap(x
, y
, 0);
73 mobs
.add(new FallingGravel(x
* 16, y
* 16));
74 updateBlock(x
, y
- 1);
78 if (world
.hasForeAt(x
, y
) && world
.getForeMapBlock(x
, y
).requiresBlock()) {
79 if (!world
.hasForeAt(x
, y
+ 1) || !world
.getForeMapBlock(x
, y
+ 1).hasCollision()) {
80 world
.destroyForeMap(x
, y
);
81 updateBlock(x
, y
- 1);
85 if (world
.getForeMap(x
, y
) == 2) {
86 if (world
.hasForeAt(x
, y
- 1) && (world
.getForeMapBlock(x
, y
- 1).hasCollision() ||
87 GameItems
.isFluid(world
.getForeMap(x
, y
- 1)))) {
88 world
.setForeMap(x
, y
, 3);
93 private void blockUpdater() {
95 for (int y
= UPD_Y
; y
< UPD_Y
+ UPD_RANGE
; y
++) {
96 for (int x
= UPD_X
; x
< UPD_X
+ UPD_RANGE
; x
++) {
104 public void update() {
108 if (fluidThread
== null || !fluidThread
.isAlive()) startFluidThread();
112 public void dispose() {
113 fluidThread
.interrupt();