basic bloodstains
TODO: coloured by entity bleed colour[?]
This commit is contained in:
parent
65d728b75a
commit
9d01ab220d
3 changed files with 30 additions and 7 deletions
|
|
@ -1,16 +1,27 @@
|
||||||
use super::{gamelog::GameLog, CombatStats, Name, Player, SufferDamage};
|
use super::{gamelog::GameLog, CombatStats, Entities, Map, Name, Player, Position, SufferDamage};
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
|
|
||||||
pub struct DamageSystem {}
|
pub struct DamageSystem {}
|
||||||
|
|
||||||
impl<'a> System<'a> for DamageSystem {
|
impl<'a> System<'a> for DamageSystem {
|
||||||
type SystemData = (WriteStorage<'a, CombatStats>, WriteStorage<'a, SufferDamage>);
|
type SystemData = (
|
||||||
|
WriteStorage<'a, CombatStats>,
|
||||||
|
WriteStorage<'a, SufferDamage>,
|
||||||
|
WriteExpect<'a, Map>,
|
||||||
|
ReadStorage<'a, Position>,
|
||||||
|
Entities<'a>,
|
||||||
|
);
|
||||||
|
|
||||||
fn run(&mut self, data: Self::SystemData) {
|
fn run(&mut self, data: Self::SystemData) {
|
||||||
let (mut stats, mut damage) = data;
|
let (mut stats, mut damage, mut map, positions, 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>();
|
stats.hp -= damage.amount.iter().sum::<i32>();
|
||||||
|
let pos = positions.get(entity);
|
||||||
|
if let Some(pos) = pos {
|
||||||
|
let idx = map.xy_idx(pos.x, pos.y);
|
||||||
|
map.bloodstains.insert(idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
damage.clear();
|
damage.clear();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use rltk::{GameState, Point, Rltk};
|
use rltk::{GameState, Point, Rltk, RGB};
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
|
|
||||||
mod components;
|
mod components;
|
||||||
|
|
@ -82,8 +82,12 @@ impl GameState for State {
|
||||||
data.sort_by(|&a, &b| b.1.render_order.cmp(&a.1.render_order));
|
data.sort_by(|&a, &b| b.1.render_order.cmp(&a.1.render_order));
|
||||||
for (pos, render) in data.iter() {
|
for (pos, render) in data.iter() {
|
||||||
let idx = map.xy_idx(pos.x, pos.y);
|
let idx = map.xy_idx(pos.x, pos.y);
|
||||||
|
let mut bg = render.bg;
|
||||||
|
if map.bloodstains.contains(&idx) {
|
||||||
|
bg = RGB::from_f32(0.4, 0., 0.);
|
||||||
|
}
|
||||||
if map.visible_tiles[idx] {
|
if map.visible_tiles[idx] {
|
||||||
ctx.set(pos.x, pos.y, render.fg, render.bg, render.glyph);
|
ctx.set(pos.x, pos.y, render.fg, bg, render.glyph);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gui::draw_ui(&self.ecs, ctx);
|
gui::draw_ui(&self.ecs, ctx);
|
||||||
|
|
|
||||||
10
src/map.rs
10
src/map.rs
|
|
@ -2,6 +2,7 @@ use super::Rect;
|
||||||
use rltk::{Algorithm2D, BaseMap, Point, RandomNumberGenerator, Rltk, RGB};
|
use rltk::{Algorithm2D, BaseMap, Point, RandomNumberGenerator, Rltk, RGB};
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone)]
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
pub enum TileType {
|
pub enum TileType {
|
||||||
|
|
@ -23,6 +24,7 @@ pub struct Map {
|
||||||
pub visible_tiles: Vec<bool>,
|
pub visible_tiles: Vec<bool>,
|
||||||
pub blocked: Vec<bool>,
|
pub blocked: Vec<bool>,
|
||||||
pub tile_content: Vec<Vec<Entity>>,
|
pub tile_content: Vec<Vec<Entity>>,
|
||||||
|
pub bloodstains: HashSet<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Map {
|
impl Map {
|
||||||
|
|
@ -89,6 +91,7 @@ impl Map {
|
||||||
visible_tiles: vec![false; MAPCOUNT],
|
visible_tiles: vec![false; MAPCOUNT],
|
||||||
blocked: vec![false; MAPCOUNT],
|
blocked: vec![false; MAPCOUNT],
|
||||||
tile_content: vec![Vec::new(); MAPCOUNT],
|
tile_content: vec![Vec::new(); MAPCOUNT],
|
||||||
|
bloodstains: HashSet::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const MAX_ROOMS: i32 = 30;
|
const MAX_ROOMS: i32 = 30;
|
||||||
|
|
@ -198,6 +201,7 @@ pub fn draw_map(ecs: &World, ctx: &mut Rltk) {
|
||||||
if map.revealed_tiles[idx] {
|
if map.revealed_tiles[idx] {
|
||||||
let glyph;
|
let glyph;
|
||||||
let mut fg;
|
let mut fg;
|
||||||
|
let mut bg = RGB::from_f32(0., 0., 0.);
|
||||||
match tile {
|
match tile {
|
||||||
TileType::Floor => {
|
TileType::Floor => {
|
||||||
glyph = rltk::to_cp437('.');
|
glyph = rltk::to_cp437('.');
|
||||||
|
|
@ -208,10 +212,14 @@ pub fn draw_map(ecs: &World, ctx: &mut Rltk) {
|
||||||
fg = RGB::from_f32(0.0, 1.0, 0.0);
|
fg = RGB::from_f32(0.0, 1.0, 0.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if map.bloodstains.contains(&idx) {
|
||||||
|
bg = RGB::from_f32(0.4, 0., 0.);
|
||||||
|
}
|
||||||
if !map.visible_tiles[idx] {
|
if !map.visible_tiles[idx] {
|
||||||
fg = fg.to_greyscale();
|
fg = fg.to_greyscale();
|
||||||
|
bg = bg.desaturate();
|
||||||
}
|
}
|
||||||
ctx.set(x, y, fg, RGB::from_f32(0.0, 0.0, 0.0), glyph);
|
ctx.set(x, y, fg, bg, glyph);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the coordinates
|
// Move the coordinates
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue