1 package ru
.deadsoftware
.cavecraft
.game
;
3 import com
.badlogic
.gdx
.math
.RandomXS128
;
4 import com
.badlogic
.gdx
.utils
.ArrayMap
;
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
;
15 public static long getSeed() {
19 static int[] genLandscape(int width
, int mid
, int min
, int max
) {
20 int[] res
= new int[width
];
23 for (int i
=1; i
<width
; i
++) {
24 t
= rand
.nextInt(3)-1;
25 res
[i
] = res
[i
-1] + t
;
26 if (res
[i
]<min
) res
[i
] = min
;
27 if (res
[i
]>max
) res
[i
] = max
;
32 private static void genOak(int x
, int y
) {
39 backMap
[x
-1][y
-3] = 16;
40 backMap
[x
-1][y
-4] = 16;
41 backMap
[x
+1][y
-3] = 16;
42 backMap
[x
+1][y
-4] = 16;
46 foreMap
[x
-1][y
-3] = 16;
47 foreMap
[x
-1][y
-4] = 16;
48 foreMap
[x
+1][y
-3] = 16;
49 foreMap
[x
+1][y
-4] = 16;
52 static void genWorld(int width
, int height
) {
53 genWorld(width
, height
, TimeUtils
.millis());
56 static void genWorld(int width
, int height
, long s
) {
59 rand
= new RandomXS128(seed
);
60 foreMap
= new int[width
][height
];
61 backMap
= new int[width
][height
];
62 hMap
= genLandscape(width
, height
/2, height
/4, height
/4*3);
63 for (int x
=0; x
<width
; x
++) {
64 for (int y
=0; y
<height
; y
++) {
66 dirtH
= 4+rand
.nextInt(2);
67 for (int y
= height
- hMap
[x
]; y
<height
; y
++) {
68 if (y
==height
- hMap
[x
]) {
71 } else if (y
<height
-hMap
[x
]+dirtH
) {
74 } else if (y
<height
-1){
82 for (int y
= height
/4*3; y
<height
- hMap
[x
]; y
++) {
83 if (foreMap
[x
][y
]==0){
88 if (x
>2 && x
<width
-2 && rand
.nextInt(100)<5){
89 genOak(x
,height
-hMap
[x
]-1);
94 static int[][] getForeMap() {
98 static int[][] getBackMap() {
102 static void clear() {