diff options
author | Orangerot <purple@orangerot.dev> | 2025-01-14 18:09:58 +0100 |
---|---|---|
committer | Orangerot <purple@orangerot.dev> | 2025-01-14 18:09:58 +0100 |
commit | deab0ecfaff91a7027d9d31475c0b59dc6611d2f (patch) | |
tree | 09cb8a3c04451b1947146ac952c0ebe02d4fa76d /lib/screens/level.dart | |
parent | ff0517d435e5a44f8e6c5fbde1081dd4c1029519 (diff) |
Diffstat (limited to 'lib/screens/level.dart')
-rw-r--r-- | lib/screens/level.dart | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/lib/screens/level.dart b/lib/screens/level.dart index a22c237..000c43c 100644 --- a/lib/screens/level.dart +++ b/lib/screens/level.dart @@ -20,7 +20,7 @@ class Level extends StatefulWidget { } class _LevelState extends State<Level> with SingleTickerProviderStateMixin { - final player = AudioPlayer(); + final _player = AudioPlayer(); bool _isPlaying = true; Duration? _duration; Duration? _position; @@ -30,11 +30,11 @@ class _LevelState extends State<Level> with SingleTickerProviderStateMixin { StreamSubscription? _buttonSubscription; final FocusNode _focusNode = FocusNode(); - InputDirection inputDirection = InputDirection(); + final InputDirection _inputDirection = InputDirection(); - String hitOrMissMessage = 'Play!'; + String _hitOrMissMessage = 'Play!'; - List<Note> notes = []; + final List<Note> _notes = []; late AnimationController _animationController; late Animation<double> _animation; @@ -62,12 +62,12 @@ class _LevelState extends State<Level> with SingleTickerProviderStateMixin { _animationController.forward(); // Use initial values from player - player.getDuration().then( + _player.getDuration().then( (value) => setState(() { _duration = value; }), ); - player.getCurrentPosition().then( + _player.getCurrentPosition().then( (value) => setState(() { _position = value; }), @@ -75,24 +75,24 @@ class _LevelState extends State<Level> with SingleTickerProviderStateMixin { // listen for new values from player _durationSubscription = - player.onDurationChanged.listen((Duration duration) { + _player.onDurationChanged.listen((Duration duration) { setState(() => _duration = duration); }); _positionSubscription = - player.onPositionChanged.listen((Duration position) { + _player.onPositionChanged.listen((Duration position) { setState(() => _position = position); - for (final note in notes) { + for (final note in _notes) { _noteHitCheck(note, position); } }); // go to GameOverStats when level finishes - player.onPlayerComplete.listen((void _) { + _player.onPlayerComplete.listen((void _) { Route route = MaterialPageRoute( builder: (context) => GameOverStats( simfile: widget.simfile, - notes: notes, + notes: _notes, )); Navigator.pushReplacement(context, route); }); @@ -112,10 +112,10 @@ class _LevelState extends State<Level> with SingleTickerProviderStateMixin { if (arrowIndex < 0 || arrowIndex > 3) { return; } - notes.add(Note(time: time, direction: ArrowDirection.values[arrowIndex])); + _notes.add(Note(time: time, direction: ArrowDirection.values[arrowIndex])); }); - player.play(DeviceFileSource(widget.simfile.audioPath!)); + _player.play(DeviceFileSource(widget.simfile.audioPath!)); } @override @@ -124,19 +124,19 @@ class _LevelState extends State<Level> with SingleTickerProviderStateMixin { _durationSubscription?.cancel(); _positionSubscription?.cancel(); _buttonSubscription?.cancel(); - player.dispose(); + _player.dispose(); super.dispose(); } /// toggle between pause and resume void _pauseResume() { if (_isPlaying) { - player.pause(); + _player.pause(); setState(() { _isPlaying = false; }); } else { - player.resume(); + _player.resume(); setState(() { _isPlaying = true; }); @@ -155,25 +155,25 @@ class _LevelState extends State<Level> with SingleTickerProviderStateMixin { // combine keyboard and esense input InputDirection esenseDirection = ESenseInput.instance.getInputDirection(note.direction); - inputDirection.up |= esenseDirection.up; - inputDirection.down |= esenseDirection.down; - inputDirection.left |= esenseDirection.left; - inputDirection.right |= esenseDirection.right; + _inputDirection.up |= esenseDirection.up; + _inputDirection.down |= esenseDirection.down; + _inputDirection.left |= esenseDirection.left; + _inputDirection.right |= esenseDirection.right; // check if input matches arrow direction bool keypressCorrect = false; switch (note.direction) { case ArrowDirection.up: - keypressCorrect = inputDirection.up; + keypressCorrect = _inputDirection.up; break; case ArrowDirection.down: - keypressCorrect = inputDirection.down; + keypressCorrect = _inputDirection.down; break; case ArrowDirection.right: - keypressCorrect = inputDirection.right; + keypressCorrect = _inputDirection.right; break; case ArrowDirection.left: - keypressCorrect = inputDirection.left; + keypressCorrect = _inputDirection.left; break; } if (keypressCorrect) { @@ -181,9 +181,9 @@ class _LevelState extends State<Level> with SingleTickerProviderStateMixin { note.wasHit = true; _animationController.reset(); _animationController.forward(); - inputDirection.reset(); + _inputDirection.reset(); setState(() { - hitOrMissMessage = 'Great!'; + _hitOrMissMessage = 'Great!'; }); } } else if (note.position < -0.5 * 1.0 / 60.0) { @@ -191,9 +191,9 @@ class _LevelState extends State<Level> with SingleTickerProviderStateMixin { note.wasHit = false; _animationController.reset(); _animationController.forward(); - inputDirection.reset(); + _inputDirection.reset(); setState(() { - hitOrMissMessage = 'Missed'; + _hitOrMissMessage = 'Missed'; }); } } @@ -210,16 +210,16 @@ class _LevelState extends State<Level> with SingleTickerProviderStateMixin { } switch (event.logicalKey) { case LogicalKeyboardKey.arrowUp: - inputDirection.up = isDown; + _inputDirection.up = isDown; break; case LogicalKeyboardKey.arrowDown: - inputDirection.down = isDown; + _inputDirection.down = isDown; break; case LogicalKeyboardKey.arrowLeft: - inputDirection.left = isDown; + _inputDirection.left = isDown; break; case LogicalKeyboardKey.arrowRight: - inputDirection.right = isDown; + _inputDirection.right = isDown; break; } } @@ -254,7 +254,7 @@ class _LevelState extends State<Level> with SingleTickerProviderStateMixin { )), ), body: Stack(children: [ - Arrows(notes: notes), + Arrows(notes: _notes), Positioned( top: 50, width: MediaQuery.of(context).size.width, @@ -262,7 +262,7 @@ class _LevelState extends State<Level> with SingleTickerProviderStateMixin { child: FadeTransition( opacity: _animation, child: Text( - hitOrMissMessage, + _hitOrMissMessage, textScaler: TextScaler.linear(4), textAlign: TextAlign.center, ), |