1 package ru
.deadsoftware
.cavedroid
.game
;
3 import com
.badlogic
.gdx
.utils
.Disposable
;
4 import ru
.deadsoftware
.cavedroid
.CaveGame
;
5 import ru
.deadsoftware
.cavedroid
.GameScreen
;
6 import ru
.deadsoftware
.cavedroid
.game
.mobs
.FallingGravel
;
7 import ru
.deadsoftware
.cavedroid
.game
.mobs
.FallingSand
;
8 import ru
.deadsoftware
.cavedroid
.game
.mobs
.Mob
;
9 import ru
.deadsoftware
.cavedroid
.game
.mobs
.Player
;
10 import ru
.deadsoftware
.cavedroid
.game
.objects
.Drop
;
11 import ru
.deadsoftware
.cavedroid
.misc
.ControlMode
;
13 import java
.io
.Serializable
;
14 import java
.util
.LinkedList
;
16 public class GameProc
implements Serializable
, Disposable
{
18 static final int MAX_CREATIVE_SCROLL
= GameItems
.getItemsSize() / 8;
20 private static final int WORLD_WIDTH
= 1024;
21 private static final int WORLD_HEIGHT
= 256;
22 private static final int UPD_RANGE
= 16;
24 static boolean DO_UPD
= false;
25 static int UPD_X
= -1, UPD_Y
= -1;
27 private transient GameFluidsThread fluidThread
;
28 public transient GameWorld world
;
29 public transient GameRenderer renderer
;
30 public transient GameInput input
;
31 transient GamePhysics physics
;
33 public ControlMode controlMode
;
34 public final Player player
;
35 public final LinkedList
<Mob
> mobs
;
36 final LinkedList
<Drop
> drops
;
38 public void resetRenderer() {
39 int scale
= CaveGame
.TOUCH ?
320 : 480;
40 renderer
= new GameRenderer(scale
, scale
* GameScreen
.getHeight() / GameScreen
.getWidth());
43 public GameProc(int gameMode
) {
44 world
= new GameWorld(WORLD_WIDTH
, WORLD_HEIGHT
);
45 player
= new Player(gameMode
);
46 drops
= new LinkedList
<>();
47 mobs
= new LinkedList
<>();
48 physics
= new GamePhysics();
49 input
= new GameInput();
50 controlMode
= CaveGame
.TOUCH ? ControlMode
.WALK
: ControlMode
.CURSOR
;
55 private void startFluidThread() {
56 fluidThread
= new GameFluidsThread();
60 private void updateBlock(int x
, int y
) {
61 if (world
.getForeMap(x
, y
) == 10) {
62 if (!world
.hasForeAt(x
, y
+ 1) || !world
.getForeMapBlock(x
, y
+ 1).hasCollision()) {
63 world
.setForeMap(x
, y
, 0);
64 mobs
.add(new FallingSand(x
* 16, y
* 16));
65 updateBlock(x
, y
- 1);
69 if (world
.getForeMap(x
, y
) == 11) {
70 if (!world
.hasForeAt(x
, y
+ 1) || !world
.getForeMapBlock(x
, y
+ 1).hasCollision()) {
71 world
.setForeMap(x
, y
, 0);
72 mobs
.add(new FallingGravel(x
* 16, y
* 16));
73 updateBlock(x
, y
- 1);
77 if (world
.hasForeAt(x
, y
) && world
.getForeMapBlock(x
, y
).requiresBlock()) {
78 if (!world
.hasForeAt(x
, y
+ 1) || !world
.getForeMapBlock(x
, y
+ 1).hasCollision()) {
79 world
.destroyForeMap(x
, y
);
80 updateBlock(x
, y
- 1);
84 if (world
.getForeMap(x
, y
) == 2) {
85 if (world
.hasForeAt(x
, y
- 1) && (world
.getForeMapBlock(x
, y
- 1).hasCollision() ||
86 GameItems
.isFluid(world
.getForeMap(x
, y
- 1)))) {
87 world
.setForeMap(x
, y
, 3);
92 private void blockUpdater() {
94 for (int y
= UPD_Y
; y
< UPD_Y
+ UPD_RANGE
; y
++) {
95 for (int x
= UPD_X
; x
< UPD_X
+ UPD_RANGE
; x
++) {
103 public void update() {
107 if (fluidThread
== null || !fluidThread
.isAlive()) startFluidThread();
111 public void dispose() {
112 fluidThread
.interrupt();