X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fgame%2FWorldGen.java;h=cc02aea03f2dff4af2151175d451cb3c751c7f23;hb=4b6a07cc0c9e649159744fc2387214a92bcc4c2f;hp=b6ab59e2f91a20b7d76837509bfd0da49c47e07e;hpb=0f2b53c7e0e2983d7d760d988dd08410e0fb97d5;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/game/WorldGen.java b/core/src/ru/deadsoftware/cavedroid/game/WorldGen.java index b6ab59e..cc02aea 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/WorldGen.java +++ b/core/src/ru/deadsoftware/cavedroid/game/WorldGen.java @@ -3,13 +3,19 @@ package ru.deadsoftware.cavedroid.game; import com.badlogic.gdx.math.RandomXS128; import com.badlogic.gdx.utils.TimeUtils; -public class WorldGen { +import javax.annotation.CheckForNull; +class WorldGen { + + @CheckForNull private static RandomXS128 rand; private static long seed; + @CheckForNull private static int[][] foreMap, backMap; + @CheckForNull private static int[] hMap; + @CheckForNull private static int[] bMap; //biomes, 0-plains, 1-desert public static long getSeed() { @@ -23,15 +29,25 @@ public class WorldGen { res[0] = mid; for (int i = 1; i < width; i++) { t = rand.nextInt(7) - 3; - if (t > -3 && t < 3) t = 0; - else t /= Math.abs(t); + if (t > -3 && t < 3) { + t = 0; + } else { + t /= Math.abs(t); + } if (i > width - (max - min)) { - if (res[i - 1] + t < res[0]) t = Math.abs(t); - else if (res[i - 1] + t > res[0]) t = -Math.abs(t); + if (res[i - 1] + t < res[0]) { + t = Math.abs(t); + } else if (res[i - 1] + t > res[0]) { + t = -Math.abs(t); + } } res[i] = res[i - 1] + t; - if (res[i] < min) res[i] = min; - if (res[i] > max) res[i] = max; + if (res[i] < min) { + res[i] = min; + } + if (res[i] > max) { + res[i] = max; + } bMap[i] = 0; // if (i >= width / 2) { // bMap[i] = 1; @@ -40,17 +56,21 @@ public class WorldGen { // bMap[i] = 0; // } } - if (res[0] < res[width - 1]) res[width - 1] = res[0]; + if (res[0] < res[width - 1]) { + res[width - 1] = res[0]; + } return res; } private static void genCactus(int x, int y) { + assert foreMap != null; foreMap[x][y] = 59; foreMap[x][y - 1] = 59; foreMap[x][y - 2] = 59; } private static void genOak(int x, int y) { + assert foreMap != null && backMap != null; backMap[x][y] = 15; backMap[x][y - 1] = 15; backMap[x][y - 2] = 15; @@ -171,16 +191,16 @@ public class WorldGen { } static int[][] getForeMap() { + assert foreMap != null; return foreMap; } static int[][] getBackMap() { + assert backMap != null; return backMap; } static void clear() { - foreMap = null; - backMap = null; hMap = null; bMap = null; }