ea5296a4f226aa93c4d3bb594d0071de41c8ec91
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 javax
.annotation
.Nullable
;
14 import java
.io
.Serializable
;
15 import java
.util
.LinkedList
;
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;
27 public final Player player
;
28 public final LinkedList
<Mob
> mobs
;
29 final LinkedList
<Drop
> drops
;
30 public transient GameWorld world
;
31 public transient GameRenderer renderer
;
32 public transient GameInput input
;
33 public ControlMode controlMode
;
34 transient GamePhysics physics
;
35 @Nullable private transient GameFluidsThread fluidThread
;
37 public GameProc(int gameMode
) {
38 world
= new GameWorld(WORLD_WIDTH
, WORLD_HEIGHT
);
39 player
= new Player(gameMode
);
40 drops
= new LinkedList
<>();
41 mobs
= new LinkedList
<>();
42 physics
= new GamePhysics();
43 input
= new GameInput();
44 controlMode
= CaveGame
.TOUCH ? ControlMode
.WALK
: ControlMode
.CURSOR
;
45 renderer
= resetRenderer();
49 public GameRenderer
resetRenderer() {
50 int scale
= CaveGame
.TOUCH ?
320 : 480;
51 renderer
= new GameRenderer(scale
, scale
* GameScreen
.getHeight() / GameScreen
.getWidth());
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()) {
113 public void dispose() {
114 if (fluidThread
!= null) {
115 fluidThread
.interrupt();