something that looks halfway ok

This commit is contained in:
zoe 2022-05-11 00:26:24 +02:00
parent e0c020bbd3
commit c2c9d9b3e3
3 changed files with 32 additions and 5 deletions

Binary file not shown.

View file

@ -1,7 +1,7 @@
extends Node
export var xsize = 16
export var ysize = 16
export var xsize = 256
export var ysize = 256
export var zsize = 3
export var cityname = "night city"

View file

@ -1,6 +1,6 @@
use gdnative::prelude::*;
use rand::prelude::StdRng;
use rand::prelude::*;
use rand::seq::SliceRandom;
use rand_seeder::Seeder;
mod tiles;
@ -37,14 +37,30 @@ impl World {
// fill edges with water
for x in 0..self.ysize {
self.tiles[x][0][0] = tiles::Tiletypes::WaterSlab;
self.tiles[x][self.ysize - 1][0] = tiles::Tiletypes::WaterSlab;
self.tiles[x][0][0] = tiles::Tiletypes::WaterSlab;
self.tiles[x][self.ysize - 1][0] = tiles::Tiletypes::WaterSlab;
}
for y in 0..self.xsize {
self.tiles[0][y][0] = tiles::Tiletypes::WaterSlab;
self.tiles[self.xsize - 1][y][0] = tiles::Tiletypes::WaterSlab;
}
for x in 1..self.xsize - 1 {
for y in 1..self.ysize - 1 {
if self.tile_is_next_to(x, y, 0, tiles::Tiletypes::WaterSlab){
let available = vec![tiles::Tiletypes::WaterSlab, tiles::Tiletypes::Sand];
self.tiles[x][y][0] = available.choose(&mut rng).unwrap().to_owned();
}
else if self.tile_is_next_to(x, y, 0, tiles::Tiletypes::Sand) {
let available = vec![tiles::Tiletypes::Grass, tiles::Tiletypes::Sand];
self.tiles[x][y][0] = available.choose(&mut rng).unwrap().to_owned();
}
else {
self.tiles[x][y][0] = tiles::Tiletypes::Air;
}
}
}
let mut ret: Vector3Array = Vector3Array::new();
for x in 0..self.xsize {
for y in 0..self.ysize {
@ -56,6 +72,17 @@ impl World {
ret
}
fn tile_is_next_to(&self, x: usize, y: usize, z: usize, neighbor: tiles::Tiletypes) -> bool {
if self.tiles[x - 1][y - 1][z] == neighbor
|| self.tiles[x - 1][y][z] == neighbor
|| self.tiles[x][y + 1][z] == neighbor
|| self.tiles[x + 1][y + 1][z] == neighbor
{
return true;
}
false
}
pub fn new(xsize: usize, ysize: usize, zsize: usize, seed: String) -> World {
World {
xsize,