rust-sokoban/src/entities.rs

50 lines
1.3 KiB
Rust
Raw Normal View History

2020-07-23 18:12:52 -04:00
use crate::components::*;
use specs::{Builder, World, WorldExt};
pub fn create_wall(world: &mut World, position: Position) {
world
.create_entity()
.with(Position { z: 10, ..position })
2020-07-23 20:25:16 -04:00
.with(Renderable::new("/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) {
world
.create_entity()
.with(Position { z: 5, ..position })
2020-07-23 20:25:16 -04:00
.with(Renderable::new("/images/floor.png"))
2020-07-23 18:12:52 -04:00
.build();
}
pub fn create_box(world: &mut World, position: Position) {
world
.create_entity()
.with(Position { z: 10, ..position })
2020-07-23 20:25:16 -04:00
.with(Renderable::new("/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) {
world
.create_entity()
.with(Position { z: 9, ..position })
2020-07-23 20:25:16 -04:00
.with(Renderable::new("/images/box_spot.png"))
2020-07-23 18:12:52 -04:00
.with(BoxSpot {})
.build();
}
pub fn create_player(world: &mut World, position: Position) {
world
.create_entity()
.with(Position { z: 10, ..position })
2020-07-23 20:25:16 -04:00
.with(Renderable::new("/images/player.png"))
2020-07-23 18:12:52 -04:00
.with(Player {})
.with(Movable)
.build();
}