53b2b9060ed6eca4fd65e0aa73d4c4380837d47e
1 package ru
.deadsoftware
.cavedroid
.game
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.Input
;
5 import com
.badlogic
.gdx
.utils
.Disposable
;
6 import com
.badlogic
.gdx
.utils
.TimeUtils
;
7 import ru
.deadsoftware
.cavedroid
.CaveGame
;
8 import ru
.deadsoftware
.cavedroid
.GameScreen
;
9 import ru
.deadsoftware
.cavedroid
.game
.mobs
.FallingGravel
;
10 import ru
.deadsoftware
.cavedroid
.game
.mobs
.FallingSand
;
11 import ru
.deadsoftware
.cavedroid
.game
.mobs
.Mob
;
12 import ru
.deadsoftware
.cavedroid
.game
.mobs
.Pig
;
13 import ru
.deadsoftware
.cavedroid
.game
.objects
.Drop
;
14 import ru
.deadsoftware
.cavedroid
.game
.objects
.Player
;
15 import ru
.deadsoftware
.cavedroid
.misc
.AppState
;
16 import ru
.deadsoftware
.cavedroid
.misc
.Assets
;
18 import java
.io
.Serializable
;
19 import java
.util
.ArrayList
;
21 public class GameProc
implements Serializable
, Disposable
{
23 private static final int FLUID_UPDATE_INTERVAL_MS
= 100;
25 static boolean DO_UPD
= false;
26 static int UPD_X
= -1, UPD_Y
= -1;
28 private transient Thread fluidThread
;
30 public transient GameWorld world
;
31 public transient GameRenderer renderer
;
32 public transient GamePhysics physics
;
35 public ArrayList
<Mob
> mobs
;
36 public ArrayList
<Drop
> drops
;
38 private long fluidLastUpdateTimestamp
= 0;
40 public boolean isTouchDown
, isKeyDown
;
41 public int ctrlMode
, touchDownX
, touchDownY
, touchDownBtn
, keyDownCode
;
42 public long touchDownTime
;
45 int creativeScroll
, maxCreativeScroll
;
48 public void initGame(int gameMode
) {
49 world
= new GameWorld();
50 world
.generate(1024, 256);
51 player
= new Player(gameMode
);
52 drops
= new ArrayList
<>();
53 mobs
= new ArrayList
<>();
54 for (int i
= 0; i
< 16; i
++) {
55 mobs
.add(new Pig(i
* 256, 196 * 16));
57 physics
= new GamePhysics();
59 renderer
= new GameRenderer(320,
60 320 * ((float) GameScreen
.getHeight() / GameScreen
.getWidth()));
63 renderer
= new GameRenderer(480,
64 480 * ((float) GameScreen
.getHeight() / GameScreen
.getWidth()));
66 maxCreativeScroll
= GameItems
.getItemsSize() / 8;
75 private void createFluidThread() {
76 fluidThread
= new Thread(() -> {
77 while (!fluidThread
.isInterrupted()) {
78 if (System
.currentTimeMillis() - fluidLastUpdateTimestamp
> FLUID_UPDATE_INTERVAL_MS
) {
80 fluidLastUpdateTimestamp
= System
.currentTimeMillis();
86 public void resetRenderer() {
88 renderer
= new GameRenderer(320,
89 320 * ((float) GameScreen
.getHeight() / GameScreen
.getWidth()));
91 renderer
= new GameRenderer(480,
92 480 * ((float) GameScreen
.getHeight() / GameScreen
.getWidth()));
96 private boolean isAutoselectable(int x
, int y
) {
97 return (world
.getForeMap(x
, y
) > 0 &&
98 GameItems
.getBlock(world
.getForeMap(x
, y
)).hasCollision());
101 private void moveCursor() {
102 int pastX
= curX
, pastY
= curY
;
103 if (ctrlMode
== 0 && CaveGame
.TOUCH
) {
104 curX
= player
.getMapX();
105 if (player
.getDir() == 0) curX
--;
107 curY
= (int) (player
.pos
.y
+ player
.getWidth()) / 16;
108 if (!isAutoselectable(curX
, curY
)) {
111 if (!isAutoselectable(curX
, curY
)) {
114 if (!isAutoselectable(curX
, curY
)) {
115 if (player
.getDir() == 0) curX
++;
118 } else if (!CaveGame
.TOUCH
) {
119 curX
= (int) (Gdx
.input
.getX() *
120 (renderer
.getWidth() / GameScreen
.getWidth()) + renderer
.getCamX()) / 16;
121 curY
= (int) (Gdx
.input
.getY() *
122 (renderer
.getHeight() / GameScreen
.getHeight()) + renderer
.getCamY()) / 16;
123 if ((Gdx
.input
.getX() *
124 (renderer
.getWidth() / GameScreen
.getWidth()) + renderer
.getCamX()) < 0)
127 if (pastX
!= curX
|| pastY
!= curY
) blockDmg
= 0;
130 private void checkCursorBounds() {
131 if (curY
< 0) curY
= 0;
132 if (curY
>= world
.getHeight()) curY
= world
.getHeight() - 1;
134 if (curX
* 16 + 8 < player
.pos
.x
+ player
.getWidth() / 2)
136 if (curX
* 16 + 8 > player
.pos
.x
+ player
.getWidth() / 2)
141 private void updateFluids(int x
, int y
) {
142 if (GameItems
.isWater(world
.getForeMap(x
, y
)) && world
.getForeMap(x
, y
) != 8) {
143 if (world
.getForeMap(x
, y
) == 60) {
144 if (!GameItems
.isWater(world
.getForeMap(x
, y
- 1)))
145 world
.setForeMap(x
, y
, world
.getForeMap(x
, y
) + 1);
146 } else if ((!GameItems
.isWater(world
.getForeMap(x
- 1, y
)) ||
147 (GameItems
.isWater(world
.getForeMap(x
, y
)) && world
.getForeMap(x
- 1, y
) >= world
.getForeMap(x
, y
))) &&
148 (!GameItems
.isWater(world
.getForeMap(x
+ 1, y
)) ||
149 (GameItems
.isWater(world
.getForeMap(x
, y
)) && world
.getForeMap(x
+ 1, y
) >= world
.getForeMap(x
, y
)))) {
150 world
.setForeMap(x
, y
, world
.getForeMap(x
, y
) + 1);
152 if (world
.getForeMap(x
, y
) > 63) world
.setForeMap(x
, y
, 0);
155 if (world
.getForeMap(x
, y
) == 8 || world
.getForeMap(x
, y
) == 60) {
156 if (world
.getForeMap(x
, y
+ 1) == 0 || (world
.getForeMap(x
, y
+ 1) >= 61 && world
.getForeMap(x
, y
+ 1) <= 63) ||
157 (!GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
, y
+ 1)))) {
158 world
.setForeMap(x
, y
+ 1, 60);
159 updateBlock(x
, y
+ 2);
160 } else if (GameItems
.isLava(world
.getForeMap(x
, y
+ 1))) {
161 if (world
.getForeMap(x
, y
+ 1) > 9) world
.setForeMap(x
, y
+ 1, 4);
162 else world
.setForeMap(x
, y
+ 1, 68);
163 } else if (GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision()) {
164 if (world
.getForeMap(x
+ 1, y
) == 0 ||
165 (!GameItems
.getBlock(world
.getForeMap(x
+ 1, y
)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
+ 1, y
))) ||
166 (GameItems
.isWater(world
.getForeMap(x
+ 1, y
)) && world
.getForeMap(x
+ 1, y
) > 61)) {
167 world
.setForeMap(x
+ 1, y
, 61);
168 updateBlock(x
+ 1, y
+ 1);
169 } else if (GameItems
.isLava(world
.getForeMap(x
+ 1, y
))) {
170 if (world
.getForeMap(x
+ 1, y
) > 9) world
.setForeMap(x
+ 1, y
, 4);
171 else world
.setForeMap(x
+ 1, y
, 68);
172 } else if (world
.getForeMap(x
+ 1, y
) == 61 && (world
.getForeMap(x
+ 2, y
) == 8 || world
.getForeMap(x
+ 2, y
) == 60))
173 world
.setForeMap(x
+ 1, y
, 8);
175 if (world
.getForeMap(x
- 1, y
) == 0 ||
176 (!GameItems
.getBlock(world
.getForeMap(x
- 1, y
)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
- 1, y
))) ||
177 (GameItems
.isWater(world
.getForeMap(x
- 1, y
)) && world
.getForeMap(x
- 1, y
) > 61)) {
178 world
.setForeMap(x
- 1, y
, 61);
179 updateBlock(x
- 1, y
+ 1);
180 } else if (GameItems
.isLava(world
.getForeMap(x
- 1, y
))) {
181 if (world
.getForeMap(x
- 1, y
) > 9) world
.setForeMap(x
- 1, y
, 4);
182 else world
.setForeMap(x
- 1, y
, 68);
183 } else if (world
.getForeMap(x
- 1, y
) == 61 && (world
.getForeMap(x
- 2, y
) == 8 || world
.getForeMap(x
- 2, y
) == 60))
184 world
.setForeMap(x
- 1, y
, 8);
188 if (world
.getForeMap(x
, y
) == 61) {
189 if (world
.getForeMap(x
, y
+ 1) == 0 || (world
.getForeMap(x
, y
+ 1) >= 61 && world
.getForeMap(x
, y
+ 1) <= 63) ||
190 (!GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
, y
+ 1)))) {
191 world
.setForeMap(x
, y
+ 1, 60);
192 updateBlock(x
, y
+ 2);
193 } else if (GameItems
.isLava(world
.getForeMap(x
, y
+ 1))) {
194 if (world
.getForeMap(x
, y
+ 1) > 9) world
.setForeMap(x
, y
+ 1, 4);
195 else world
.setForeMap(x
, y
+ 1, 68);
196 } else if (GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision()) {
197 if (world
.getForeMap(x
+ 1, y
) == 0 ||
198 (!GameItems
.getBlock(world
.getForeMap(x
+ 1, y
)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
+ 1, y
))) ||
199 (GameItems
.isWater(world
.getForeMap(x
+ 1, y
)) && world
.getForeMap(x
+ 1, y
) > 62)) {
200 world
.setForeMap(x
+ 1, y
, 62);
201 updateBlock(x
+ 1, y
+ 1);
202 } else if (GameItems
.isLava(world
.getForeMap(x
+ 1, y
))) {
203 if (world
.getForeMap(x
+ 1, y
) > 9) world
.setForeMap(x
+ 1, y
, 4);
204 else world
.setForeMap(x
+ 1, y
, 68);
207 if (world
.getForeMap(x
- 1, y
) == 0 ||
208 (!GameItems
.getBlock(world
.getForeMap(x
- 1, y
)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
- 1, y
))) ||
209 (GameItems
.isWater(world
.getForeMap(x
- 1, y
)) && world
.getForeMap(x
- 1, y
) > 62)) {
210 world
.setForeMap(x
- 1, y
, 62);
211 updateBlock(x
- 1, y
+ 1);
212 } else if (GameItems
.isLava(world
.getForeMap(x
- 1, y
))) {
213 if (world
.getForeMap(x
- 1, y
) > 9) world
.setForeMap(x
- 1, y
, 4);
214 else world
.setForeMap(x
- 1, y
, 68);
219 if (world
.getForeMap(x
, y
) == 62) {
220 if (world
.getForeMap(x
, y
+ 1) == 0 || (world
.getForeMap(x
, y
+ 1) >= 61 && world
.getForeMap(x
, y
+ 1) <= 63) ||
221 (!GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
, y
+ 1)))) {
222 world
.setForeMap(x
, y
+ 1, 60);
223 updateBlock(x
, y
+ 2);
224 } else if (GameItems
.isLava(world
.getForeMap(x
, y
+ 1))) {
225 if (world
.getForeMap(x
, y
+ 1) > 9) world
.setForeMap(x
, y
+ 1, 4);
226 else world
.setForeMap(x
, y
+ 1, 68);
227 } else if (GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision()) {
228 if (world
.getForeMap(x
+ 1, y
) == 0 ||
229 (!GameItems
.getBlock(world
.getForeMap(x
+ 1, y
)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
+ 1, y
)))) {
230 world
.setForeMap(x
+ 1, y
, 63);
231 updateBlock(x
+ 1, y
+ 1);
232 } else if (GameItems
.isLava(world
.getForeMap(x
+ 1, y
))) {
233 if (world
.getForeMap(x
+ 1, y
) > 9) world
.setForeMap(x
+ 1, y
, 4);
234 else world
.setForeMap(x
+ 1, y
, 68);
237 if (world
.getForeMap(x
- 1, y
) == 0 ||
238 (!GameItems
.getBlock(world
.getForeMap(x
- 1, y
)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
- 1, y
)))) {
239 world
.setForeMap(x
- 1, y
, 63);
240 updateBlock(x
- 1, y
+ 1);
241 } else if (GameItems
.isLava(world
.getForeMap(x
- 1, y
))) {
242 if (world
.getForeMap(x
- 1, y
) > 9) world
.setForeMap(x
- 1, y
, 4);
243 else world
.setForeMap(x
- 1, y
, 68);
248 if (world
.getForeMap(x
, y
) == 63) {
249 if (world
.getForeMap(x
, y
+ 1) == 0 || (world
.getForeMap(x
, y
+ 1) >= 61 && world
.getForeMap(x
, y
+ 1) <= 63) ||
250 (!GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
, y
+ 1)))) {
251 world
.setForeMap(x
, y
+ 1, 60);
252 updateBlock(x
, y
+ 2);
253 } else if (GameItems
.isLava(world
.getForeMap(x
, y
+ 1))) {
254 if (world
.getForeMap(x
, y
+ 1) > 9) world
.setForeMap(x
, y
+ 1, 4);
255 else world
.setForeMap(x
, y
+ 1, 68);
260 if (GameItems
.isLava(world
.getForeMap(x
, y
)) && world
.getForeMap(x
, y
) != 9) {
261 if (world
.getForeMap(x
, y
) == 64) {
262 if (!GameItems
.isLava(world
.getForeMap(x
, y
- 1)))
263 world
.setForeMap(x
, y
, world
.getForeMap(x
, y
) + 1);
264 } else if ((!GameItems
.isLava(world
.getForeMap(x
, y
- 1))) &&
265 (!GameItems
.isLava(world
.getForeMap(x
- 1, y
)) ||
266 (GameItems
.isLava(world
.getForeMap(x
, y
)) && world
.getForeMap(x
- 1, y
) >= world
.getForeMap(x
, y
))) &&
267 (!GameItems
.isLava(world
.getForeMap(x
+ 1, y
)) ||
268 (GameItems
.isLava(world
.getForeMap(x
, y
)) && world
.getForeMap(x
+ 1, y
) >= world
.getForeMap(x
, y
)))) {
269 world
.setForeMap(x
, y
, world
.getForeMap(x
, y
) + 1);
271 if (world
.getForeMap(x
, y
) > 67) world
.setForeMap(x
, y
, 0);
274 if (world
.getForeMap(x
, y
) == 9 || world
.getForeMap(x
, y
) == 64) {
275 if (world
.getForeMap(x
, y
+ 1) == 0 || (world
.getForeMap(x
, y
+ 1) >= 65 && world
.getForeMap(x
, y
+ 1) <= 67) ||
276 (!GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
, y
+ 1)))) {
277 world
.setForeMap(x
, y
+ 1, 64);
278 updateBlock(x
, y
+ 2);
279 } else if (GameItems
.isWater(world
.getForeMap(x
, y
+ 1))) {
280 world
.setForeMap(x
, y
+ 1, 1);
281 } else if (GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision()) {
282 if (world
.getForeMap(x
+ 1, y
) == 0 ||
283 (!GameItems
.getBlock(world
.getForeMap(x
+ 1, y
)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
+ 1, y
))) ||
284 (GameItems
.isLava(world
.getForeMap(x
+ 1, y
)) && world
.getForeMap(x
+ 1, y
) > 65)) {
285 world
.setForeMap(x
+ 1, y
, 65);
286 updateBlock(x
+ 1, y
+ 1);
287 } else if (GameItems
.isWater(world
.getForeMap(x
+ 1, y
))) {
288 world
.setForeMap(x
+ 1, y
, 1);
291 if (world
.getForeMap(x
- 1, y
) == 0 ||
292 (!GameItems
.getBlock(world
.getForeMap(x
- 1, y
)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
- 1, y
))) ||
293 (GameItems
.isLava(world
.getForeMap(x
- 1, y
)) && world
.getForeMap(x
- 1, y
) > 65)) {
294 world
.setForeMap(x
- 1, y
, 65);
295 updateBlock(x
- 1, y
+ 1);
296 } else if (GameItems
.isWater(world
.getForeMap(x
- 1, y
))) {
297 world
.setForeMap(x
- 1, y
, 1);
302 if (world
.getForeMap(x
, y
) == 65) {
303 if (world
.getForeMap(x
, y
+ 1) == 0 || (world
.getForeMap(x
, y
+ 1) >= 65 && world
.getForeMap(x
, y
+ 1) <= 67) ||
304 (!GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
, y
+ 1)))) {
305 world
.setForeMap(x
, y
+ 1, 64);
306 updateBlock(x
, y
+ 2);
307 } else if (GameItems
.isWater(world
.getForeMap(x
, y
+ 1))) {
308 world
.setForeMap(x
, y
+ 1, 1);
309 } else if (GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision()) {
310 if (world
.getForeMap(x
+ 1, y
) == 0 ||
311 (!GameItems
.getBlock(world
.getForeMap(x
+ 1, y
)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
+ 1, y
))) ||
312 (GameItems
.isLava(world
.getForeMap(x
+ 1, y
)) && world
.getForeMap(x
+ 1, y
) > 66)) {
313 world
.setForeMap(x
+ 1, y
, 66);
314 updateBlock(x
+ 1, y
+ 1);
315 } else if (GameItems
.isWater(world
.getForeMap(x
+ 1, y
))) {
316 world
.setForeMap(x
+ 1, y
, 1);
319 if (world
.getForeMap(x
- 1, y
) == 0 ||
320 (!GameItems
.getBlock(world
.getForeMap(x
- 1, y
)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
- 1, y
))) ||
321 (GameItems
.isLava(world
.getForeMap(x
- 1, y
)) && world
.getForeMap(x
- 1, y
) > 66)) {
322 world
.setForeMap(x
- 1, y
, 66);
323 updateBlock(x
- 1, y
+ 1);
324 } else if (GameItems
.isWater(world
.getForeMap(x
- 1, y
))) {
325 world
.setForeMap(x
- 1, y
, 1);
330 if (world
.getForeMap(x
, y
) == 66) {
331 if (world
.getForeMap(x
, y
+ 1) == 0 || (world
.getForeMap(x
, y
+ 1) >= 65 && world
.getForeMap(x
, y
+ 1) <= 67) ||
332 (!GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
, y
+ 1)))) {
333 world
.setForeMap(x
, y
+ 1, 64);
334 updateBlock(x
, y
+ 2);
335 } else if (GameItems
.isWater(world
.getForeMap(x
, y
+ 1))) {
336 world
.setForeMap(x
, y
+ 1, 1);
337 } else if (GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision()) {
338 if (world
.getForeMap(x
+ 1, y
) == 0 ||
339 (!GameItems
.getBlock(world
.getForeMap(x
+ 1, y
)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
+ 1, y
)))) {
340 world
.setForeMap(x
+ 1, y
, 67);
341 updateBlock(x
+ 1, y
+ 1);
342 } else if (GameItems
.isWater(world
.getForeMap(x
+ 1, y
))) {
343 world
.setForeMap(x
+ 1, y
, 1);
346 if (world
.getForeMap(x
- 1, y
) == 0 ||
347 (!GameItems
.getBlock(world
.getForeMap(x
- 1, y
)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
- 1, y
)))) {
348 world
.setForeMap(x
- 1, y
, 67);
349 updateBlock(x
- 1, y
+ 1);
350 } else if (GameItems
.isWater(world
.getForeMap(x
- 1, y
))) {
351 world
.setForeMap(x
- 1, y
, 1);
356 if (world
.getForeMap(x
, y
) == 67) {
357 if (world
.getForeMap(x
, y
+ 1) == 0 || (world
.getForeMap(x
, y
+ 1) >= 65 && world
.getForeMap(x
, y
+ 1) <= 67) ||
358 (!GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision() && !GameItems
.isFluid(world
.getForeMap(x
, y
+ 1)))) {
359 world
.setForeMap(x
, y
+ 1, 64);
360 updateBlock(x
, y
+ 2);
361 } else if (GameItems
.isWater(world
.getForeMap(x
, y
+ 1))) {
362 world
.setForeMap(x
, y
+ 1, 1);
367 private void updateBlock(int x
, int y
) {
368 if (world
.getForeMap(x
, y
) == 10) {
369 if (world
.getForeMap(x
, y
+ 1) == 0 || !GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision()) {
370 world
.setForeMap(x
, y
, 0);
371 mobs
.add(new FallingSand(x
* 16, y
* 16));
372 updateBlock(x
, y
- 1);
376 if (world
.getForeMap(x
, y
) == 11) {
377 if (world
.getForeMap(x
, y
+ 1) == 0 || !GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision()) {
378 world
.setForeMap(x
, y
, 0);
379 mobs
.add(new FallingGravel(x
* 16, y
* 16));
380 updateBlock(x
, y
- 1);
384 if (world
.getForeMap(x
, y
) > 0 && GameItems
.getBlock(world
.getForeMap(x
, y
)).requiresBlock()) {
385 if (world
.getForeMap(x
, y
+ 1) == 0 || !GameItems
.getBlock(world
.getForeMap(x
, y
+ 1)).hasCollision()) {
386 world
.destroyForeMap(x
, y
);
387 updateBlock(x
, y
- 1);
391 if (world
.getForeMap(x
, y
) == 2) {
392 if (world
.getForeMap(x
, y
- 1) > 0 && (GameItems
.getBlock(world
.getForeMap(x
, y
- 1)).hasCollision() ||
393 GameItems
.isFluid(world
.getForeMap(x
, y
- 1)))) {
394 world
.setForeMap(x
, y
, 3);
399 private void fluidUpdater() {
400 int midScreen
= (int) (renderer
.getCamX() + renderer
.getWidth() / 2) / 16;
401 for (int y
= 0; y
< world
.getHeight(); y
++) {
402 for (int x
= 0; x
< (int) (renderer
.getWidth() / 2) / 16 + 1; x
++) {
403 updateFluids(midScreen
+ x
, y
);
404 updateFluids(midScreen
- x
, y
);
409 void useItem(int x
, int y
, int id
, boolean bg
) {
411 if (GameItems
.getItem(id
).isBlock()) {
412 if (!bg
) world
.placeToForeground(x
, y
, GameItems
.getBlockIdByItemId(id
));
413 else world
.placeToBackground(x
, y
, GameItems
.getBlockIdByItemId(id
));
417 world
.placeToForeground(x
, y
, 8);
418 player
.inv
[player
.invSlot
] = 64;
421 world
.placeToForeground(x
, y
, 9);
422 player
.inv
[player
.invSlot
] = 64;
429 public void update(float delta
) {
431 for (int y
= UPD_Y
; y
< UPD_Y
+ 16; y
++)
432 for (int x
= UPD_X
; x
< UPD_X
+ 16; x
++) {
438 physics
.update(delta
);
442 if (isTouchDown
&& touchDownBtn
== Input
.Buttons
.LEFT
) {
443 if ((world
.getForeMap(curX
, curY
) > 0 && GameItems
.getBlock(world
.getForeMap(curX
, curY
)).getHp() >= 0) ||
444 (world
.getForeMap(curX
, curY
) == 0 &&
445 world
.getBackMap(curX
, curY
) > 0 &&
446 GameItems
.getBlock(world
.getBackMap(curX
, curY
)).getHp() >= 0)) {
447 if (player
.gameMode
== 0) {
449 if (world
.getForeMap(curX
, curY
) > 0) {
450 if (blockDmg
>= GameItems
.getBlock(world
.getForeMap(curX
, curY
)).getHp()) {
451 world
.destroyForeMap(curX
, curY
);
454 } else if (world
.getBackMap(curX
, curY
) > 0) {
455 if (blockDmg
>= GameItems
.getBlock(world
.getBackMap(curX
, curY
)).getHp()) {
456 world
.destroyBackMap(curX
, curY
);
461 if (world
.getForeMap(curX
, curY
) > 0) world
.placeToForeground(curX
, curY
, 0);
462 else if (world
.getBackMap(curX
, curY
) > 0) world
.placeToBackground(curX
, curY
, 0);
468 if (isTouchDown
&& TimeUtils
.timeSinceMillis(touchDownTime
) > 500) {
469 if (touchDownBtn
== Input
.Buttons
.RIGHT
) {
470 useItem(curX
, curY
, player
.inv
[player
.invSlot
], true);
472 } else if (touchDownY
< Assets
.invBar
.getRegionHeight() &&
473 touchDownX
> renderer
.getWidth() / 2 - (float) Assets
.invBar
.getRegionWidth() / 2 &&
474 touchDownX
< renderer
.getWidth() / 2 + (float) Assets
.invBar
.getRegionWidth() / 2) {
475 CaveGame
.STATE
= AppState
.GAME_CREATIVE_INV
;
480 if (fluidThread
== null || !fluidThread
.isAlive()) {
487 public void dispose() {
488 fluidThread
.interrupt();