8c0f4ca7eec7cd7ae6d038ce688fb32872d9fc74
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 bMap
[i
] = i
/(width
/2);
27 t
= rand
.nextInt(7)-3;
28 if (t
>-3 && t
<3) t
=0; else t
/=Math
.abs(t
);
29 if (i
>width
-(max
-min
)) {
30 if (res
[i
-1]+t
<res
[0]) t
=Math
.abs(t
);
31 else if (res
[i
-1]+t
>res
[0]) t
=-Math
.abs(t
);
33 res
[i
] = res
[i
-1] + t
;
34 if (res
[i
]<min
) res
[i
] = min
;
35 if (res
[i
]>max
) res
[i
] = max
;
40 private static void genCactus(int x
, int y
) {
46 private static void genOak(int x
, int y
) {
53 backMap
[x
-1][y
-3] = 16;
54 backMap
[x
-1][y
-4] = 16;
55 backMap
[x
+1][y
-3] = 16;
56 backMap
[x
+1][y
-4] = 16;
60 foreMap
[x
-1][y
-3] = 16;
61 foreMap
[x
-1][y
-4] = 16;
62 foreMap
[x
+1][y
-3] = 16;
63 foreMap
[x
+1][y
-4] = 16;
66 static void genWorld(int width
, int height
) {
67 genWorld(width
, height
, TimeUtils
.millis());
70 static void genWorld(int width
, int height
, long worldseed
) {
73 rand
= new RandomXS128(seed
);
74 foreMap
= new int[width
][height
];
75 backMap
= new int[width
][height
];
76 hMap
= genLandscape(width
, height
/8*3, height
/8, height
/2);
77 for (int x
=0; x
<width
; x
++) {
78 dirtH
= 4+rand
.nextInt(2);
79 for (int y
= height
- hMap
[x
]; y
<height
; y
++) {
80 if (y
==height
- hMap
[x
]) {
91 } else if (y
<height
-hMap
[x
]+dirtH
) {
102 } else if (bMap
[x
]==1 && y
<height
-hMap
[x
]+dirtH
+3) {
105 } else if (y
<height
-1){
115 for (int y
= height
-60; y
<height
-1; y
++) {
116 if (foreMap
[x
][y
]==0 && bMap
[x
]!=1){
119 if (y
==height
-hMap
[x
]-1) {
124 if (x
>2 && x
<width
-2 && rand
.nextInt(100)<5){
125 if (foreMap
[x
][height
-hMap
[x
]-1]==0 && foreMap
[x
][height
-hMap
[x
]]==2) {
126 genOak(x
,height
-hMap
[x
]-1);
128 if (foreMap
[x
][height
-hMap
[x
]-1]==0 && foreMap
[x
][height
-hMap
[x
]]==10) {
129 genCactus(x
,height
-hMap
[x
]-1);
135 static int[][] getForeMap() {
139 static int[][] getBackMap() {
143 static void clear() {