From 3f679665d98e46ae52ebe5703ed91918e26dcd54 Mon Sep 17 00:00:00 2001 From: CoCo_Sol Date: Mon, 1 Apr 2024 15:46:43 +0200 Subject: [PATCH] save --- crates/border-wars/src/map/ownership.rs | 9 +++++---- crates/border-wars/src/scenes/menu.rs | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/border-wars/src/map/ownership.rs b/crates/border-wars/src/map/ownership.rs index 1321c4a..3218215 100644 --- a/crates/border-wars/src/map/ownership.rs +++ b/crates/border-wars/src/map/ownership.rs @@ -28,6 +28,7 @@ fn setup_ownership_resources(mut commands: Commands) { commands.insert_resource(OwnershipColorContrast(0.4)); } +/// Render the ownership of the tiles by applying colors. fn render_ownership( mut query: Query<(&mut Sprite, &Owner), Changed>, contrast: Res, @@ -40,12 +41,12 @@ fn render_ownership( } } -// Mixes two colors. +/// Mixes two colors. fn mix_colors(color1: Color, color2: Color, alpha: f32) -> Color { let [r1, g1, b1, _] = color1.as_rgba_u8(); let [r2, g2, b2, _] = color2.as_rgba_u8(); - let mixed_r = ((1.0 - alpha) * r1 as f32 + alpha * r2 as f32).round() as u8; - let mixed_g = ((1.0 - alpha) * g1 as f32 + alpha * g2 as f32).round() as u8; - let mixed_b = ((1.0 - alpha) * b1 as f32 + alpha * b2 as f32).round() as u8; + let mixed_r = (1.0 - alpha).mul_add(r1 as f32, alpha * r2 as f32).round() as u8; + let mixed_g = (1.0 - alpha).mul_add(g1 as f32, alpha * g2 as f32).round() as u8; + let mixed_b = (1.0 - alpha).mul_add(b1 as f32, alpha * b2 as f32).round() as u8; Color::rgb_u8(mixed_r, mixed_g, mixed_b) } diff --git a/crates/border-wars/src/scenes/menu.rs b/crates/border-wars/src/scenes/menu.rs index 809db1e..a13de1a 100644 --- a/crates/border-wars/src/scenes/menu.rs +++ b/crates/border-wars/src/scenes/menu.rs @@ -58,7 +58,7 @@ fn menu_ui( name: name.clone(), rank: PlayerRank::Player, uuid, - color: (0, 0, 0), + color: rand::random::<(u8, u8, u8)>(), }), )); } @@ -72,7 +72,7 @@ fn menu_ui( name: name.clone(), rank: PlayerRank::Admin, uuid, - color: (255, 255, 255), + color: rand::random::<(u8, u8, u8)>(), }); } });