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;
26 public final Player player
;
27 public final LinkedList
<Mob
> mobs
;
28 final LinkedList
<Drop
> drops
;
29 public transient GameWorld world
;
30 public transient GameRenderer renderer
;
31 public transient GameInput input
;
32 public ControlMode controlMode
;
33 transient GamePhysics physics
;
34 private transient GameFluidsThread fluidThread
;
36 public GameProc(int gameMode
) {
37 world
= new GameWorld(WORLD_WIDTH
, WORLD_HEIGHT
);
38 player
= new Player(gameMode
);
39 drops
= new LinkedList
<>();
40 mobs
= new LinkedList
<>();
41 physics
= new GamePhysics();
42 input
= new GameInput();
43 controlMode
= CaveGame
.TOUCH ? ControlMode
.WALK
: ControlMode
.CURSOR
;
48 public void resetRenderer() {
49 int scale
= CaveGame
.TOUCH ?
320 : 480;
50 renderer
= new GameRenderer(scale
, scale
* GameScreen
.getHeight() / GameScreen
.getWidth());
53 private void startFluidThread() {
54 fluidThread
= new GameFluidsThread();
58 private void updateBlock(int x
, int y
) {
59 if (world
.getForeMap(x
, y
) == 10) {
60 if (!world
.hasForeAt(x
, y
+ 1) || !world
.getForeMapBlock(x
, y
+ 1).hasCollision()) {
61 world
.setForeMap(x
, y
, 0);
62 mobs
.add(new FallingSand(x
* 16, y
* 16));
63 updateBlock(x
, y
- 1);
67 if (world
.getForeMap(x
, y
) == 11) {
68 if (!world
.hasForeAt(x
, y
+ 1) || !world
.getForeMapBlock(x
, y
+ 1).hasCollision()) {
69 world
.setForeMap(x
, y
, 0);
70 mobs
.add(new FallingGravel(x
* 16, y
* 16));
71 updateBlock(x
, y
- 1);
75 if (world
.hasForeAt(x
, y
) && world
.getForeMapBlock(x
, y
).requiresBlock()) {
76 if (!world
.hasForeAt(x
, y
+ 1) || !world
.getForeMapBlock(x
, y
+ 1).hasCollision()) {
77 world
.destroyForeMap(x
, y
);
78 updateBlock(x
, y
- 1);
82 if (world
.getForeMap(x
, y
) == 2) {
83 if (world
.hasForeAt(x
, y
- 1) && (world
.getForeMapBlock(x
, y
- 1).hasCollision() ||
84 GameItems
.isFluid(world
.getForeMap(x
, y
- 1)))) {
85 world
.setForeMap(x
, y
, 3);
90 private void blockUpdater() {
92 for (int y
= UPD_Y
; y
< UPD_Y
+ UPD_RANGE
; y
++) {
93 for (int x
= UPD_X
; x
< UPD_X
+ UPD_RANGE
; x
++) {
101 public void update() {
105 if (fluidThread
== null || !fluidThread
.isAlive()) {
111 public void dispose() {
112 fluidThread
.interrupt();