diff --git a/src/player.rs b/src/player.rs index 1e9255e..b7d658d 100644 --- a/src/player.rs +++ b/src/player.rs @@ -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::(); let mut wants_to_melee = ecs.write_storage::(); let mut entity_moved = ecs.write_storage::(); + let mut doors = ecs.write_storage::(); + let mut blocks_visibility = ecs.write_storage::(); + let mut blocks_movement = ecs.write_storage::(); + let mut renderables = ecs.write_storage::(); 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] {