From 7c4012e139bfdf288befca0e0cee19918efdffad Mon Sep 17 00:00:00 2001 From: crumblingstatue Date: Fri, 7 Apr 2023 23:31:26 +0200 Subject: [PATCH] Add light dropoff the deeper you go --- src/game.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/game.rs b/src/game.rs index 8a20fc8..b1640be 100644 --- a/src/game.rs +++ b/src/game.rs @@ -33,7 +33,7 @@ pub struct GameState { #[derivative(Debug = "ignore")] #[opaque] pub worldgen: Worldgen, - pub ambient_light: f32, + pub ambient_light: u8, #[opaque] pub clock: SfBox, pub light_sources: Vec, @@ -89,9 +89,18 @@ impl GameState { } pub(crate) fn light_pass(&mut self, lightmap: &mut RenderTexture, res: &Res) { + let how_much_below_surface = self.camera_offset.y.saturating_sub(WorldPos::SURFACE); + let light_dropoff = (how_much_below_surface / 8).min(255) as u8; + let daylight = 255u8; + self.ambient_light = daylight.saturating_sub(light_dropoff); // Clear light map // You can clear to a brighter color to increase ambient light level - lightmap.clear(Color::rgba(0, 0, 0, 255)); + lightmap.clear(Color::rgba( + self.ambient_light, + self.ambient_light, + self.ambient_light, + 255, + )); for ls in &self.light_sources { let (x, y) = ( ls.pos.x as i32 - self.camera_offset.x as i32, @@ -140,7 +149,7 @@ impl Default for GameState { current_biome: Biome::Surface, prev_biome: Biome::Surface, worldgen: Worldgen::default(), - ambient_light: 1.0, + ambient_light: 0, clock: Clock::start(), light_sources: Vec::new(), }