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 int WIDTH
, HEIGHT
;
11 private int[][] foreMap
;
12 private int[][] backMap
;
14 public int getWidth() {
18 public int getHeight() {
22 public int[][] getFullForeMap() {
26 public int[][] getFullBackMap() {
30 public int getForeMap(int x
, int y
) {
34 if (x
<0) x
=getWidth()-Math
.abs(x
);
36 } catch (ArrayIndexOutOfBoundsException e
) {
37 Gdx
.app
.error("GameWorld",e
.toString());
42 public void setForeMap(int x
, int y
, int value
) {
45 if (x
<0) x
=getWidth()-Math
.abs(x
);
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 if (x
<0) x
=getWidth()-Math
.abs(x
);
58 } catch (ArrayIndexOutOfBoundsException e
) {
59 Gdx
.app
.error("GameWorld",e
.toString());
64 public void setBackMap(int x
, int y
, int value
) {
67 if (x
<0) x
=getWidth()-Math
.abs(x
);
68 backMap
[x
][y
] = value
;
69 } catch (ArrayIndexOutOfBoundsException e
) {
70 Gdx
.app
.error("GameWorld", e
.toString());
74 public void placeToForeground(int x
, int y
, int value
) {
75 if (getForeMap(x
,y
) == 0 || value
== 0) {
76 setForeMap(x
,y
,value
);
80 public void placeToBackground(int x
, int y
, int value
) {
81 if (value
==0 || (getBackMap(x
,y
) == 0 && !Items
.BLOCKS
.getValueAt(value
).foreground
)) {
82 setBackMap(x
,y
,value
);
86 public Vector2
getSpawnPoint() {
90 if (getForeMap(x
,y
)>0 && Items
.BLOCKS
.getValueAt(getForeMap(x
,y
)).collision
) break;
94 return new Vector2(x
,y
);
97 public void generate(int w
, int h
) {
100 WorldGen
.genWorld(WIDTH
,HEIGHT
);
101 foreMap
= WorldGen
.getForeMap();
102 backMap
= WorldGen
.getBackMap();
106 public void setMaps(int[][] foreMap
, int[][] backMap
) {
107 this.foreMap
= foreMap
.clone();
108 this.backMap
= backMap
.clone();
109 WIDTH
= foreMap
.length
;
110 HEIGHT
= foreMap
[0].length
;