Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic enemy colors to minimap #795

Merged
merged 5 commits into from
Jun 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 40 additions & 15 deletions crates/controller/src/hud/minimap/fill.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use bevy::{ecs::system::SystemParam, prelude::*};
use de_core::{
gamestate::GameState, gconfig::GameConfig, objects::ObjectTypeComponent,
player::PlayerComponent, schedule::PostMovement,
gamestate::GameState, objects::ObjectTypeComponent, player::PlayerComponent,
schedule::PostMovement,
};
use de_map::size::MapBounds;
use de_objects::SolidObjects;
use de_terrain::TerrainCollider;
use de_types::projection::ToFlat;
use de_types::{
objects::{ActiveObjectType, ObjectType},
player::Player,
projection::ToFlat,
};
use parry2d::{
bounding_volume::Aabb,
math::Point,
Expand All @@ -17,11 +21,35 @@ use super::draw::DrawingParam;
use crate::ray::ScreenRay;

const TERRAIN_COLOR: Color = Color::rgb(0.61, 0.46, 0.32);
const PLAYER_COLOR: Color = Color::rgb(0.1, 0.1, 0.9);
const ENEMY_COLOR: Color = Color::rgb(0.9, 0.1, 0.1);
const PLAYER_COLORS: [Color; Player::MAX_PLAYERS] = [
Color::rgb(0.1, 0.1, 0.9),
Color::rgb(0.1, 0.9, 0.1),
Color::rgb(0.9, 0.1, 0.1),
Color::rgb(0.9, 0.9, 0.1),
];
const MIN_ENTITY_SIZE: Vec2 = Vec2::splat(0.02);
const CAMERA_COLOR: Color = Color::rgb(0.9, 0.9, 0.9);

#[derive(Resource, Debug)]
struct PlayerColors([Color; Player::MAX_PLAYERS]);

impl PlayerColors {
redbugz marked this conversation as resolved.
Show resolved Hide resolved
fn get_color(&self, player: Player, object_type: ActiveObjectType) -> Color {
let player_idx: usize = (player.to_num() - 1) as usize;
let player_color = self.0[player_idx].as_hsla();
match object_type {
ActiveObjectType::Building(_) => player_color,
ActiveObjectType::Unit(_) => player_color.with_s(0.7 * player_color.s()),
}
}
}

impl Default for PlayerColors {
fn default() -> Self {
Self(PLAYER_COLORS)
}
}

pub(super) struct FillPlugin;

impl Plugin for FillPlugin {
Expand Down Expand Up @@ -74,22 +102,19 @@ fn draw_entities_system(
mut drawing: DrawingParam,
ui_coords: UiCoords,
solids: SolidObjects,
game: Res<GameConfig>,
colors: Local<PlayerColors>,
entities: Query<(&Transform, &PlayerComponent, &ObjectTypeComponent)>,
) {
let mut drawing = drawing.drawing();

for (transform, &player, &object_type) in entities.iter() {
let minimap_position = ui_coords.flat_to_rel(transform.translation.to_flat());
let color = if game.locals().is_playable(*player) {
PLAYER_COLOR
} else {
ENEMY_COLOR
};

let radius = solids.get(*object_type).ichnography().radius();
let rect_size = MIN_ENTITY_SIZE.max(ui_coords.size_to_rel(Vec2::splat(radius)));
drawing.rect(minimap_position, rect_size, color);
if let ObjectType::Active(active_object) = *object_type {
let color = colors.get_color(*player, active_object);
let radius = solids.get(*object_type).ichnography().radius();
let rect_size = MIN_ENTITY_SIZE.max(ui_coords.size_to_rel(Vec2::splat(radius)));
drawing.rect(minimap_position, rect_size, color);
}
}
}

Expand Down
Loading