player.rs 695 Bytes
Newer Older
1
use crate::colliders;
Rahix's avatar
Rahix committed
2
use crate::components;
Simon Goller's avatar
Simon Goller committed
3
use crate::sprites;
Simon Goller's avatar
Simon Goller committed
4
use crate::svg_loader;
Rahix's avatar
Rahix committed
5

Rahix's avatar
Rahix committed
6
7
use rand::seq::SliceRandom;

Simon Goller's avatar
Simon Goller committed
8
9
10
pub fn create_player(
    world: &mut legion::World,
    level: &svg_loader::SvgLevel,
11
    player: components::Player,
Simon Goller's avatar
Simon Goller committed
12
) -> legion::Entity {
Rahix's avatar
Rahix committed
13
14
15
16
17
    let spawn_locations = level
        .spawnpoints
        .get("player")
        .expect("no player spawns in this map");
    let spawn = spawn_locations.choose(&mut rand::thread_rng()).unwrap();
Simon Goller's avatar
Simon Goller committed
18

19
    world.push((
20
        player,
Rahix's avatar
Rahix committed
21
        components::Position::new(spawn.x, spawn.y),
22
        components::Movable::new(),
23
        colliders::Collider::new_player(50.0),
24
        components::Sprite::new(sprites::Sprite::Player),
25
    ))
Rahix's avatar
Rahix committed
26
}