2020-07-24 17:55:38 -04:00
|
|
|
use crate::components::{BoxColor, Position};
|
2020-07-23 18:12:52 -04:00
|
|
|
use crate::entities::*;
|
|
|
|
use specs::World;
|
|
|
|
|
|
|
|
pub fn load_map(world: &mut World, map_string: String) {
|
|
|
|
// read all lines
|
|
|
|
let rows: Vec<&str> = map_string.trim().split('\n').map(|x| x.trim()).collect();
|
|
|
|
|
|
|
|
for (y, row) in rows.iter().enumerate() {
|
|
|
|
let columns: Vec<&str> = row.split(' ').collect();
|
|
|
|
|
|
|
|
for (x, column) in columns.iter().enumerate() {
|
|
|
|
// Create the position at which to create something on the map
|
|
|
|
let position = Position::new(x as u8, y as u8);
|
|
|
|
|
|
|
|
// Figure out which object to create
|
|
|
|
match *column {
|
|
|
|
"." => create_floor(world, position),
|
|
|
|
"W" => {
|
|
|
|
create_floor(world, position);
|
|
|
|
create_wall(world, position);
|
|
|
|
}
|
|
|
|
"P" => {
|
|
|
|
create_floor(world, position);
|
|
|
|
create_player(world, position);
|
|
|
|
}
|
2020-07-24 17:55:38 -04:00
|
|
|
"BB" => {
|
2020-07-23 18:12:52 -04:00
|
|
|
create_floor(world, position);
|
2020-07-24 17:55:38 -04:00
|
|
|
create_box(world, position, BoxColor::Blue);
|
2020-07-23 18:12:52 -04:00
|
|
|
}
|
2020-07-24 17:55:38 -04:00
|
|
|
"RB" => {
|
2020-07-23 18:12:52 -04:00
|
|
|
create_floor(world, position);
|
2020-07-24 17:55:38 -04:00
|
|
|
create_box(world, position, BoxColor::Red);
|
|
|
|
}
|
|
|
|
"BS" => {
|
|
|
|
create_floor(world, position);
|
|
|
|
create_box_spot(world, position, BoxColor::Blue);
|
|
|
|
}
|
|
|
|
"RS" => {
|
|
|
|
create_floor(world, position);
|
|
|
|
create_box_spot(world, position, BoxColor::Red);
|
2020-07-23 18:12:52 -04:00
|
|
|
}
|
|
|
|
"N" => (),
|
|
|
|
c => panic!("unrecognized map item {}", c),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|