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
.CaveGame
;
7 import ru
.deadsoftware
.cavecraft
.GameState
;
8 import ru
.deadsoftware
.cavecraft
.Items
;
10 public class GameWorld
{
12 private final int WIDTH
, HEIGHT
;
14 private int[][] foreMap
;
15 private int[][] backMap
;
17 public GameWorld(int w
, int h
) {
20 WorldGen
.genWorld(WIDTH
,HEIGHT
);
21 foreMap
= WorldGen
.getForeMap();
22 backMap
= WorldGen
.getBackMap();
26 public int getWidth() {
30 public int getHeight() {
34 public int getForeMap(int x
, int y
) {
38 } catch (ArrayIndexOutOfBoundsException e
) {
39 Gdx
.app
.error("GameWorld",e
.toString());
44 public void setForeMap(int x
, int y
, int value
) {
46 foreMap
[x
][y
] = value
;
47 } catch (ArrayIndexOutOfBoundsException e
) {
48 Gdx
.app
.error("GameWorld", e
.toString());
52 public int getBackMap(int x
, int y
) {
56 } catch (ArrayIndexOutOfBoundsException e
) {
57 Gdx
.app
.error("GameWorld",e
.toString());
62 public void setBackMap(int x
, int y
, int value
) {
64 backMap
[x
][y
] = value
;
65 } catch (ArrayIndexOutOfBoundsException e
) {
66 Gdx
.app
.error("GameWorld", e
.toString());
70 public void placeToForeground(int x
, int y
, int value
) {
71 if (getForeMap(x
,y
) == 0 || value
== 0) {
72 setForeMap(x
,y
,value
);
76 public void placeToBackground(int x
, int y
, int value
) {
77 if (value
==0 || (getBackMap(x
,y
) == 0 && !Items
.BLOCKS
.getValueAt(value
).foreground
)) {
78 setBackMap(x
,y
,value
);
82 public Vector2
getSpawnPoint() {
84 boolean found
= false;
87 for (int i
= 0; i
< getHeight(); i
++) {
88 if (getForeMap((int)x
, i
)>0 &&
89 Items
.BLOCKS
.getValueAt(getForeMap((int)x
, i
)).collision
&&
90 getForeMap((int)x
, i
-1)==0 && getForeMap((int)x
, i
-1)==0) {
98 if (x
<0) x
=getWidth()-1;
99 if ((int)x
== getWidth()/2+1) {
108 return new Vector2(x
,y
);