32cb8f94a0f28db677a4045a177f3aec0cfbaf4a
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
.ArrayMap
;
6 import com
.badlogic
.gdx
.utils
.TimeUtils
;
8 public class WorldGen
{
10 private static RandomXS128 rand
;
11 private static long seed
;
13 private static int[][] foreMap
, backMap
;
14 private static int[] hMap
;
16 public static long getSeed() {
20 static int[] genLandscape(int width
, int mid
, int min
, int max
) {
21 int[] res
= new int[width
];
24 for (int i
=1; i
<width
; i
++) {
25 t
= rand
.nextInt(3)-1;
26 res
[i
] = res
[i
-1] + t
;
27 if (res
[i
]<min
) res
[i
] = min
;
28 if (res
[i
]>max
) res
[i
] = max
;
33 private static void genOak(int x
, int y
) {
40 backMap
[x
-1][y
-3] = 16;
41 backMap
[x
-1][y
-4] = 16;
42 backMap
[x
+1][y
-3] = 16;
43 backMap
[x
+1][y
-4] = 16;
47 foreMap
[x
-1][y
-3] = 16;
48 foreMap
[x
-1][y
-4] = 16;
49 foreMap
[x
+1][y
-3] = 16;
50 foreMap
[x
+1][y
-4] = 16;
53 static void genWorld(int width
, int height
) {
54 genWorld(width
, height
, TimeUtils
.millis());
57 static void genWorld(int width
, int height
, long s
) {
60 rand
= new RandomXS128(seed
);
61 foreMap
= new int[width
][height
];
62 backMap
= new int[width
][height
];
63 hMap
= genLandscape(width
, height
/4, height
/8, height
/2);
64 for (int x
=0; x
<width
; x
++) {
65 for (int y
=0; y
<height
; y
++) {
67 dirtH
= 4+rand
.nextInt(2);
68 for (int y
= height
- hMap
[x
]; y
<height
; y
++) {
69 if (y
==height
- hMap
[x
]) {
72 } else if (y
<height
-hMap
[x
]+dirtH
) {
75 } else if (y
<height
-1){
83 for (int y
= height
-64; y
<height
-1; y
++) {
84 if (foreMap
[x
][y
]==0){
89 if (x
>2 && x
<width
-2 && rand
.nextInt(100)<5){
90 genOak(x
,height
-hMap
[x
]-1);
95 static int[][] getForeMap() {
99 static int[][] getBackMap() {
103 static void clear() {