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
;
11 private int[][] foreMap
;
12 private int[][] backMap
;
14 public GameWorld(int w
, int h
) {
17 WorldGen
.genWorld(WIDTH
,HEIGHT
);
18 foreMap
= WorldGen
.getForeMap();
19 backMap
= WorldGen
.getBackMap();
23 public int getWidth() {
27 public int getHeight() {
31 public int getForeMap(int x
, int y
) {
36 x
= getWidth()- Math
.abs(x
);
41 } catch (ArrayIndexOutOfBoundsException e
) {
42 Gdx
.app
.error("GameWorld",e
.toString());
47 public void setForeMap(int x
, int y
, int value
) {
51 x
= getWidth()- Math
.abs(x
);
55 foreMap
[x
][y
] = value
;
56 } catch (ArrayIndexOutOfBoundsException e
) {
57 Gdx
.app
.error("GameWorld", e
.toString());
61 public int getBackMap(int x
, int y
) {
66 x
= getWidth()- Math
.abs(x
);
71 } catch (ArrayIndexOutOfBoundsException e
) {
72 Gdx
.app
.error("GameWorld",e
.toString());
77 public void setBackMap(int x
, int y
, int value
) {
81 x
= getWidth()- Math
.abs(x
);
85 backMap
[x
][y
] = value
;
86 } catch (ArrayIndexOutOfBoundsException e
) {
87 Gdx
.app
.error("GameWorld", e
.toString());
91 public void placeToForeground(int x
, int y
, int value
) {
92 if (getForeMap(x
,y
) == 0 || value
== 0) {
93 setForeMap(x
,y
,value
);
97 public void placeToBackground(int x
, int y
, int value
) {
98 if (value
==0 || (getBackMap(x
,y
) == 0 && !Items
.BLOCKS
.getValueAt(value
).foreground
)) {
99 setBackMap(x
,y
,value
);
103 public Vector2
getSpawnPoint() {
107 return new Vector2(x
,y
);