1 package ru
.deadsoftware
.cavecraft
.game
;
3 import com
.badlogic
.gdx
.math
.Vector2
;
4 import ru
.deadsoftware
.cavecraft
.game
.objects
.Drop
;
6 public class GameWorld
{
8 private int WIDTH
, HEIGHT
;
9 private int[][] foreMap
;
10 private int[][] backMap
;
12 public int getWidth() {
16 public int getHeight() {
20 public int[][] getFullForeMap() {
24 public int[][] getFullBackMap() {
28 private int transformX(int x
) {
30 if (x
< 0) x
= getWidth() - Math
.abs(x
);
34 public int getForeMap(int x
, int y
) {
39 } catch (ArrayIndexOutOfBoundsException e
) {
40 //Gdx.app.error("GameWorld",e.toString());
45 public void setForeMap(int x
, int y
, int value
) {
48 foreMap
[x
][y
] = value
;
49 } catch (ArrayIndexOutOfBoundsException e
) {
50 //Gdx.app.error("GameWorld", e.toString());
54 public int getBackMap(int x
, int y
) {
59 } catch (ArrayIndexOutOfBoundsException e
) {
60 //Gdx.app.error("GameWorld",e.toString());
65 public void setBackMap(int x
, int y
, int value
) {
68 backMap
[x
][y
] = value
;
69 } catch (ArrayIndexOutOfBoundsException e
) {
70 //Gdx.app.error("GameWorld", e.toString());
74 private void placeSlab(int x
, int y
, int value
) {
97 public void placeToForeground(int x
, int y
, int value
) {
98 if (getForeMap(x
, y
) == 0 || value
== 0 || !GameItems
.getBlock(getForeMap(x
, y
)).coll
) {
99 setForeMap(x
, y
, value
);
100 } else if (GameItems
.isSlab(value
) && getForeMap(x
, y
) == value
) {
101 placeSlab(x
, y
, value
);
103 GameProc
.UPD_X
= x
- 8;
104 GameProc
.UPD_Y
= y
- 8;
105 GameProc
.DO_UPD
= true;
108 public void placeToBackground(int x
, int y
, int value
) {
109 if (value
== 0 || (getBackMap(x
, y
) == 0 && GameItems
.getBlock(value
).coll
) &&
110 (!GameItems
.getBlock(value
).tp
|| value
== 18)) {
111 setBackMap(x
, y
, value
);
115 public void destroyForeMap(int x
, int y
, GameProc gp
) {
116 if (GameItems
.getBlock(getForeMap(x
, y
)).getDrop() > 0)
117 gp
.drops
.add(new Drop(transformX(x
) * 16 + 4, y
* 16 + 4, GameItems
.getBlock(getForeMap(x
, y
)).getDrop()));
118 placeToForeground(x
, y
, 0);
121 public void destroyBackMap(int x
, int y
, GameProc gp
) {
122 if (GameItems
.getBlock(getBackMap(x
, y
)).getDrop() > 0)
123 gp
.drops
.add(new Drop(transformX(x
) * 16 + 4, y
* 16 + 4, GameItems
.getBlock(getBackMap(x
, y
)).getDrop()));
124 placeToBackground(x
, y
, 0);
127 public Vector2
getSpawnPoint() {
131 if (getForeMap(x
, y
) > 0 && GameItems
.getBlock(getForeMap(x
, y
)).coll
) break;
135 return new Vector2(x
, y
);
138 public void generate(int w
, int h
) {
141 WorldGen
.genWorld(WIDTH
, HEIGHT
);
142 foreMap
= WorldGen
.getForeMap();
143 backMap
= WorldGen
.getBackMap();
147 public void setMaps(int[][] foreMap
, int[][] backMap
) {
148 this.foreMap
= foreMap
.clone();
149 this.backMap
= backMap
.clone();
150 WIDTH
= foreMap
.length
;
151 HEIGHT
= foreMap
[0].length
;