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 getForeMap(int x
, int y
) {
27 x
= getWidth()- Math
.abs(x
);
32 } catch (ArrayIndexOutOfBoundsException e
) {
33 Gdx
.app
.error("GameWorld",e
.toString());
38 public void setForeMap(int x
, int y
, int value
) {
42 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
) {
57 x
= getWidth()- Math
.abs(x
);
62 } catch (ArrayIndexOutOfBoundsException e
) {
63 Gdx
.app
.error("GameWorld",e
.toString());
68 public void setBackMap(int x
, int y
, int value
) {
72 x
= getWidth()- Math
.abs(x
);
76 backMap
[x
][y
] = value
;
77 } catch (ArrayIndexOutOfBoundsException e
) {
78 Gdx
.app
.error("GameWorld", e
.toString());
82 public void placeToForeground(int x
, int y
, int value
) {
83 if (getForeMap(x
,y
) == 0 || value
== 0) {
84 setForeMap(x
,y
,value
);
88 public void placeToBackground(int x
, int y
, int value
) {
89 if (value
==0 || (getBackMap(x
,y
) == 0 && !Items
.BLOCKS
.getValueAt(value
).foreground
)) {
90 setBackMap(x
,y
,value
);
94 public Vector2
getSpawnPoint(int x
) {
98 if (getForeMap(x
,y
)>0 && Items
.BLOCKS
.getValueAt(getForeMap(x
,y
)).collision
) break;
102 return new Vector2(x
,y
);
105 public void generate(int w
, int h
) {
108 WorldGen
.genWorld(WIDTH
,HEIGHT
);
109 foreMap
= WorldGen
.getForeMap();
110 backMap
= WorldGen
.getBackMap();
116 WorldSaver
.save(foreMap
, backMap
);
121 foreMap
= WorldSaver
.getLoadedForeMap();
122 backMap
= WorldSaver
.getLoadedBackMap();
123 WIDTH
= foreMap
.length
;
124 HEIGHT
= foreMap
[0].length
;