1 package ru
.deadsoftware
.cavecraft
.game
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.math
.Vector2
;
5 import ru
.deadsoftware
.cavecraft
.Items
;
7 public class GameWorld
{
9 private final int WIDTH
, HEIGHT
;
10 private int[][] foreMap
;
11 private int[][] backMap
;
13 public GameWorld(int w
, int h
) {
16 WorldGen
.genWorld(WIDTH
,HEIGHT
);
17 foreMap
= WorldGen
.getForeMap();
18 backMap
= WorldGen
.getBackMap();
22 public int getWidth() {
26 public int getHeight() {
30 public int getForeMap(int x
, int y
) {
34 } catch (ArrayIndexOutOfBoundsException e
) {
35 Gdx
.app
.error("GameWorld",e
.toString());
40 public void setForeMap(int x
, int y
, int value
) {
42 foreMap
[x
][y
] = value
;
43 } catch (ArrayIndexOutOfBoundsException e
) {
44 Gdx
.app
.error("GameWorld", e
.toString());
48 public int getBackMap(int x
, int y
) {
52 } catch (ArrayIndexOutOfBoundsException e
) {
53 Gdx
.app
.error("GameWorld",e
.toString());
58 public void setBackMap(int x
, int y
, int value
) {
60 backMap
[x
][y
] = value
;
61 } catch (ArrayIndexOutOfBoundsException e
) {
62 Gdx
.app
.error("GameWorld", e
.toString());
66 public void placeToForeground(int x
, int y
, int value
) {
67 if (getForeMap(x
,y
) == 0 || value
== 0) setForeMap(x
,y
,value
);
70 public void placeToBackground(int x
, int y
, int value
) {
71 if (value
==0 || (getBackMap(x
,y
) == 0 && !Items
.BLOCKS
.getValueAt(value
).foreground
))
72 setBackMap(x
,y
,value
);
75 public Vector2
getSpawnPoint() {
77 boolean found
= false;
80 for (int i
= 0; i
< getHeight(); i
++) {
81 if (getForeMap((int)x
, i
)>0 &&
82 Items
.BLOCKS
.getValueAt(getForeMap((int)x
, i
)).collision
) {
92 return new Vector2(x
,y
);