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 double time;
final ArrowDirection direction; final ArrowDirection direction;
double position = 0; double position = 0;
bool wasHit = false; bool? wasHit;
Note({required this.time, required this.direction}); Note({required this.time, required this.direction});
} }

View file

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