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
;
13 private static int[] bMap
; //biomes, 0-plains, 1-desert
15 public static long getSeed() {
19 static int[] genLandscape(int width
, int mid
, int min
, int max
) {
20 int[] res
= new int[width
];
21 bMap
= new int[width
];
24 for (int i
= 1; i
< width
; i
++) {
25 t
= rand
.nextInt(7) - 3;
26 if (t
> -3 && t
< 3) t
= 0;
27 else t
/= Math
.abs(t
);
28 if (i
> width
- (max
- min
)) {
29 if (res
[i
- 1] + t
< res
[0]) t
= Math
.abs(t
);
30 else if (res
[i
- 1] + t
> res
[0]) t
= -Math
.abs(t
);
32 res
[i
] = res
[i
- 1] + t
;
33 if (res
[i
] < min
) res
[i
] = min
;
34 if (res
[i
] > max
) res
[i
] = max
;
37 if (res
[i
] < 60) res
[i
] = 60;
42 if (res
[0] < res
[width
- 1]) res
[width
- 1] = res
[0];
46 private static void genCactus(int x
, int y
) {
48 foreMap
[x
][y
- 1] = 59;
49 foreMap
[x
][y
- 2] = 59;
52 private static void genOak(int x
, int y
) {
54 backMap
[x
][y
- 1] = 15;
55 backMap
[x
][y
- 2] = 15;
56 backMap
[x
][y
- 3] = 15;
57 backMap
[x
][y
- 4] = 16;
58 backMap
[x
][y
- 5] = 16;
59 backMap
[x
- 1][y
- 3] = 16;
60 backMap
[x
- 1][y
- 4] = 16;
61 backMap
[x
+ 1][y
- 3] = 16;
62 backMap
[x
+ 1][y
- 4] = 16;
63 foreMap
[x
][y
- 3] = 16;
64 foreMap
[x
][y
- 4] = 16;
65 foreMap
[x
][y
- 5] = 16;
66 foreMap
[x
- 1][y
- 3] = 16;
67 foreMap
[x
- 1][y
- 4] = 16;
68 foreMap
[x
+ 1][y
- 3] = 16;
69 foreMap
[x
+ 1][y
- 4] = 16;
72 static void genWorld(int width
, int height
) {
73 genWorld(width
, height
, TimeUtils
.millis());
76 static void genWorld(int width
, int height
, long worldseed
) {
79 rand
= new RandomXS128(seed
);
80 foreMap
= new int[width
][height
];
81 backMap
= new int[width
][height
];
82 hMap
= genLandscape(width
, height
/ 4, height
/ 8, height
/ 2);
83 for (int x
= 0; x
< width
; x
++) {
84 dirtH
= 4 + rand
.nextInt(2);
85 for (int y
= height
- hMap
[x
]; y
< height
; y
++) {
86 if (y
== height
- hMap
[x
]) {
97 } else if (y
< height
- hMap
[x
] + dirtH
) {
108 } else if (bMap
[x
] == 1 && y
< height
- hMap
[x
] + dirtH
+ 3) {
111 } else if (y
< height
- 1) {
119 for (int y
= height
- 60; y
< height
- 1; y
++) {
120 if (foreMap
[x
][y
] == 0 && bMap
[x
] != 1) {
123 if (y
== height
- 60) {
129 if (y
== height
- hMap
[x
] - 1) {
130 foreMap
[x
][y
+ 1] = 3;
131 backMap
[x
][y
+ 1] = 3;
135 if (x
> 2 && x
< width
- 2) {
136 if (foreMap
[x
][height
- hMap
[x
] - 1] == 0 && foreMap
[x
][height
- hMap
[x
]] == 2) {
137 switch (rand
.nextInt(50)) {
139 genOak(x
, height
- hMap
[x
] - 1);
142 foreMap
[x
][height
- hMap
[x
] - 1] = 26;
145 foreMap
[x
][height
- hMap
[x
] - 1] = 29;
148 foreMap
[x
][height
- hMap
[x
] - 1] = 30;
151 foreMap
[x
][height
- hMap
[x
] - 1] = 31;
154 foreMap
[x
][height
- hMap
[x
] - 1] = 32;
158 if (foreMap
[x
][height
- hMap
[x
] - 1] == 0 && foreMap
[x
][height
- hMap
[x
]] == 10) {
159 switch (rand
.nextInt(20)) {
161 genCactus(x
, height
- hMap
[x
] - 1);
164 foreMap
[x
][height
- hMap
[x
] - 1] = 27;
172 static int[][] getForeMap() {
176 static int[][] getBackMap() {
180 static void clear() {