generated from 2ndbeam/bevy-template
feat: Added BeatMap accuracy
This commit is contained in:
parent
6e1ab7d860
commit
f5eb328ea8
1 changed files with 17 additions and 3 deletions
20
src/main.rs
20
src/main.rs
|
|
@ -52,13 +52,21 @@ impl Beat {
|
||||||
struct BeatMap(Vec<Beat>);
|
struct BeatMap(Vec<Beat>);
|
||||||
|
|
||||||
impl BeatMap {
|
impl BeatMap {
|
||||||
fn beat_length(&self) -> f32 {
|
pub fn beat_length(&self) -> f32 {
|
||||||
let Some(last_beat) = self.0.last() else {
|
let Some(last_beat) = self.0.last() else {
|
||||||
return 0f32;
|
return 0f32;
|
||||||
};
|
};
|
||||||
|
|
||||||
last_beat.position
|
last_beat.position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn accuracy(&self, compared: &BeatMap) -> f32 {
|
||||||
|
let mut total_accuracy = 1f32;
|
||||||
|
for i in 0..self.0.len() {
|
||||||
|
total_accuracy *= self.0[i].accuracy(&compared.0[i]);
|
||||||
|
}
|
||||||
|
total_accuracy
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource, Debug)]
|
#[derive(Resource, Debug)]
|
||||||
|
|
@ -187,8 +195,14 @@ fn handle_input(
|
||||||
if bm.beatmaps["test"].0.len() > last_index {
|
if bm.beatmaps["test"].0.len() > last_index {
|
||||||
let accuracy = bm.beatmaps["test"].0[last_index].accuracy(bm.input.0.last().unwrap());
|
let accuracy = bm.beatmaps["test"].0[last_index].accuracy(bm.input.0.last().unwrap());
|
||||||
println!("accuracy: {}%", accuracy * 100f32);
|
println!("accuracy: {}%", accuracy * 100f32);
|
||||||
} else {
|
}
|
||||||
println!("accuracy: 0%; too much beats!");
|
if bm.beatmaps["test"].0.len() == bm.input.0.len() {
|
||||||
|
let total_accuracy = bm.beatmaps["test"].accuracy(&bm.input);
|
||||||
|
println!("sequence completed, total accuracy: {}%", total_accuracy * 100f32);
|
||||||
|
if total_accuracy >= 0.85 {
|
||||||
|
println!("accuracy > 85%; imagine like something happened");
|
||||||
|
}
|
||||||
|
bm.input.0.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue