summaryrefslogtreecommitdiff
path: root/src/content/world/mines.rs
blob: d7e23bc3940ccb02f1229199b3903db8a60fd9d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use fastnoise_lite::{FastNoiseLite, FractalType};
use glam::IVec2;

use crate::{content::materials::MaterialId, proc_gen::Biome, sim::cell::Cell};

const ROUGHNESS: f32 = 0.375;

pub struct MinesBiome {
    pub edge_roughness: FastNoiseLite,
}

impl MinesBiome {
    pub fn new() -> Self {
        let mut edge_roughness = FastNoiseLite::new();
        edge_roughness.octaves = 2;
        edge_roughness.fractal_type = FractalType::Ridged;
        MinesBiome { edge_roughness }
    }
}

impl Biome for MinesBiome {
    fn cell(&self, solidity: f32, world: IVec2) -> Cell {
        let world = world.as_vec2();

        let displacement = ROUGHNESS * self.edge_roughness.get_noise_2d(world.x, world.y);

        if solidity + displacement <= 0.0 {
            return Cell::void();
        }

        Cell::from_material(MaterialId::Dirt)
    }
}