DEADSOFTWARE

More convenient controls on desktop
[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.ArrayMap;
6 import com.badlogic.gdx.utils.TimeUtils;
8 public class WorldGen {
10 private static RandomXS128 rand;
11 private static long seed;
13 private static int[][] foreMap, backMap;
14 private static int[] hMap;
16 public static long getSeed() {
17 return seed;
18 }
20 static int[] genLandscape(int width, int mid, int min, int max) {
21 int[] res = new int[width];
22 int t;
23 res[0] = mid;
24 for (int i=1; i<width; i++) {
25 t = rand.nextInt(3)-1;
26 res[i] = res[i-1] + t;
27 if (res[i]<min) res[i] = min;
28 if (res[i]>max) res[i] = max;
29 }
30 return res;
31 }
33 private static void genOak(int x, int y) {
34 backMap[x][y] = 15;
35 backMap[x][y-1] = 15;
36 backMap[x][y-2] = 15;
37 backMap[x][y-3] = 15;
38 backMap[x][y-4] = 16;
39 backMap[x][y-5] = 16;
40 backMap[x-1][y-3] = 16;
41 backMap[x-1][y-4] = 16;
42 backMap[x+1][y-3] = 16;
43 backMap[x+1][y-4] = 16;
44 foreMap[x][y-3] = 16;
45 foreMap[x][y-4] = 16;
46 foreMap[x][y-5] = 16;
47 foreMap[x-1][y-3] = 16;
48 foreMap[x-1][y-4] = 16;
49 foreMap[x+1][y-3] = 16;
50 foreMap[x+1][y-4] = 16;
51 }
53 static void genWorld(int width, int height) {
54 genWorld(width, height, TimeUtils.millis());
55 }
57 static void genWorld(int width, int height, long s) {
58 int dirtH;
59 seed = s;
60 rand = new RandomXS128(seed);
61 foreMap = new int[width][height];
62 backMap = new int[width][height];
63 hMap = genLandscape(width, height/4, height/8, height/2);
64 for (int x=0; x<width; x++) {
65 for (int y=0; y<height; y++) {
66 }
67 dirtH = 4+rand.nextInt(2);
68 for (int y = height- hMap[x]; y<height; y++) {
69 if (y==height- hMap[x]) {
70 foreMap[x][y] = 2;
71 backMap[x][y] = 2;
72 } else if (y<height-hMap[x]+dirtH) {
73 foreMap[x][y] = 3;
74 backMap[x][y] = 3;
75 } else if (y<height-1){
76 foreMap[x][y] = 1;
77 backMap[x][y] = 1;
78 } else {
79 foreMap[x][y] = 7;
80 backMap[x][y] = 7;
81 }
82 }
83 for (int y = height-64; y<height-1; y++) {
84 if (foreMap[x][height-y]==0){
85 foreMap[x][height-y] = 8;
86 backMap[x][height-y] = 8;
87 }
88 }
89 if (x>2 && x<width-2 && rand.nextInt(100)<5){
90 genOak(x,height-hMap[x]-1);
91 }
92 }
93 }
95 static int[][] getForeMap() {
96 return foreMap;
97 }
99 static int[][] getBackMap() {
100 return backMap;
103 static void clear() {
104 foreMap = null;
105 backMap = null;