diff options
author | Orangerot <purple@orangerot.dev> | 2024-12-29 19:15:16 +0100 |
---|---|---|
committer | Orangerot <purple@orangerot.dev> | 2024-12-29 19:15:16 +0100 |
commit | acebb2431c43108167a073e889a61147cc526edd (patch) | |
tree | 34d90aa629058bee534bafe3997481a5f6b990b8 | |
parent | f577670d7564b24dfe8cc247459670a2d7ef5bab (diff) |
feat: show whether you hit or missed the beat
-rw-r--r-- | lib/arrows.dart | 2 | ||||
-rw-r--r-- | lib/level.dart | 19 |
2 files changed, 16 insertions, 5 deletions
diff --git a/lib/arrows.dart b/lib/arrows.dart index b4779f7..ff53e02 100644 --- 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 index a6d4967..aa042f4 100644 --- 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), + ), + ); } } }); |