From a198fe1832b315660c98e303dbcf230f04f17401 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 16 Nov 2021 10:28:05 -0500 Subject: [PATCH] Implement bloodstains --- src/damage_system.rs | 15 ++++++++++++--- src/map.rs | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/damage_system.rs b/src/damage_system.rs index eabec95..21d6991 100644 --- a/src/damage_system.rs +++ b/src/damage_system.rs @@ -1,4 +1,5 @@ -use crate::{game_log::GameLog, CombatStats, Name, Player, RunState, SufferDamage}; +use crate::components::{CombatStats, Name, Player, SufferDamage}; +use crate::{game_log::GameLog, Map, Position, RunState}; use specs::prelude::*; pub struct DamageSystem {} @@ -7,13 +8,21 @@ impl<'a> System<'a> for DamageSystem { type SystemData = ( WriteStorage<'a, CombatStats>, WriteStorage<'a, SufferDamage>, + ReadStorage<'a, Position>, + WriteExpect<'a, Map>, + Entities<'a>, ); fn run(&mut self, data: Self::SystemData) { - let (mut stats, mut damage) = data; + let (mut stats, mut damage, positions, mut map, entities) = data; - for (mut stats, damage) in (&mut stats, &damage).join() { + for (entity, mut stats, damage) in (&entities, &mut stats, &damage).join() { stats.hp -= damage.amount.iter().sum::(); + + if let Some(pos) = positions.get(entity) { + let idx = map.xy_idx(pos.x, pos.y); + map.bloodstains.insert(idx); + } } damage.clear(); diff --git a/src/map.rs b/src/map.rs index 4e5211c..22af6f2 100644 --- a/src/map.rs +++ b/src/map.rs @@ -3,6 +3,7 @@ use rltk::{Algorithm2D, BaseMap, Point, RandomNumberGenerator, Rltk, SmallVec, R use serde::{Deserialize, Serialize}; use specs::prelude::*; use std::cmp::{max, min}; +use std::collections::HashSet; pub const MAP_WIDTH: usize = 80; pub const MAP_HEIGHT: usize = 43; @@ -25,6 +26,7 @@ pub struct Map { pub visible_tiles: Vec, pub blocked: Vec, pub depth: i32, + pub bloodstains: HashSet, #[serde(skip_serializing)] #[serde(skip_deserializing)] @@ -100,6 +102,7 @@ impl Map { blocked: vec![false; MAP_COUNT], tile_content: vec![Vec::new(); MAP_COUNT], depth: new_depth, + bloodstains: HashSet::new(), }; const MAX_ROOMS: i32 = 30; @@ -219,6 +222,7 @@ pub fn draw_map(ecs: &World, ctx: &mut Rltk) { if map.revealed_tiles[idx] { let glyph; let mut fg; + let mut bg = RGB::from_f32(0., 0., 0.); match tile { TileType::Floor => { @@ -235,11 +239,16 @@ pub fn draw_map(ecs: &World, ctx: &mut Rltk) { } } - if !map.visible_tiles[idx] { - fg = fg.to_greyscale(); + if map.bloodstains.contains(&idx) { + bg = RGB::from_f32(0.75, 0., 0.); } - ctx.set(x, y, fg, RGB::from_f32(0., 0., 0.), glyph); + if !map.visible_tiles[idx] { + fg = fg.to_greyscale(); + bg = RGB::from_f32(0.,0.,0.); + } + + ctx.set(x, y, fg, bg, glyph); } // Move to the next set of coordinates