X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fgame%2FGameWorld.java;h=e921b98138ceaabcab6db3d9dff559e4aa9113a0;hb=cab1b788df7221370108854b08e747e8e4382968;hp=e9539e207b8d5701c307fc7623a1117ef06c061d;hpb=f5375688faf7e80a0cd145d69bdb335fe2450267;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java b/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java index e9539e2..e921b98 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java @@ -1,16 +1,34 @@ package ru.deadsoftware.cavedroid.game; +import org.jetbrains.annotations.NotNull; import ru.deadsoftware.cavedroid.game.objects.Block; import ru.deadsoftware.cavedroid.game.objects.Drop; import static ru.deadsoftware.cavedroid.GameScreen.GP; +@SuppressWarnings("WeakerAccess") public class GameWorld { private int WIDTH, HEIGHT; private int[][] foreMap; private int[][] backMap; + GameWorld(int width, int height) { + WIDTH = width; + HEIGHT = height; + WorldGen.genWorld(WIDTH, HEIGHT); + foreMap = WorldGen.getForeMap(); + backMap = WorldGen.getBackMap(); + WorldGen.clear(); + } + + GameWorld(@NotNull int[][] foreMap, @NotNull int[][] backMap) { + this.foreMap = foreMap.clone(); + this.backMap = backMap.clone(); + WIDTH = foreMap.length; + HEIGHT = foreMap[0].length; + } + public int getWidth() { return WIDTH; } @@ -60,10 +78,14 @@ public class GameWorld { } } - public boolean hasBlockAt(int x, int y) { + public boolean hasForeAt(int x, int y) { 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); } @@ -112,7 +134,7 @@ public class GameWorld { } 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); @@ -143,20 +165,4 @@ public class GameWorld { 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