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,
|
mark_box,
|
||||||
markflip_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::Fail), draw_fail)
|
||||||
.add_systems(OnEnter(GameState::Win), draw_win)
|
.add_systems(OnEnter(GameState::Win), draw_win)
|
||||||
.run();
|
.run();
|
||||||
@ -103,7 +103,7 @@ fn despawn_boxes(
|
|||||||
boxes: Query<Entity, With<Box>>,
|
boxes: Query<Entity, With<Box>>,
|
||||||
) {
|
) {
|
||||||
for e in boxes.iter() {
|
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(
|
fn load_initial_entities(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
) {
|
) {
|
||||||
|
let mut stopwatch = Stopwatch::new();
|
||||||
|
stopwatch.pause();
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
// Accepts a `String` or any type that converts into a `String`, such as `&str`
|
// Accepts a `String` or any type that converts into a `String`, such as `&str`
|
||||||
Text::new("0"),
|
Text::new("0"),
|
||||||
@ -125,7 +127,7 @@ fn load_initial_entities(
|
|||||||
right: Val::Percent(50.),
|
right: Val::Percent(50.),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
GameStopwatch(Stopwatch::new()),
|
GameStopwatch(stopwatch),
|
||||||
));
|
));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -153,6 +155,7 @@ fn switch_to_win(
|
|||||||
fn draw_win(
|
fn draw_win(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut game_stopwatch: Query<&mut GameStopwatch>,
|
mut game_stopwatch: Query<&mut GameStopwatch>,
|
||||||
|
mut next_state: ResMut<NextState<GameState>>,
|
||||||
) {
|
) {
|
||||||
let mut stopwatch = game_stopwatch.single_mut();
|
let mut stopwatch = game_stopwatch.single_mut();
|
||||||
stopwatch.0.pause();
|
stopwatch.0.pause();
|
||||||
@ -171,6 +174,7 @@ fn draw_win(
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
next_state.set(GameState::Start);
|
||||||
}
|
}
|
||||||
fn draw_fail(
|
fn draw_fail(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
@ -326,6 +330,7 @@ fn init_mines(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
game_stopwatch.single_mut().0.reset();
|
game_stopwatch.single_mut().0.reset();
|
||||||
|
game_stopwatch.single_mut().0.unpause();
|
||||||
next_state.set(GameState::Playing);
|
next_state.set(GameState::Playing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user