Add chapter: 17

This commit is contained in:
Kasper Juul Hermansen 2022-01-28 20:20:04 +01:00
parent 743bf7abde
commit 0e2c91dd12
Signed by: kjuulh
GPG Key ID: DCD9397082D97069
3 changed files with 22 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
use rltk::console;
use specs::prelude::*;
use crate::{Name, RunState};
use crate::{Map, Name, Position, RunState};
use crate::components::{CombatStats, Player, SufferDamage};
use crate::gamelog::GameLog;
@ -11,13 +11,20 @@ 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();

View File

@ -1,4 +1,5 @@
use std::cmp::{max, min};
use std::collections::HashSet;
use rltk::{Algorithm2D, BaseMap, FontCharType, Point, RandomNumberGenerator, RGB, Rltk};
use serde::{Deserialize, Serialize};
@ -28,6 +29,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)]
@ -97,6 +99,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;
@ -207,6 +210,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 => {
fg = RGB::from_f32(0.0, 0.5, 0.5);
@ -223,10 +227,14 @@ pub fn draw_map(ecs: &World, ctx: &mut Rltk) {
fg = RGB::from_f32(0., 1., 1.);
}
}
if !map.visible_tiles[idx] {
fg = fg.to_greyscale()
if map.bloodstains.contains(&idx) {
bg = RGB::from_f32(0.71, 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);
}
x += 1;