1 package ru
.deadsoftware
.cavecraft
.game
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.math
.Vector2
;
6 public class GameWorld
{
8 private int WIDTH
, HEIGHT
;
9 private int[][] foreMap
;
10 private int[][] backMap
;
12 public int getWidth() {
16 public int getHeight() {
20 public int[][] getFullForeMap() {
24 public int[][] getFullBackMap() {
28 private int transformX(int x
) {
30 if (x
<0) x
=getWidth()-Math
.abs(x
);
34 public int getForeMap(int x
, int y
) {
39 } catch (ArrayIndexOutOfBoundsException e
) {
40 Gdx
.app
.error("GameWorld",e
.toString());
45 public void setForeMap(int x
, int y
, int value
) {
48 foreMap
[x
][y
] = value
;
49 } catch (ArrayIndexOutOfBoundsException e
) {
50 Gdx
.app
.error("GameWorld", e
.toString());
54 public int getBackMap(int x
, int y
) {
59 } catch (ArrayIndexOutOfBoundsException e
) {
60 Gdx
.app
.error("GameWorld",e
.toString());
65 public void setBackMap(int x
, int y
, int value
) {
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
).collision
)) {
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
;