1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! construct the virtual world

use bevy::prelude::*;
use bevy_rapier2d::prelude::*;

use crate::{consts::*, componet::ColliderFlag};

/// wall flag, different from `ColliderFlag`
#[derive(Component)]
pub struct Wall;

pub fn setup_walls(mut commands: Commands) {

    let mut half_window_width = WORLD_WIDTH_SWIM / 2.0;
    let mut half_window_height = WORLD_HEIGHT_SWIM /2.0;
    
    if TRAINING_MODE == "walk" {
        half_window_width = WORLD_WIDTH_WALK / 2.0;
        half_window_height = WORLD_HEIGHT_WALK /2.0;
    }


    // Left wall
    commands.spawn((
        Collider::cuboid(1.0, half_window_height),
        TransformBundle::from_transform(Transform::from_xyz(-half_window_width, 0.0, 0.0)),
        ColliderFlag::WALL,
        Wall
    ));

    // Right wall
    commands.spawn((
        Collider::cuboid(1.0, half_window_height),
        TransformBundle::from_transform(Transform::from_xyz(half_window_width, 0.0, 0.0)),
        ColliderFlag::WALL,
        Wall
    ));

    // Top wall
    commands.spawn((
        Collider::cuboid(half_window_width, 1.0),
        TransformBundle::from_transform(Transform::from_xyz(0.0, half_window_height, 0.0)),
        ColliderFlag::WALL,
        Wall
    ));

    // Bottom wall
    commands.spawn((
        Collider::cuboid(half_window_width, 1.0),
        TransformBundle::from_transform(Transform::from_xyz(0.0, -half_window_height, 0.0)),
        ColliderFlag::WALL,
        Wall
    ));
}