DEADSOFTWARE

Even better collision
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / GameWorld.java
1 package ru.deadsoftware.cavecraft.game;
3 import com.badlogic.gdx.Gdx;
4 import ru.deadsoftware.cavecraft.Items;
6 public class GameWorld {
8 private final int WIDTH, HEIGHT;
9 private int[][] foreMap;
10 private int[][] backMap;
12 public GameWorld(int w, int h) {
13 WIDTH = w;
14 HEIGHT = h;
15 WorldGen.genWorld(WIDTH,HEIGHT);
16 foreMap = WorldGen.getForeMap();
17 backMap = WorldGen.getBackMap();
18 WorldGen.clear();
19 }
21 public int getWidth() {
22 return WIDTH;
23 }
25 public int getHeight() {
26 return HEIGHT;
27 }
29 public int getForeMap(int x, int y) {
30 int ret = 0;
31 try {
32 ret = foreMap[x][y];
33 } catch (ArrayIndexOutOfBoundsException e) {
34 Gdx.app.error("GameWorld",e.toString());
35 }
36 return ret;
37 }
39 public void setForeMap(int x, int y, int value) {
40 try {
41 foreMap[x][y] = value;
42 } catch (ArrayIndexOutOfBoundsException e) {
43 Gdx.app.error("GameWorld", e.toString());
44 }
45 }
47 public int getBackMap(int x, int y) {
48 int ret = 0;
49 try {
50 ret = backMap[x][y];
51 } catch (ArrayIndexOutOfBoundsException e) {
52 Gdx.app.error("GameWorld",e.toString());
53 }
54 return ret;
55 }
57 public void setBackMap(int x, int y, int value) {
58 try {
59 backMap[x][y] = value;
60 } catch (ArrayIndexOutOfBoundsException e) {
61 Gdx.app.error("GameWorld", e.toString());
62 }
63 }
65 public void placeToForeground(int x, int y, int value) {
66 if (getForeMap(x,y) == 0 || value == 0) setForeMap(x,y,value);
67 }
69 public void placeToBackground(int x, int y, int value) {
70 if ((getBackMap(x,y) == 0 || value == 0) &&
71 !Items.BLOCKS.getValueAt(value).foreground) setBackMap(x,y,value);
72 }
74 }