Allow doors to be opened

This commit is contained in:
Timothy Warren 2021-12-17 14:23:36 -05:00
parent a2cdf9e4cd
commit 1e969db5b0

View File

@ -4,8 +4,8 @@ use rltk::{Point, Rltk, VirtualKeyCode};
use specs::prelude::*; use specs::prelude::*;
use crate::components::{ use crate::components::{
CombatStats, EntityMoved, HungerClock, HungerState, Item, Monster, Player, Position, Viewshed, BlocksTile, BlocksVisibility, CombatStats, Door, EntityMoved, HungerClock, HungerState, Item,
WantsToMelee, WantsToPickupItem, Monster, Player, Position, Renderable, Viewshed, WantsToMelee, WantsToPickupItem,
}; };
use crate::game_log::GameLog; use crate::game_log::GameLog;
use crate::{Map, RunState, State, TileType}; use crate::{Map, RunState, State, TileType};
@ -19,6 +19,10 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) {
let map = ecs.fetch::<Map>(); let map = ecs.fetch::<Map>();
let mut wants_to_melee = ecs.write_storage::<WantsToMelee>(); let mut wants_to_melee = ecs.write_storage::<WantsToMelee>();
let mut entity_moved = ecs.write_storage::<EntityMoved>(); let mut entity_moved = ecs.write_storage::<EntityMoved>();
let mut doors = ecs.write_storage::<Door>();
let mut blocks_visibility = ecs.write_storage::<BlocksVisibility>();
let mut blocks_movement = ecs.write_storage::<BlocksTile>();
let mut renderables = ecs.write_storage::<Renderable>();
for (entity, _player, pos, viewshed) in for (entity, _player, pos, viewshed) in
(&entities, &players, &mut positions, &mut viewsheds).join() (&entities, &players, &mut positions, &mut viewsheds).join()
@ -44,6 +48,16 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) {
.expect("Add target failed"); .expect("Add target failed");
return; return;
} }
if let Some(door) = doors.get_mut(*potential_target) {
door.open = true;
blocks_visibility.remove(*potential_target);
blocks_movement.remove(*potential_target);
let glyph = renderables.get_mut(*potential_target).unwrap();
glyph.glyph = rltk::to_cp437('/');
viewshed.dirty = true;
}
} }
if !map.blocked[destination_idx] { if !map.blocked[destination_idx] {