DEADSOFTWARE

faf0322ed38491d995f717417069d4f46a291722
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / GameWorld.java
1 package ru.deadsoftware.cavecraft.game;
3 import com.badlogic.gdx.Gdx;
5 public class GameWorld {
7 private final int WIDTH, HEIGHT;
8 private int[][] foreMap;
9 private int[][] backMap;
11 public GameWorld(int w, int h) {
12 WIDTH = w;
13 HEIGHT = h;
14 WorldGen.genWorld(WIDTH,HEIGHT);
15 foreMap = WorldGen.getForeMap();
16 backMap = WorldGen.getBackMap();
17 WorldGen.clear();
18 }
20 public int getWidth() {
21 return WIDTH;
22 }
24 public int getHeight() {
25 return HEIGHT;
26 }
28 public int getForeMap(int x, int y) {
29 int ret = 0;
30 try {
31 ret = foreMap[x][y];
32 } catch (ArrayIndexOutOfBoundsException e) {
33 Gdx.app.error("GameWorld",e.toString());
34 }
35 return ret;
36 }
38 public void setForeMap(int x, int y, int value) {
39 try {
40 foreMap[x][y] = value;
41 } catch (ArrayIndexOutOfBoundsException e) {
42 Gdx.app.error("GameWorld", e.toString());
43 }
44 }
46 public int getBackMap(int x, int y) {
47 int ret = 0;
48 try {
49 ret = backMap[x][y];
50 } catch (ArrayIndexOutOfBoundsException e) {
51 Gdx.app.error("GameWorld",e.toString());
52 }
53 return ret;
54 }
56 public void setBackMap(int x, int y, int value) {
57 try {
58 backMap[x][y] = value;
59 } catch (ArrayIndexOutOfBoundsException e) {
60 Gdx.app.error("GameWorld", e.toString());
61 }
62 }
64 public void placeToForeground(int x, int y, int value) {
65 if (getForeMap(x,y) == 0 || value == 0) setForeMap(x,y,value);
66 }
68 public void placeToBackground(int x, int y, int value) {
69 if (getBackMap(x,y) == 0 || value == 0) setBackMap(x,y,value);
70 }
72 }