fix stopwatch
This commit is contained in:
parent
6e7313a509
commit
30c7679af5
11
src/main.rs
11
src/main.rs
@ -92,7 +92,7 @@ fn main() {
|
||||
mark_box,
|
||||
markflip_box,
|
||||
))
|
||||
.add_systems(OnEnter(GameState::Start), (despawn_boxes.before(draw_boxes), draw_boxes))
|
||||
.add_systems(OnEnter(GameState::Start), (despawn_boxes, draw_boxes).chain())
|
||||
.add_systems(OnEnter(GameState::Fail), draw_fail)
|
||||
.add_systems(OnEnter(GameState::Win), draw_win)
|
||||
.run();
|
||||
@ -103,7 +103,7 @@ fn despawn_boxes(
|
||||
boxes: Query<Entity, With<Box>>,
|
||||
) {
|
||||
for e in boxes.iter() {
|
||||
commands.entity(e).despawn();
|
||||
commands.entity(e).despawn_recursive();
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,6 +111,8 @@ fn despawn_boxes(
|
||||
fn load_initial_entities(
|
||||
mut commands: Commands,
|
||||
) {
|
||||
let mut stopwatch = Stopwatch::new();
|
||||
stopwatch.pause();
|
||||
commands.spawn((
|
||||
// Accepts a `String` or any type that converts into a `String`, such as `&str`
|
||||
Text::new("0"),
|
||||
@ -125,7 +127,7 @@ fn load_initial_entities(
|
||||
right: Val::Percent(50.),
|
||||
..default()
|
||||
},
|
||||
GameStopwatch(Stopwatch::new()),
|
||||
GameStopwatch(stopwatch),
|
||||
));
|
||||
|
||||
}
|
||||
@ -153,6 +155,7 @@ fn switch_to_win(
|
||||
fn draw_win(
|
||||
mut commands: Commands,
|
||||
mut game_stopwatch: Query<&mut GameStopwatch>,
|
||||
mut next_state: ResMut<NextState<GameState>>,
|
||||
) {
|
||||
let mut stopwatch = game_stopwatch.single_mut();
|
||||
stopwatch.0.pause();
|
||||
@ -171,6 +174,7 @@ fn draw_win(
|
||||
..default()
|
||||
},
|
||||
));
|
||||
next_state.set(GameState::Start);
|
||||
}
|
||||
fn draw_fail(
|
||||
mut commands: Commands,
|
||||
@ -326,6 +330,7 @@ fn init_mines(
|
||||
}
|
||||
}
|
||||
game_stopwatch.single_mut().0.reset();
|
||||
game_stopwatch.single_mut().0.unpause();
|
||||
next_state.set(GameState::Playing);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user