obstacle.rs 747 Bytes
Newer Older
Grisu's avatar
Grisu committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use crate::colliders;
use crate::components;
use crate::svg_loader;
use rand::seq::SliceRandom;

pub fn create_stationary_obstacles(world: &mut legion::World, level: &svg_loader::SvgLevel) {
    let spawn_locations = level
        .spawnpoints
        .get("stationary_obstacle_type_1")
        .map_or(&[][..], |x| &x[..]);
    for obs in spawn_locations.choose_multiple(&mut rand::thread_rng(), 3) {
        let orientation = *[true, false].choose(&mut rand::thread_rng()).unwrap();
        let new_obs = components::Obstacle::new(orientation);
        world.push((
            new_obs,
            components::Position::new(obs.x, obs.y),
            colliders::Collider::new_static_rect(new_obs.width(), new_obs.height()),
        ));
    }
}