DEADSOFTWARE

7e676f82f8bbafd59df33cb4346b9abb05cc6ce9
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / WorldGen.java
1 package ru.deadsoftware.cavecraft.game;
3 import com.badlogic.gdx.math.RandomXS128;
4 import com.badlogic.gdx.utils.TimeUtils;
6 public class WorldGen {
8 private static RandomXS128 rand;
9 private static long seed;
11 private static int[][] foreMap, backMap;
12 private static int[] hMap;
14 public static long getSeed() {
15 return seed;
16 }
18 static int[] genLandscape(int width, int mid, int min, int max) {
19 int[] res = new int[width];
20 int t;
21 res[0] = mid;
22 for (int i=1; i<width; i++) {
23 t = rand.nextInt(3)-1;
24 res[i] = res[i-1] + t;
25 if (res[i]<min) res[i] = min;
26 if (res[i]>max) res[i] = max;
27 }
28 return res;
29 }
31 static void genWorld(int width, int height) {
32 genWorld(width, height, TimeUtils.millis());
33 }
35 static void genWorld(int width, int height, long s) {
36 int dirtH;
37 seed = s;
38 rand = new RandomXS128(seed);
39 foreMap = new int[width][height];
40 backMap = new int[width][height];
41 hMap = genLandscape(width, height/2, height/4, height/4*3);
42 for (int x=0; x<width; x++) {
43 dirtH = 4+rand.nextInt(2);
44 for (int y = height- hMap[x]; y<height; y++) {
45 if (y==height- hMap[x]) {
46 foreMap[x][y] = 2;
47 backMap[x][y] = 2;
48 } else if (y<height-hMap[x]+dirtH) {
49 foreMap[x][y] = 3;
50 backMap[x][y] = 3;
51 } else if (y<height-1){
52 foreMap[x][y] = 1;
53 backMap[x][y] = 1;
54 } else {
55 foreMap[x][y] = 7;
56 backMap[x][y] = 7;
57 }
58 }
59 }
60 }
62 static int[][] getForeMap() {
63 return foreMap;
64 }
66 static int[][] getBackMap() {
67 return backMap;
68 }
70 static void clear() {
71 foreMap = null;
72 backMap = null;
73 }
74 }