Reset example
This commit is contained in:
parent
a9e80d6df9
commit
32fe7580f3
16
src/ui.rs
16
src/ui.rs
@ -4,7 +4,6 @@ use bevy::{
|
||||
prelude::*,
|
||||
sprite::collide_aabb::{collide, Collision},
|
||||
sprite::MaterialMesh2dBundle,
|
||||
app::CoreSchedule,
|
||||
};
|
||||
|
||||
// Defines the amount of time that should elapse between each physics step.
|
||||
@ -54,7 +53,7 @@ const SCORE_COLOR: Color = Color::rgb(1.0, 0.5, 0.5);
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.insert_resource(StatusCounter { size: 0, fd: 0.0 })
|
||||
.insert_resource(Scoreboard { score: 0 })
|
||||
.insert_resource(ClearColor(BACKGROUND_COLOR))
|
||||
.add_startup_system(setup)
|
||||
.add_event::<CollisionEvent>()
|
||||
@ -172,9 +171,8 @@ impl WallBundle {
|
||||
|
||||
// This resource tracks the game's score
|
||||
#[derive(Resource)]
|
||||
struct StatusCounter {
|
||||
size: usize,
|
||||
fd: f32,
|
||||
struct Scoreboard {
|
||||
score: usize,
|
||||
}
|
||||
|
||||
// Add the game's entities to our world
|
||||
@ -350,14 +348,14 @@ fn apply_velocity(mut query: Query<(&mut Transform, &Velocity)>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn update_scoreboard(scoreboard: Res<StatusCounter>, mut query: Query<&mut Text>) {
|
||||
fn update_scoreboard(scoreboard: Res<Scoreboard>, mut query: Query<&mut Text>) {
|
||||
let mut text = query.single_mut();
|
||||
text.sections[1].value = scoreboard.size.to_string();
|
||||
text.sections[1].value = scoreboard.score.to_string();
|
||||
}
|
||||
|
||||
fn check_for_collisions(
|
||||
mut commands: Commands,
|
||||
mut scoreboard: ResMut<StatusCounter>,
|
||||
mut scoreboard: ResMut<Scoreboard>,
|
||||
mut ball_query: Query<(&mut Velocity, &Transform), With<Ball>>,
|
||||
collider_query: Query<(Entity, &Transform, Option<&Brick>), With<Collider>>,
|
||||
mut collision_events: EventWriter<CollisionEvent>,
|
||||
@ -379,7 +377,7 @@ fn check_for_collisions(
|
||||
|
||||
// Bricks should be despawned and increment the scoreboard on collision
|
||||
if maybe_brick.is_some() {
|
||||
scoreboard.size += 1;
|
||||
scoreboard.score += 1;
|
||||
commands.entity(collider_entity).despawn();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user