X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fgame%2FGameWorld.java;h=0c4435045898d292016c756237a3adb758471ecd;hb=ef32f2e88b9c0daa411d0c304ce62b1235541fb1;hp=89c458523c1a0c53df3f1f3cdf97138c5dbcc3b5;hpb=4eb1f6f24fb76c0336394b85393e801fd0b99da4;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java b/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java index 89c4585..0c44350 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java @@ -1,15 +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; + 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(@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; @@ -27,11 +46,11 @@ public class GameWorld { return HEIGHT * 16f; } - public int[][] getFullForeMap() { + int[][] getFullForeMap() { return foreMap; } - public int[][] getFullBackMap() { + int[][] getFullBackMap() { return backMap; } @@ -60,10 +79,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 +135,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 +166,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