bin-projekt/src/scene.rs
2024-05-08 18:55:19 +02:00

43 lines
1.3 KiB
Rust

use bevy::{
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
use bevy_rapier2d::prelude::*;
use crate::METER;
#[derive(Component)]
pub struct Wall;
pub fn setup_scene(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
let scene_objs = [
// Arena walls
(Rectangle::new(16. * METER, METER), (0., 7.5 * METER)),
(Rectangle::new(16. * METER, METER), (0., -7.5 * METER)),
(Rectangle::new(METER, 16. * METER), (7.5 * METER, 0.)),
(Rectangle::new(METER, 16. * METER), (-7.5 * METER, 0.)),
(Rectangle::new(8. * METER, METER), (0., 2. * METER)),
(Rectangle::new(1. * METER, 2. * METER), (2. * METER, 0.)),
(Rectangle::new(8. * METER, METER), (0., -2. * METER)),
];
for (shape_, pos) in scene_objs {
let shape = Mesh2dHandle(meshes.add(shape_));
commands
.spawn(Wall)
.insert(MaterialMesh2dBundle {
mesh: shape,
material: materials.add(Color::rgb(1., 0., 0.)),
transform: Transform::from_xyz(pos.0, pos.1, 1.),
..default()
})
.insert((
RigidBody::Fixed,
Collider::cuboid(shape_.half_size.x, shape_.half_size.y),
));
}
}