diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java b/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java
index e9539e207b8d5701c307fc7623a1117ef06c061d..c5e7d46ecd99eb7b33f9b07eb0c762d6fdda914b 100644 (file)
import static ru.deadsoftware.cavedroid.GameScreen.GP;
import static ru.deadsoftware.cavedroid.GameScreen.GP;
+@SuppressWarnings("WeakerAccess")
public class GameWorld {
public class GameWorld {
- private int WIDTH, HEIGHT;
- private int[][] foreMap;
- private int[][] backMap;
+ private final int WIDTH;
+ private final int HEIGHT;
+ private final int[][] foreMap;
+ private final int[][] backMap;
+
+ GameWorld(int width, int height) {
+ WIDTH = width;
+ HEIGHT = height;
+ WorldGen.genWorld(WIDTH, HEIGHT);
+ foreMap = WorldGen.getForeMap();
+ backMap = WorldGen.getBackMap();
+ WorldGen.clear();
+ }
+
+ GameWorld(int[][] foreMap, int[][] backMap) {
+ this.foreMap = foreMap.clone();
+ this.backMap = backMap.clone();
+ WIDTH = foreMap.length;
+ HEIGHT = foreMap[0].length;
+ }
public int getWidth() {
return WIDTH;
public int getWidth() {
return WIDTH;
private int transformX(int x) {
x = x % getWidth();
private int transformX(int x) {
x = x % getWidth();
- if (x < 0) x = getWidth() - Math.abs(x);
+ if (x < 0) {
+ x = getWidth() - Math.abs(x);
+ }
return x;
}
return x;
}
private void setMap(int x, int y, int layer, int value) {
try {
x = transformX(x);
private void setMap(int x, int y, int layer, int value) {
try {
x = transformX(x);
- if (layer == 0) foreMap[x][y] = value;
- else backMap[x][y] = value;
+ if (layer == 0) {
+ foreMap[x][y] = value;
+ } else {
+ backMap[x][y] = value;
+ }
} catch (ArrayIndexOutOfBoundsException ignored) {
}
}
} catch (ArrayIndexOutOfBoundsException ignored) {
}
}
- public boolean hasBlockAt(int x, int y) {
+ public boolean hasForeAt(int x, int y) {
return getMap(x, y, 0) != 0;
}
return getMap(x, y, 0) != 0;
}
+ public boolean hasBackAt(int x, int y) {
+ return getMap(x, y, 1) != 0;
+ }
+
public int getForeMap(int x, int y) {
return getMap(x, y, 0);
}
public int getForeMap(int x, int y) {
return getMap(x, y, 0);
}
}
public void placeToForeground(int x, int y, int value) {
}
public void placeToForeground(int x, int y, int value) {
- if (!hasBlockAt(x, y) || value == 0 || !GameItems.getBlock(getForeMap(x, y)).hasCollision()) {
+ if (!hasForeAt(x, y) || value == 0 || !GameItems.getBlock(getForeMap(x, y)).hasCollision()) {
setForeMap(x, y, value);
} else if (GameItems.isSlab(value) && getForeMap(x, y) == value) {
placeSlab(x, y, value);
setForeMap(x, y, value);
} else if (GameItems.isSlab(value) && getForeMap(x, y) == value) {
placeSlab(x, y, value);
}
public void destroyForeMap(int x, int y) {
}
public void destroyForeMap(int x, int y) {
- if (GameItems.getBlock(getForeMap(x, y)).hasDrop())
+ if (GameItems.getBlock(getForeMap(x, y)).hasDrop()) {
GP.drops.add(new Drop(transformX(x) * 16 + 4, y * 16 + 4,
GameItems.getItemId(GameItems.getBlock(getForeMap(x, y)).getDrop())));
GP.drops.add(new Drop(transformX(x) * 16 + 4, y * 16 + 4,
GameItems.getItemId(GameItems.getBlock(getForeMap(x, y)).getDrop())));
+ }
placeToForeground(x, y, 0);
}
public void destroyBackMap(int x, int y) {
placeToForeground(x, y, 0);
}
public void destroyBackMap(int x, int y) {
- if (GameItems.getBlock(getBackMap(x, y)).hasDrop())
+ if (GameItems.getBlock(getBackMap(x, y)).hasDrop()) {
GP.drops.add(new Drop(transformX(x) * 16 + 4, y * 16 + 4,
GameItems.getItemId(GameItems.getBlock(getBackMap(x, y)).getDrop())));
GP.drops.add(new Drop(transformX(x) * 16 + 4, y * 16 + 4,
GameItems.getItemId(GameItems.getBlock(getBackMap(x, y)).getDrop())));
+ }
placeToBackground(x, y, 0);
}
placeToBackground(x, y, 0);
}
- public void generate(int w, int h) {
- WIDTH = w;
- HEIGHT = h;
- WorldGen.genWorld(WIDTH, HEIGHT);
- foreMap = WorldGen.getForeMap();
- backMap = WorldGen.getBackMap();
- WorldGen.clear();
- }
-
- void setMaps(int[][] foreMap, int[][] backMap) {
- this.foreMap = foreMap.clone();
- this.backMap = backMap.clone();
- WIDTH = foreMap.length;
- HEIGHT = foreMap[0].length;
- }
-
}
\ No newline at end of file
}
\ No newline at end of file