commit acebb2431c43108167a073e889a61147cc526edd
parent f577670d7564b24dfe8cc247459670a2d7ef5bab
Author: Orangerot <purple@orangerot.dev>
Date: Sun, 29 Dec 2024 19:15:16 +0100
feat: show whether you hit or missed the beat
Diffstat:
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/lib/arrows.dart b/lib/arrows.dart
@@ -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});
}
diff --git a/lib/level.dart b/lib/level.dart
@@ -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),
+ ),
+ );
}
}
});