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
;
10 private int[][] foreMap
;
11 private int[][] backMap
;
13 public int getWidth() {
17 public int getHeight() {
21 public int[][] getFullForeMap() {
25 public int[][] getFullBackMap() {
29 public int getForeMap(int x
, int y
) {
33 if (x
<0) x
=getWidth()-Math
.abs(x
);
35 } catch (ArrayIndexOutOfBoundsException e
) {
36 Gdx
.app
.error("GameWorld",e
.toString());
41 public void setForeMap(int x
, int y
, int value
) {
44 if (x
<0) x
=getWidth()-Math
.abs(x
);
45 foreMap
[x
][y
] = value
;
46 } catch (ArrayIndexOutOfBoundsException e
) {
47 Gdx
.app
.error("GameWorld", e
.toString());
51 public int getBackMap(int x
, int y
) {
55 if (x
<0) x
=getWidth()-Math
.abs(x
);
57 } catch (ArrayIndexOutOfBoundsException e
) {
58 Gdx
.app
.error("GameWorld",e
.toString());
63 public void setBackMap(int x
, int y
, int value
) {
66 if (x
<0) x
=getWidth()-Math
.abs(x
);
67 backMap
[x
][y
] = value
;
68 } catch (ArrayIndexOutOfBoundsException e
) {
69 Gdx
.app
.error("GameWorld", e
.toString());
73 public void placeToForeground(int x
, int y
, int value
) {
74 if (getForeMap(x
,y
) == 0 || value
== 0) {
75 setForeMap(x
,y
,value
);
79 public void placeToBackground(int x
, int y
, int value
) {
80 if (value
==0 || (getBackMap(x
,y
) == 0 && !Items
.BLOCKS
.getValueAt(value
).foreground
)) {
81 setBackMap(x
,y
,value
);
85 public Vector2
getSpawnPoint() {
89 if (getForeMap(x
,y
)>0 && Items
.BLOCKS
.getValueAt(getForeMap(x
,y
)).collision
) break;
93 return new Vector2(x
,y
);
96 public void generate(int w
, int h
) {
99 WorldGen
.genWorld(WIDTH
,HEIGHT
);
100 foreMap
= WorldGen
.getForeMap();
101 backMap
= WorldGen
.getBackMap();
105 public void setMaps(int[][] foreMap
, int[][] backMap
) {
106 this.foreMap
= foreMap
.clone();
107 this.backMap
= backMap
.clone();
108 WIDTH
= foreMap
.length
;
109 HEIGHT
= foreMap
[0].length
;