1 package ru
.deadsoftware
.cavedroid
.game
;
3 import com
.badlogic
.gdx
.math
.RandomXS128
;
4 import com
.badlogic
.gdx
.utils
.TimeUtils
;
6 import javax
.annotation
.CheckForNull
;
11 private static RandomXS128 rand
;
12 private static long seed
;
15 private static int[][] foreMap
, backMap
;
17 private static int[] hMap
;
19 private static int[] bMap
; //biomes, 0-plains, 1-desert
21 public static long getSeed() {
25 static int[] genLandscape(int width
, int mid
, int min
, int max
) {
26 int[] res
= new int[width
];
27 bMap
= new int[width
];
30 for (int i
= 1; i
< width
; i
++) {
31 t
= rand
.nextInt(7) - 3;
32 if (t
> -3 && t
< 3) {
37 if (i
> width
- (max
- min
)) {
38 if (res
[i
- 1] + t
< res
[0]) {
40 } else if (res
[i
- 1] + t
> res
[0]) {
44 res
[i
] = res
[i
- 1] + t
;
52 // if (i >= width / 2) {
54 // if (res[i] < 60) res[i] = 60;
59 if (res
[0] < res
[width
- 1]) {
60 res
[width
- 1] = res
[0];
65 private static void genCactus(int x
, int y
) {
66 assert foreMap
!= null;
68 foreMap
[x
][y
- 1] = 59;
69 foreMap
[x
][y
- 2] = 59;
72 private static void genOak(int x
, int y
) {
73 assert foreMap
!= null && backMap
!= null;
75 backMap
[x
][y
- 1] = 15;
76 backMap
[x
][y
- 2] = 15;
77 backMap
[x
][y
- 3] = 15;
78 backMap
[x
][y
- 4] = 16;
79 backMap
[x
][y
- 5] = 16;
80 backMap
[x
- 1][y
- 3] = 16;
81 backMap
[x
- 1][y
- 4] = 16;
82 backMap
[x
+ 1][y
- 3] = 16;
83 backMap
[x
+ 1][y
- 4] = 16;
84 foreMap
[x
][y
- 3] = 16;
85 foreMap
[x
][y
- 4] = 16;
86 foreMap
[x
][y
- 5] = 16;
87 foreMap
[x
- 1][y
- 3] = 16;
88 foreMap
[x
- 1][y
- 4] = 16;
89 foreMap
[x
+ 1][y
- 3] = 16;
90 foreMap
[x
+ 1][y
- 4] = 16;
93 static void genWorld(int width
, int height
) {
94 genWorld(width
, height
, TimeUtils
.millis());
97 static void genWorld(int width
, int height
, long worldseed
) {
100 rand
= new RandomXS128(seed
);
101 foreMap
= new int[width
][height
];
102 backMap
= new int[width
][height
];
103 hMap
= genLandscape(width
, height
/ 4, height
/ 8, height
/ 2);
104 for (int x
= 0; x
< width
; x
++) {
105 dirtH
= 4 + rand
.nextInt(2);
106 for (int y
= height
- hMap
[x
]; y
< height
; y
++) {
107 if (y
== height
- hMap
[x
]) {
118 } else if (y
< height
- hMap
[x
] + dirtH
) {
129 } else if (bMap
[x
] == 1 && y
< height
- hMap
[x
] + dirtH
+ 3) {
132 } else if (y
< height
- 1) {
140 for (int y
= height
- 60; y
< height
- 1; y
++) {
141 if (foreMap
[x
][y
] == 0 && bMap
[x
] != 1) {
144 if (y
== height
- 60) {
150 if (y
== height
- hMap
[x
] - 1) {
151 foreMap
[x
][y
+ 1] = 3;
152 backMap
[x
][y
+ 1] = 3;
156 if (x
> 2 && x
< width
- 2) {
157 if (foreMap
[x
][height
- hMap
[x
] - 1] == 0 && foreMap
[x
][height
- hMap
[x
]] == 2) {
158 switch (rand
.nextInt(50)) {
160 genOak(x
, height
- hMap
[x
] - 1);
163 foreMap
[x
][height
- hMap
[x
] - 1] = 26;
166 foreMap
[x
][height
- hMap
[x
] - 1] = 29;
169 foreMap
[x
][height
- hMap
[x
] - 1] = 30;
172 foreMap
[x
][height
- hMap
[x
] - 1] = 31;
175 foreMap
[x
][height
- hMap
[x
] - 1] = 32;
179 if (foreMap
[x
][height
- hMap
[x
] - 1] == 0 && foreMap
[x
][height
- hMap
[x
]] == 10) {
180 switch (rand
.nextInt(20)) {
182 genCactus(x
, height
- hMap
[x
] - 1);
185 foreMap
[x
][height
- hMap
[x
] - 1] = 27;
193 static int[][] getForeMap() {
194 assert foreMap
!= null;
198 static int[][] getBackMap() {
199 assert backMap
!= null;
203 static void clear() {