feat: show whether you hit or missed the beat

This commit is contained in:
Orangerot 2024-12-29 19:15:16 +01:00
parent f577670d75
commit acebb2431c
2 changed files with 16 additions and 5 deletions

View file

@ -15,7 +15,7 @@ class Note {
final double time;
final ArrowDirection direction;
double position = 0;
bool wasHit = false;
bool? wasHit;
Note({required this.time, required this.direction});
}

View file

@ -78,8 +78,10 @@ class _LevelState extends State<Level> {
setState(() => _position = p);
for (final note in notes) {
note.position = note.time - p.inMilliseconds / 60000.0;
if (!note.wasHit && note.position.abs() < 0.5 * 1.0 / 60.0) {
if (note.wasHit != null) {
continue;
}
if (note.position.abs() < 0.5 * 1.0 / 60.0) {
bool keypressCorrect = false;
switch (note.direction) {
case ArrowDirection.up:
@ -101,11 +103,20 @@ class _LevelState extends State<Level> {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('This is a toast message'),
duration: Duration(seconds: 2),
content: Text('Great!'),
duration: Duration(milliseconds: 500),
),
);
}
} else if (note.position < -0.5 * 1.0 / 60.0) {
print("Missed");
note.wasHit = false;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Missed!'),
duration: Duration(milliseconds: 500),
),
);
}
}
});