6c09cf697bc908f6d69790d5fc68f66c7a92100a
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
;
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 static void genWorld(int width
, int height
) {
33 genWorld(width
, height
, TimeUtils
.millis());
36 static void genWorld(int width
, int height
, long s
) {
39 rand
= new RandomXS128(seed
);
40 foreMap
= new int[width
][height
];
41 backMap
= new int[width
][height
];
42 hMap
= genLandscape(width
, height
/2, height
/4, height
/4*3);
43 for (int x
=0; x
<width
; x
++) {
44 dirtH
= 4+rand
.nextInt(2);
45 for (int y
= height
- hMap
[x
]; y
<height
; y
++) {
46 if (y
==height
- hMap
[x
]) {
49 } else if (y
<height
-hMap
[x
]+dirtH
) {
52 } else if (y
<height
-1){
60 for (int y
= height
/2; y
<height
- hMap
[x
]; y
++) {
61 if (foreMap
[x
][y
]==0){
69 static int[][] getForeMap() {
73 static int[][] getBackMap() {