improve generation even more

This commit is contained in:
Zoe 2022-05-13 21:56:45 +02:00
parent 4daf1fe0ff
commit 929e296fb7
3 changed files with 46 additions and 43 deletions

Binary file not shown.

View file

@ -1,9 +1,9 @@
extends Node
export var xsize = 1048
export var ysize = 1048
export var xsize = 142
export var ysize = 142
var zsize = 10
export var cityname = "dsfdsfdsfdsfsfkdsjfksdjf"
export var cityname = "käse"
func _ready():
StateServer.generate_world(xsize, ysize, zsize, cityname)

View file

@ -9,7 +9,6 @@ pub struct World {
pub zsize: usize,
tiles: Vec<Vec<Vec<tiles::Tiletypes>>>,
seed: String,
tileattributes: tiles::Attributelists,
}
impl World {
@ -34,50 +33,36 @@ impl World {
let mut rng = gen::get_rng(self.seed.to_owned());
let noisemap = gen::get_noise(&mut rng, (self.xsize, self.ysize));
// return array with all changed tiles, needs rework
let mut ret: Vector3Array = Vector3Array::new();
for x in 0..self.xsize {
for y in 0..self.ysize {
ret.push(Vector3::new(x as f32, y as f32, 0.0));
if noisemap.get_value(x, y) > 0.5 {
self.tiles[x][y][0] = tiles::Tiletypes::Rock;
self.tiles[x][y][1] = tiles::Tiletypes::Rock;
ret.push(Vector3::new(x as f32, y as f32, 1.0));
self.tiles[x][y][2] = tiles::Tiletypes::Rock;
ret.push(Vector3::new(x as f32, y as f32, 2.0));
self.tiles[x][y][3] = tiles::Tiletypes::Rock;
ret.push(Vector3::new(x as f32, y as f32, 3.0));
if noisemap.get_value(x, y) > 0.6 {
self.tiles[x][y][4] = tiles::Tiletypes::Rock;
ret.push(Vector3::new(x as f32, y as f32, 4.0));
}
if noisemap.get_value(x, y) > 0.7 {
self.tiles[x][y][5] = tiles::Tiletypes::Rock;
ret.push(Vector3::new(x as f32, y as f32, 5.0));
}
}
else if noisemap.get_value(x, y) > 0.2 {
self.tiles[x][y][0] = tiles::Tiletypes::Dirt;
if noisemap.get_value(x, y) > 0.3 {
self.tiles[x][y][1] = tiles::Tiletypes::Dirt;
ret.push(Vector3::new(x as f32, y as f32, 1.0));
self.tiles[x][y][2] = tiles::Tiletypes::Grass;
ret.push(Vector3::new(x as f32, y as f32, 2.0));
}
else {
self.tiles[x][y][1] = tiles::Tiletypes::Grass;
ret.push(Vector3::new(x as f32, y as f32, 1.0));
}
}
else if noisemap.get_value(x, y) > 0.0 {
if noisemap.get_value(x, y) > 0.4 {
ret.append(&self.stack_tiles(
4,
tiles::Tiletypes::Grass,
tiles::Tiletypes::Dirt,
(x, y),
));
} else if noisemap.get_value(x, y) > 0.3 {
ret.append(&self.stack_tiles(
3,
tiles::Tiletypes::Grass,
tiles::Tiletypes::Dirt,
(x, y),
));
} else if noisemap.get_value(x, y) > 0.2 {
ret.append(&self.stack_tiles(
2,
tiles::Tiletypes::Grass,
tiles::Tiletypes::Dirt,
(x, y),
));
} else if noisemap.get_value(x, y) > -0.3 {
self.tiles[x][y][0] = tiles::Tiletypes::Grass;
}
else if noisemap.get_value(x, y) > -0.1 {
} else if noisemap.get_value(x, y) > -0.4 {
self.tiles[x][y][0] = tiles::Tiletypes::Sand;
}
else {
} else {
self.tiles[x][y][0] = tiles::Tiletypes::WaterSlab;
}
}
@ -85,6 +70,25 @@ impl World {
ret
}
fn stack_tiles(
&mut self,
height: usize,
top: tiles::Tiletypes,
filler: tiles::Tiletypes,
pos: (usize, usize),
) -> Vector3Array {
let mut positions = Vector3Array::new();
for z in 0..height {
positions.push(Vector3::new(pos.0 as f32, pos.1 as f32, z as f32));
if z == height - 1 {
self.tiles[pos.0][pos.1][z] = top;
} else {
self.tiles[pos.0][pos.1][z] = filler;
}
}
positions
}
pub fn new(xsize: usize, ysize: usize, zsize: usize, seed: String) -> World {
World {
xsize,
@ -92,7 +96,6 @@ impl World {
zsize,
tiles: get_vec3(xsize, ysize, zsize),
seed,
tileattributes: tiles::Attributelists::new(),
}
}
}