diff --git a/src/main.rs b/src/main.rs index 5ff398f..a50f00f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,13 +52,21 @@ impl Beat { struct BeatMap(Vec); impl BeatMap { - fn beat_length(&self) -> f32 { + pub fn beat_length(&self) -> f32 { let Some(last_beat) = self.0.last() else { return 0f32; }; 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)] @@ -187,8 +195,14 @@ fn handle_input( if bm.beatmaps["test"].0.len() > last_index { let accuracy = bm.beatmaps["test"].0[last_index].accuracy(bm.input.0.last().unwrap()); 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;