1 package ru
.deadsoftware
.cavecraft
.game
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.math
.Vector2
;
5 import com
.badlogic
.gdx
.utils
.ArrayMap
;
6 import ru
.deadsoftware
.cavecraft
.Items
;
8 public class GameWorld
{
10 private final int WIDTH
, HEIGHT
;
12 private int[][] foreMap
;
13 private int[][] backMap
;
15 public GameWorld(int w
, int h
) {
18 WorldGen
.genWorld(WIDTH
,HEIGHT
);
19 foreMap
= WorldGen
.getForeMap();
20 backMap
= WorldGen
.getBackMap();
24 public int getWidth() {
28 public int getHeight() {
32 public int getForeMap(int x
, int y
) {
36 } catch (ArrayIndexOutOfBoundsException e
) {
37 Gdx
.app
.error("GameWorld",e
.toString());
42 public void setForeMap(int x
, int y
, int value
) {
44 foreMap
[x
][y
] = value
;
45 } catch (ArrayIndexOutOfBoundsException e
) {
46 Gdx
.app
.error("GameWorld", e
.toString());
50 public int getBackMap(int x
, int y
) {
54 } catch (ArrayIndexOutOfBoundsException e
) {
55 Gdx
.app
.error("GameWorld",e
.toString());
60 public void setBackMap(int x
, int y
, int value
) {
62 backMap
[x
][y
] = value
;
63 } catch (ArrayIndexOutOfBoundsException e
) {
64 Gdx
.app
.error("GameWorld", e
.toString());
68 public void placeToForeground(int x
, int y
, int value
) {
69 if (getForeMap(x
,y
) == 0 || value
== 0) {
70 setForeMap(x
,y
,value
);
74 public void placeToBackground(int x
, int y
, int value
) {
75 if (value
==0 || (getBackMap(x
,y
) == 0 && !Items
.BLOCKS
.getValueAt(value
).foreground
)) {
76 setBackMap(x
,y
,value
);
80 public Vector2
getSpawnPoint() {
82 boolean found
= false;
85 for (int i
= 0; i
< getHeight(); i
++) {
86 if (getForeMap((int)x
, i
)>0 &&
87 Items
.BLOCKS
.getValueAt(getForeMap((int)x
, i
)).collision
) {
97 return new Vector2(x
,y
);