DEADSOFTWARE

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