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
.TimeUtils
;
7 public class WorldGen
{
9 private static RandomXS128 rand
;
10 private static long seed
;
12 private static int[][] foreMap
, backMap
;
13 private static int[] hMap
;
14 private static int[] bMap
; //biomes, 0-plains, 1-desert
16 public static long getSeed() {
20 static int[] genLandscape(int width
, int mid
, int min
, int max
) {
21 int[] res
= new int[width
];
22 bMap
= new int[width
];
25 for (int i
=1; i
<width
; i
++) {
26 t
= rand
.nextInt(7)-3;
27 if (t
>-3 && t
<3) t
=0; 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
) {
52 private static void genOak(int x
, int y
) {
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;
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){
129 if (y
==height
-hMap
[x
]-1) {
135 if (x
>2 && x
<width
-2 && rand
.nextInt(100)<5){
136 if (foreMap
[x
][height
-hMap
[x
]-1]==0 && foreMap
[x
][height
-hMap
[x
]]==2) {
137 genOak(x
,height
-hMap
[x
]-1);
139 if (foreMap
[x
][height
-hMap
[x
]-1]==0 && foreMap
[x
][height
-hMap
[x
]]==10) {
140 genCactus(x
,height
-hMap
[x
]-1);
146 static int[][] getForeMap() {
150 static int[][] getBackMap() {
154 static void clear() {