Implement bloodstains
This commit is contained in:
parent
b1b3105a80
commit
a198fe1832
@ -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::<i32>();
|
||||
|
||||
if let Some(pos) = positions.get(entity) {
|
||||
let idx = map.xy_idx(pos.x, pos.y);
|
||||
map.bloodstains.insert(idx);
|
||||
}
|
||||
}
|
||||
|
||||
damage.clear();
|
||||
|
15
src/map.rs
15
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<bool>,
|
||||
pub blocked: Vec<bool>,
|
||||
pub depth: i32,
|
||||
pub bloodstains: HashSet<usize>,
|
||||
|
||||
#[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
|
||||
|
Loading…
Reference in New Issue
Block a user