Allow doors to be opened
This commit is contained in:
parent
a2cdf9e4cd
commit
1e969db5b0
@ -4,8 +4,8 @@ use rltk::{Point, Rltk, VirtualKeyCode};
|
||||
use specs::prelude::*;
|
||||
|
||||
use crate::components::{
|
||||
CombatStats, EntityMoved, HungerClock, HungerState, Item, Monster, Player, Position, Viewshed,
|
||||
WantsToMelee, WantsToPickupItem,
|
||||
BlocksTile, BlocksVisibility, CombatStats, Door, EntityMoved, HungerClock, HungerState, Item,
|
||||
Monster, Player, Position, Renderable, Viewshed, WantsToMelee, WantsToPickupItem,
|
||||
};
|
||||
use crate::game_log::GameLog;
|
||||
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 mut wants_to_melee = ecs.write_storage::<WantsToMelee>();
|
||||
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
|
||||
(&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");
|
||||
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] {
|
||||
|
Loading…
Reference in New Issue
Block a user