1 package ru
.deadsoftware
.cavedroid
.game
;
3 import com
.badlogic
.gdx
.math
.RandomXS128
;
4 import com
.badlogic
.gdx
.utils
.TimeUtils
;
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
;
36 // if (i >= width / 2) {
38 // if (res[i] < 60) res[i] = 60;
43 if (res
[0] < res
[width
- 1]) res
[width
- 1] = res
[0];
47 private static void genCactus(int x
, int y
) {
49 foreMap
[x
][y
- 1] = 59;
50 foreMap
[x
][y
- 2] = 59;
53 private static void genOak(int x
, int y
) {
55 backMap
[x
][y
- 1] = 15;
56 backMap
[x
][y
- 2] = 15;
57 backMap
[x
][y
- 3] = 15;
58 backMap
[x
][y
- 4] = 16;
59 backMap
[x
][y
- 5] = 16;
60 backMap
[x
- 1][y
- 3] = 16;
61 backMap
[x
- 1][y
- 4] = 16;
62 backMap
[x
+ 1][y
- 3] = 16;
63 backMap
[x
+ 1][y
- 4] = 16;
64 foreMap
[x
][y
- 3] = 16;
65 foreMap
[x
][y
- 4] = 16;
66 foreMap
[x
][y
- 5] = 16;
67 foreMap
[x
- 1][y
- 3] = 16;
68 foreMap
[x
- 1][y
- 4] = 16;
69 foreMap
[x
+ 1][y
- 3] = 16;
70 foreMap
[x
+ 1][y
- 4] = 16;
73 static void genWorld(int width
, int height
) {
74 genWorld(width
, height
, TimeUtils
.millis());
77 static void genWorld(int width
, int height
, long worldseed
) {
80 rand
= new RandomXS128(seed
);
81 foreMap
= new int[width
][height
];
82 backMap
= new int[width
][height
];
83 hMap
= genLandscape(width
, height
/ 4, height
/ 8, height
/ 2);
84 for (int x
= 0; x
< width
; x
++) {
85 dirtH
= 4 + rand
.nextInt(2);
86 for (int y
= height
- hMap
[x
]; y
< height
; y
++) {
87 if (y
== height
- hMap
[x
]) {
98 } else if (y
< height
- hMap
[x
] + dirtH
) {
109 } else if (bMap
[x
] == 1 && y
< height
- hMap
[x
] + dirtH
+ 3) {
112 } else if (y
< height
- 1) {
120 for (int y
= height
- 60; y
< height
- 1; y
++) {
121 if (foreMap
[x
][y
] == 0 && bMap
[x
] != 1) {
124 if (y
== height
- 60) {
130 if (y
== height
- hMap
[x
] - 1) {
131 foreMap
[x
][y
+ 1] = 3;
132 backMap
[x
][y
+ 1] = 3;
136 if (x
> 2 && x
< width
- 2) {
137 if (foreMap
[x
][height
- hMap
[x
] - 1] == 0 && foreMap
[x
][height
- hMap
[x
]] == 2) {
138 switch (rand
.nextInt(50)) {
140 genOak(x
, height
- hMap
[x
] - 1);
143 foreMap
[x
][height
- hMap
[x
] - 1] = 26;
146 foreMap
[x
][height
- hMap
[x
] - 1] = 29;
149 foreMap
[x
][height
- hMap
[x
] - 1] = 30;
152 foreMap
[x
][height
- hMap
[x
] - 1] = 31;
155 foreMap
[x
][height
- hMap
[x
] - 1] = 32;
159 if (foreMap
[x
][height
- hMap
[x
] - 1] == 0 && foreMap
[x
][height
- hMap
[x
]] == 10) {
160 switch (rand
.nextInt(20)) {
162 genCactus(x
, height
- hMap
[x
] - 1);
165 foreMap
[x
][height
- hMap
[x
] - 1] = 27;
173 static int[][] getForeMap() {
177 static int[][] getBackMap() {
181 static void clear() {