DEADSOFTWARE

9f6e693886a11db7386bebeb2b9a3f7f4ced59dc
[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 int[][] foreMap, backMap;
9 private static int[] hMap;
11 static int[] genLandscape(int width, int mid, int min, int max) {
12 RandomXS128 rand = new RandomXS128(TimeUtils.millis());
13 int[] res = new int[width];
14 int t;
15 res[0] = mid;
16 for (int i=1; i<width; i++) {
17 t = rand.nextInt(3)-1;
18 res[i] = res[i-1] + t;
19 if (res[i]<min) res[i] = min;
20 if (res[i]>max) res[i] = max;
21 }
22 return res;
23 }
25 static void genWorld(int width, int height) {
26 foreMap = new int[width][height];
27 backMap = new int[width][height];
28 hMap = genLandscape(width, height/2, height/4, height/4*3);
29 for (int x=0; x<width; x++) {
30 for (int y = height- hMap[x]; y<height; y++) {
31 if (y==height- hMap[x]) {
32 foreMap[x][y] = 3;
33 backMap[x][y] = 3;
34 } else if (y<height- hMap[x]+4) {
35 foreMap[x][y] = 2;
36 backMap[x][y] = 2;
37 } else {
38 foreMap[x][y] = 1;
39 backMap[x][y] = 1;
40 }
41 }
42 }
43 }
45 static int[][] getForeMap() {
46 return foreMap;
47 }
49 static int[][] getBackMap() {
50 return backMap;
51 }
53 static void clear() {
54 foreMap = null;
55 backMap = null;
56 }
57 }