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
;
14 public static long getSeed() {
18 static int[] genLandscape(int width
, int mid
, int min
, int max
) {
19 int[] res
= new int[width
];
22 for (int i
=1; i
<width
; i
++) {
23 t
= rand
.nextInt(7)-3;
24 if (t
>-3 && t
<3) t
=0; else t
/=Math
.abs(t
);
25 if (i
>width
-(max
-min
)) {
26 if (res
[i
-1]+t
<res
[0]) t
=Math
.abs(t
);
27 else if (res
[i
-1]+t
>res
[0]) t
=-Math
.abs(t
);
29 res
[i
] = res
[i
-1] + t
;
30 if (res
[i
]<min
) res
[i
] = min
;
31 if (res
[i
]>max
) res
[i
] = max
;
36 private static void genOak(int x
, int y
) {
43 backMap
[x
-1][y
-3] = 16;
44 backMap
[x
-1][y
-4] = 16;
45 backMap
[x
+1][y
-3] = 16;
46 backMap
[x
+1][y
-4] = 16;
50 foreMap
[x
-1][y
-3] = 16;
51 foreMap
[x
-1][y
-4] = 16;
52 foreMap
[x
+1][y
-3] = 16;
53 foreMap
[x
+1][y
-4] = 16;
56 static void genWorld(int width
, int height
) {
57 genWorld(width
, height
, TimeUtils
.millis());
60 static void genWorld(int width
, int height
, long worldseed
) {
63 rand
= new RandomXS128(seed
);
64 foreMap
= new int[width
][height
];
65 backMap
= new int[width
][height
];
66 hMap
= genLandscape(width
, height
/8*3, height
/8, height
/2);
67 for (int x
=0; x
<width
; x
++) {
68 dirtH
= 4+rand
.nextInt(2);
69 for (int y
= height
- hMap
[x
]; y
<height
; y
++) {
70 if (y
==height
- hMap
[x
]) {
73 } else if (y
<height
-hMap
[x
]+dirtH
) {
76 } else if (y
<height
-1){
84 for (int y
= height
-64; y
<height
-1; y
++) {
85 if (foreMap
[x
][y
]==0){
88 if (y
==height
-hMap
[x
]-1) {
93 if (x
>2 && x
<width
-2 && rand
.nextInt(100)<5){
94 if (foreMap
[x
][height
-hMap
[x
]-1]==0) {
95 genOak(x
,height
-hMap
[x
]-1);
101 static int[][] getForeMap() {
105 static int[][] getBackMap() {
109 static void clear() {