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 || !Items
.BLOCKS
.getValueAt(getForeMap(x
, y
)).collision
) {
76 setForeMap(x
, y
, value
);
79 GameProc
.DO_UPD
= true;
83 public void placeToBackground(int x
, int y
, int value
) {
84 if (value
==0 || (getBackMap(x
,y
) == 0 && Items
.BLOCKS
.getValueAt(value
).collision
) &&
85 (!Items
.BLOCKS
.getValueAt(value
).transparent
|| value
== 18)) {
86 setBackMap(x
,y
,value
);
90 public Vector2
getSpawnPoint() {
94 if (getForeMap(x
,y
)>0 && Items
.BLOCKS
.getValueAt(getForeMap(x
,y
)).collision
) break;
98 return new Vector2(x
,y
);
101 public void generate(int w
, int h
) {
104 WorldGen
.genWorld(WIDTH
,HEIGHT
);
105 foreMap
= WorldGen
.getForeMap();
106 backMap
= WorldGen
.getBackMap();
110 public void setMaps(int[][] foreMap
, int[][] backMap
) {
111 this.foreMap
= foreMap
.clone();
112 this.backMap
= backMap
.clone();
113 WIDTH
= foreMap
.length
;
114 HEIGHT
= foreMap
[0].length
;