Skip to content

Commit

Permalink
Update GameSettings on endgame
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmauro committed Apr 1, 2024
1 parent 5e7cf65 commit ffbb261
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/game/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ fn end_of_round_system(
}

fn end_of_game_system(
mut settings: ResMut<GameSettings>,
mut scores: ResMut<LatestGameScores>,
mut app_state: ResMut<NextState<AppState>>,
query: Query<(&CueEngine, &Round, &CueTimer, &mut Score)>,
Expand All @@ -319,9 +320,17 @@ fn end_of_game_system(
round_duration: timer.0.duration().as_secs_f32(),
correct: score.correct(),
wrong: score.wrong(),
f1_score: score.f1_score(),
f1_score_percent: score.f1_score_percent(),
});

if score.f1_score_percent() >= 80 {
settings.n += 1;
settings.rounds = 20 + settings.n.pow(2);
} else if score.f1_score_percent() <= 50 {
settings.n = settings.n.max(1);
settings.rounds = 20 + settings.n.pow(2);
}

app_state.set(AppState::Menu);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct GameScore {
pub round_duration: f32,
pub correct: usize,
pub wrong: usize,
pub f1_score: f32,
pub f1_score_percent: usize,
}

#[derive(Default, Resource)]
Expand Down
4 changes: 2 additions & 2 deletions src/game/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ impl Default for GameSettings {
fn default() -> Self {
Self {
n: 2,
rounds: 10,
round_time: 2.0,
rounds: 24,
round_time: 3.0,
}
}
}
2 changes: 1 addition & 1 deletion src/menu/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn menu_ui(
"{:.2}s",
score.total_rounds as f32 * score.round_duration
));
cols[3].label(format!("{}%", (score.f1_score * 100.0) as usize));
cols[3].label(format!("{}%", score.f1_score_percent));
});
}
});
Expand Down

0 comments on commit ffbb261

Please sign in to comment.