Spawn platforms function
This commit is contained in:
parent
10abb0a676
commit
e7f2188091
5 changed files with 125 additions and 47 deletions
52
src/game.rs
52
src/game.rs
|
|
@ -171,6 +171,37 @@ pub fn spawn_character(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn spawn_platforms<I: IntoIterator<Item = (Transform, Vec2)>>(
|
||||
commands: &mut Commands,
|
||||
meshes: &mut ResMut<Assets<Mesh>>,
|
||||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
||||
|
||||
platforms: I,
|
||||
) {
|
||||
for (transform, size) in platforms.into_iter() {
|
||||
spawn_platform(commands, meshes, materials, transform, size);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_platform(
|
||||
commands: &mut Commands,
|
||||
meshes: &mut ResMut<Assets<Mesh>>,
|
||||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
||||
|
||||
transform: Transform,
|
||||
size: Vec2,
|
||||
) {
|
||||
commands
|
||||
.spawn_bundle(ColorMesh2dBundle {
|
||||
mesh: meshes.add(Mesh::from(Quad { size, flip: false })).into(),
|
||||
material: materials.add(ColorMaterial::from(Color::GRAY)),
|
||||
transform,
|
||||
..default()
|
||||
})
|
||||
.insert(Collider::cuboid(size.x / 2., size.y / 2.))
|
||||
.insert(Level);
|
||||
}
|
||||
|
||||
fn collision_event_system(
|
||||
mut commands: Commands,
|
||||
character_meshes: Res<CharacterMeshes>,
|
||||
|
|
@ -325,8 +356,26 @@ fn character_particle_effect_system(
|
|||
}
|
||||
}
|
||||
|
||||
fn win_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
fn win_setup(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
asset_server: Res<AssetServer>,
|
||||
) {
|
||||
let font = asset_server.get_handle("UacariLegacy-Thin.ttf");
|
||||
commands
|
||||
.spawn_bundle(ColorMesh2dBundle {
|
||||
mesh: meshes
|
||||
.add(Mesh::from(Quad {
|
||||
size: Vec2 { x: 512., y: 64. },
|
||||
flip: false,
|
||||
}))
|
||||
.into(),
|
||||
material: materials.add(ColorMaterial::from(Color::rgba(0., 0., 0., 0.9))),
|
||||
transform: Transform::from_xyz(0., 0., 3.),
|
||||
..default()
|
||||
})
|
||||
.insert(Level);
|
||||
commands
|
||||
.spawn_bundle(Text2dBundle {
|
||||
text: Text::from_section(
|
||||
|
|
@ -338,6 +387,7 @@ fn win_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
},
|
||||
)
|
||||
.with_alignment(TextAlignment::CENTER),
|
||||
transform: Transform::from_xyz(0., 0., 4.),
|
||||
..Default::default()
|
||||
})
|
||||
.insert(Level);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue