2020-07-23 18:12:52 -04:00
|
|
|
use crate::components::*;
|
2020-07-23 21:24:36 -04:00
|
|
|
use specs::{Builder, World, WorldExt, EntityBuilder};
|
2020-07-23 18:12:52 -04:00
|
|
|
|
2020-07-23 21:24:36 -04:00
|
|
|
/// Cut down on the common syntax boilerplate
|
|
|
|
fn common_entity<'w>(world: &'w mut World, position: Position, z: u8, sprite_path: &str) -> EntityBuilder<'w> {
|
|
|
|
return world
|
2020-07-23 18:12:52 -04:00
|
|
|
.create_entity()
|
2020-07-24 14:55:49 -04:00
|
|
|
.with(position.with_z(z))
|
2020-07-23 21:24:36 -04:00
|
|
|
.with(Renderable { path: sprite_path.to_string() });
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create_wall(world: &mut World, position: Position) {
|
|
|
|
common_entity(world, position, 10, "/images/wall.png")
|
2020-07-23 18:12:52 -04:00
|
|
|
.with(Wall {})
|
|
|
|
.with(Immovable)
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create_floor(world: &mut World, position: Position) {
|
2020-07-23 21:24:36 -04:00
|
|
|
common_entity(world, position, 5, "/images/floor.png").build();
|
2020-07-23 18:12:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create_box(world: &mut World, position: Position) {
|
2020-07-23 21:24:36 -04:00
|
|
|
common_entity(world, position, 10, "/images/box.png")
|
2020-07-23 18:12:52 -04:00
|
|
|
.with(Box {})
|
|
|
|
.with(Movable)
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create_box_spot(world: &mut World, position: Position) {
|
2020-07-23 21:24:36 -04:00
|
|
|
common_entity(world, position, 9, "/images/box_spot.png")
|
2020-07-23 18:12:52 -04:00
|
|
|
.with(BoxSpot {})
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create_player(world: &mut World, position: Position) {
|
2020-07-23 21:24:36 -04:00
|
|
|
common_entity(world, position, 10, "/images/player.png")
|
2020-07-23 18:12:52 -04:00
|
|
|
.with(Player {})
|
|
|
|
.with(Movable)
|
|
|
|
.build();
|
|
|
|
}
|