1 package ru
.deadsoftware
.cavecraft
.game
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import ru
.deadsoftware
.cavecraft
.Items
;
6 public class GameWorld
{
8 private final int WIDTH
, HEIGHT
;
9 private int[][] foreMap
;
10 private int[][] backMap
;
12 public GameWorld(int w
, int h
) {
15 WorldGen
.genWorld(WIDTH
,HEIGHT
);
16 foreMap
= WorldGen
.getForeMap();
17 backMap
= WorldGen
.getBackMap();
21 public int getWidth() {
25 public int getHeight() {
29 public int getForeMap(int x
, int y
) {
33 } catch (ArrayIndexOutOfBoundsException e
) {
34 Gdx
.app
.error("GameWorld",e
.toString());
39 public void setForeMap(int x
, int y
, int value
) {
41 foreMap
[x
][y
] = value
;
42 } catch (ArrayIndexOutOfBoundsException e
) {
43 Gdx
.app
.error("GameWorld", e
.toString());
47 public int getBackMap(int x
, int y
) {
51 } catch (ArrayIndexOutOfBoundsException e
) {
52 Gdx
.app
.error("GameWorld",e
.toString());
57 public void setBackMap(int x
, int y
, int value
) {
59 backMap
[x
][y
] = value
;
60 } catch (ArrayIndexOutOfBoundsException e
) {
61 Gdx
.app
.error("GameWorld", e
.toString());
65 public void placeToForeground(int x
, int y
, int value
) {
66 if (getForeMap(x
,y
) == 0 || value
== 0) setForeMap(x
,y
,value
);
69 public void placeToBackground(int x
, int y
, int value
) {
70 if ((getBackMap(x
,y
) == 0 || value
== 0) &&
71 !Items
.BLOCKS
.getValueAt(value
).foreground
) setBackMap(x
,y
,value
);