From 6d7567d0ae21d5f64449448d9829eb1d058e1525 Mon Sep 17 00:00:00 2001 From: Arkitu <85173315+Arkitu@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:53:48 +0100 Subject: [PATCH] expansion + better grass colors --- src/map.rs | 3 +-- src/map/cells.rs | 63 +++++++++++++++++++++++++++++++++++++++--------- src/time.rs | 4 +-- 3 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/map.rs b/src/map.rs index aba642e..524e657 100644 --- a/src/map.rs +++ b/src/map.rs @@ -16,9 +16,8 @@ pub struct Plugin; impl bevy::prelude::Plugin for Plugin { fn build(&self, app: &mut App) { app.add_systems(Startup, setup) - .insert_resource(Time::::from_seconds(0.25)) // Time for a day .add_systems(PreUpdate, picking_backend.in_set(PickSet::Backend)) - .add_systems(Update, (update_map_mesh, cells_regeneration)) + .add_systems(Update, (update_map_mesh, cells_regeneration, expand)) .insert_resource(ClearColor(Color::srgb(0., 0., 1.))) .insert_resource(Seed(thread_rng().gen())); } diff --git a/src/map/cells.rs b/src/map/cells.rs index 761d2dc..9904403 100644 --- a/src/map/cells.rs +++ b/src/map/cells.rs @@ -1,10 +1,11 @@ use std::time::Duration; use bevy::prelude::*; +use rand::{seq::IteratorRandom, thread_rng, Rng}; use crate::time::GameTime; -use super::{MapMarker, MeshNeedsUpdate}; +use super::{CellsEntities, MapMarker, MeshNeedsUpdate, Voronoi}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum CellKind { @@ -33,15 +34,6 @@ pub struct Cell { pub vertices: Vec } impl Cell { - // pub fn new(kind: CellKind, voronoi_id: usize, altitude: u8, moisture: u8, vertices: Vec) -> Self { - // Self { - // kind, - // voronoi_id, - // altitude, - // moisture, - // vertices - // } - // } pub fn color(&self, wealth: u8) -> [f32; 4] { match self.kind { CellKind::Sea => [0., 0., 1., 1.], @@ -49,7 +41,7 @@ impl Cell { CellKind::Forest => [0., 0.5 - (wealth as f32/255.*0.4), 0., 1.], CellKind::Dirt => [0.53 - (wealth as f32/255.*0.4), 0.38-(wealth as f32/255.*0.4), 0.29-(wealth as f32/255.*0.4), 1.], CellKind::Stone => [0.5, 0.5, 0.5, 1.], - CellKind::Grass => [(136./255.) - (wealth as f32/255.*0.4), (204./255.) - (wealth as f32/255.*0.4), (59./255.) - (wealth as f32/255.*0.4), 1.] + CellKind::Grass => [(136./255.) - (wealth as f32/255.*0.15), (154./255.) + (wealth as f32/255.*0.1), (59./255.) - (wealth as f32/255.*0.15), 1.] } } } @@ -83,4 +75,53 @@ pub fn cells_regeneration( map_needs_update.0 = true; } } +} + +pub fn expand( + mut cells: Query<(&mut Cell, Option<&Wealth>)>, + map: Query<(&Voronoi, &CellsEntities)>, + mut cmds: Commands, + t: Res