From 286be37225b5de1fb438db0a4029fd391b35c13e Mon Sep 17 00:00:00 2001 From: troido Date: Wed, 29 Jan 2020 22:53:06 +0100 Subject: players can no longer walk through walls --- src/room.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/room.rs') diff --git a/src/room.rs b/src/room.rs index c19af37..de179aa 100644 --- a/src/room.rs +++ b/src/room.rs @@ -10,10 +10,15 @@ use specs::{ }; use super::controls::Control; -use super::components::{Position, Visible, Controller}; +use super::components::{Position, Controller}; use super::assemblages::Assemblage; use super::resources::{Size, TopView}; -use super::systems::{Draw, Move, ClearControllers}; +use super::systems::{ + Draw, + Move, + ClearControllers, + MakeFloor +}; @@ -29,18 +34,17 @@ impl <'a, 'b>Room<'a, 'b> { pub fn new(size: (i32, i32)) -> Room<'a, 'b> { let (width, height) = size; let mut world = World::new(); - world.register::(); - world.register::(); - world.register::(); - world.insert(Size(width, height)); - world.insert(TopView{width: width, height: height, cells: HashMap::new()}); + world.insert(Size{width, height}); - let dispatcher = DispatcherBuilder::new() - .with(Move, "move", &[]) + let mut dispatcher = DispatcherBuilder::new() + .with(MakeFloor, "makefloor", &[]) + .with(Move, "move", &["makefloor"]) .with(Draw, "draw", &["move"]) .with(ClearControllers, "clearcontrollers", &["move"]) .build(); + dispatcher.setup(&mut world); + Room { world, dispatcher, @@ -51,8 +55,7 @@ impl <'a, 'b>Room<'a, 'b> { pub fn view(&self) -> (Vec, Vec>) { let tv = &*self.world.fetch::(); - let width = tv.width; - let height = tv.height; + let (width, height) = self.get_size(); let size = width * height; let mut values :Vec = Vec::with_capacity(size as usize); let mut mapping: Vec> = Vec::new(); @@ -84,7 +87,7 @@ impl <'a, 'b>Room<'a, 'b> { } pub fn get_size(&self) -> (i32, i32) { - let Size(width, height) = *self.world.fetch::(); + let Size{width, height} = *self.world.fetch::(); (width, height) } @@ -103,10 +106,6 @@ impl <'a, 'b>Room<'a, 'b> { self.world.delete_entity(ent).expect("player in world does not have entity"); } -// pub fn clear_controls(&mut self){ -// (*self.world.fetch_mut::()).0.clear(); -// } - pub fn control(&mut self, name: String, control: Control){ if let Some(ent) = self.players.get(&name){ let _ = self.world.write_component::().insert(*ent, Controller(control)); -- cgit