experimenting a bit more

This commit is contained in:
griffi-gh 2023-01-18 03:51:11 +01:00
parent ed5b8de09a
commit 37ab56115f

View file

@ -6,6 +6,9 @@ use crate::game::{
}; };
const HEIGHTMAP_SCALE: f64 = 0.004; const HEIGHTMAP_SCALE: f64 = 0.004;
const MOUNTAINESS_SCALE: f64 = 0.0001;
const MNT_RAMP_1: f64 = 0.5;
const MNT_RAMP_2: f64 = 0.6;
const TERRAIN_HEIGHT_MIN: f64 = 64.; const TERRAIN_HEIGHT_MIN: f64 = 64.;
const TERRAIN_HEIGHT_MAX: f64 = 80.; const TERRAIN_HEIGHT_MAX: f64 = 80.;
@ -17,14 +20,31 @@ pub fn generate_chunk(position: IVec2, seed: u32) -> ChunkData {
let mut terrain_base_fbm: Fbm<Perlin> = Fbm::new(seed); let mut terrain_base_fbm: Fbm<Perlin> = Fbm::new(seed);
terrain_base_fbm.octaves = 6; terrain_base_fbm.octaves = 6;
let mut mountainess_base_fbm: Fbm<Perlin> = Fbm::new(seed);
mountainess_base_fbm.octaves = 4;
//put everything together //put everything together
for x in 0..CHUNK_SIZE { for x in 0..CHUNK_SIZE {
for z in 0..CHUNK_SIZE { for z in 0..CHUNK_SIZE {
let point = world_xz.as_dvec2() + DVec2::from_array([x as f64, z as f64]); let point = world_xz.as_dvec2() + DVec2::from_array([x as f64, z as f64]);
let heightmap = (terrain_base_fbm.get((point * HEIGHTMAP_SCALE).to_array()) + 1.) / 2.; let heightmap = (terrain_base_fbm.get((point * HEIGHTMAP_SCALE).to_array()) + 1.) / 2.;
let mountainess = (mountainess_base_fbm.get((point * MOUNTAINESS_SCALE).to_array()) + 1.) / 2.;
//generate basic terrain //generate basic terrain
let terain_height = (TERRAIN_HEIGHT_MIN + (heightmap * TERRAIN_HEIGHT_MAX)).floor() as usize; let terain_height =
(
TERRAIN_HEIGHT_MIN +
(heightmap * TERRAIN_HEIGHT_MAX * (1. + if mountainess < MNT_RAMP_1 {
0.
} else {
if mountainess > MNT_RAMP_2 {
1.
} else {
mountainess - MNT_RAMP_1
}
}))
).floor() as usize;
for y in 0..terain_height { for y in 0..terain_height {
chunk[x][y][z] = Block::Dirt; chunk[x][y][z] = Block::Dirt;
} }