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) {
31 if (i
> width
- (max
- min
)) {
32 if (res
[i
- 1] + t
< res
[0]) {
34 } else if (res
[i
- 1] + t
> res
[0]) {
38 res
[i
] = res
[i
- 1] + t
;
46 // if (i >= width / 2) {
48 // if (res[i] < 60) res[i] = 60;
53 if (res
[0] < res
[width
- 1]) {
54 res
[width
- 1] = res
[0];
59 private static void genCactus(int x
, int y
) {
61 foreMap
[x
][y
- 1] = 59;
62 foreMap
[x
][y
- 2] = 59;
65 private static void genOak(int x
, int y
) {
67 backMap
[x
][y
- 1] = 15;
68 backMap
[x
][y
- 2] = 15;
69 backMap
[x
][y
- 3] = 15;
70 backMap
[x
][y
- 4] = 16;
71 backMap
[x
][y
- 5] = 16;
72 backMap
[x
- 1][y
- 3] = 16;
73 backMap
[x
- 1][y
- 4] = 16;
74 backMap
[x
+ 1][y
- 3] = 16;
75 backMap
[x
+ 1][y
- 4] = 16;
76 foreMap
[x
][y
- 3] = 16;
77 foreMap
[x
][y
- 4] = 16;
78 foreMap
[x
][y
- 5] = 16;
79 foreMap
[x
- 1][y
- 3] = 16;
80 foreMap
[x
- 1][y
- 4] = 16;
81 foreMap
[x
+ 1][y
- 3] = 16;
82 foreMap
[x
+ 1][y
- 4] = 16;
85 static void genWorld(int width
, int height
) {
86 genWorld(width
, height
, TimeUtils
.millis());
89 static void genWorld(int width
, int height
, long worldseed
) {
92 rand
= new RandomXS128(seed
);
93 foreMap
= new int[width
][height
];
94 backMap
= new int[width
][height
];
95 hMap
= genLandscape(width
, height
/ 4, height
/ 8, height
/ 2);
96 for (int x
= 0; x
< width
; x
++) {
97 dirtH
= 4 + rand
.nextInt(2);
98 for (int y
= height
- hMap
[x
]; y
< height
; y
++) {
99 if (y
== height
- hMap
[x
]) {
110 } else if (y
< height
- hMap
[x
] + dirtH
) {
121 } else if (bMap
[x
] == 1 && y
< height
- hMap
[x
] + dirtH
+ 3) {
124 } else if (y
< height
- 1) {
132 for (int y
= height
- 60; y
< height
- 1; y
++) {
133 if (foreMap
[x
][y
] == 0 && bMap
[x
] != 1) {
136 if (y
== height
- 60) {
142 if (y
== height
- hMap
[x
] - 1) {
143 foreMap
[x
][y
+ 1] = 3;
144 backMap
[x
][y
+ 1] = 3;
148 if (x
> 2 && x
< width
- 2) {
149 if (foreMap
[x
][height
- hMap
[x
] - 1] == 0 && foreMap
[x
][height
- hMap
[x
]] == 2) {
150 switch (rand
.nextInt(50)) {
152 genOak(x
, height
- hMap
[x
] - 1);
155 foreMap
[x
][height
- hMap
[x
] - 1] = 26;
158 foreMap
[x
][height
- hMap
[x
] - 1] = 29;
161 foreMap
[x
][height
- hMap
[x
] - 1] = 30;
164 foreMap
[x
][height
- hMap
[x
] - 1] = 31;
167 foreMap
[x
][height
- hMap
[x
] - 1] = 32;
171 if (foreMap
[x
][height
- hMap
[x
] - 1] == 0 && foreMap
[x
][height
- hMap
[x
]] == 10) {
172 switch (rand
.nextInt(20)) {
174 genCactus(x
, height
- hMap
[x
] - 1);
177 foreMap
[x
][height
- hMap
[x
] - 1] = 27;
185 static int[][] getForeMap() {
189 static int[][] getBackMap() {
193 static void clear() {