|
@@ -24,6 +24,13 @@ pub struct MoveLeft;
|
|
|
#[derive(Component)]
|
|
|
pub struct Player;
|
|
|
|
|
|
+impl Player {
|
|
|
+ fn get_entity(world: &mut specs::World) -> Entity {
|
|
|
+ let storage = (&world.read_component::<Player>(), &world.entities());
|
|
|
+ storage.join().next().expect("No entities tagged as Player").1
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#[derive(Component)]
|
|
|
pub struct Motion {
|
|
|
down: i8,
|
|
@@ -31,8 +38,8 @@ pub struct Motion {
|
|
|
}
|
|
|
|
|
|
impl Motion {
|
|
|
- fn move_player(&mut specs::World, down: i8, right: i8) {
|
|
|
- let player = (&world.read_component::<Player>(), &world.entities()).join().next().unwrap().1;
|
|
|
+ fn move_player(world: &mut specs::World, down: i8, right: i8) {
|
|
|
+ let player = Player::get_entity(world);
|
|
|
world.write_component::<Motion>().insert(player, Motion { down, right }).unwrap();
|
|
|
}
|
|
|
}
|