diff --git a/lib/arrows.dart b/lib/arrows.dart deleted file mode 100644 index ff53e02..0000000 --- a/lib/arrows.dart +++ /dev/null @@ -1,57 +0,0 @@ -import 'package:flutter/material.dart'; - -enum ArrowDirection { - left(Icons.arrow_back), - down(Icons.arrow_downward), - up(Icons.arrow_upward), - right(Icons.arrow_forward); - - const ArrowDirection(this.icon); - - final IconData icon; -} - -class Note { - final double time; - final ArrowDirection direction; - double position = 0; - bool? wasHit; - - Note({required this.time, required this.direction}); -} - -class Arrows extends StatelessWidget { - final List notes; - final double position; - - const Arrows({super.key, required this.notes, required this.position}); - - @override - Widget build(BuildContext context) { - return Stack( - children: notes.map((note) { - double position = note.position * 10000; // * 20 * MediaQuery.of(context).size.height; - - return Arrow( - position: position, - direction: note.direction, - ); - }).toList()); - } -} - -class Arrow extends StatelessWidget { - final double position; - final ArrowDirection direction; - - const Arrow({super.key, required this.position, required this.direction}); - - @override - Widget build(BuildContext context) { - return Positioned( - left: MediaQuery.of(context).size.width / 2 - 50, // Center the arrow - bottom: position + 50, - child: Icon(size: 100, color: Colors.redAccent.shade400, direction.icon), - ); - } -} diff --git a/lib/main.dart b/lib/main.dart index eb01d44..85443bb 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import 'level_selection.dart'; +import 'package:sense_the_rhythm/screens/level_selection.dart'; void main() { runApp(const MyApp()); diff --git a/lib/models/arrow_direction.dart b/lib/models/arrow_direction.dart new file mode 100644 index 0000000..5f0298b --- /dev/null +++ b/lib/models/arrow_direction.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; + +enum ArrowDirection { + left(Icons.arrow_back), + down(Icons.arrow_downward), + up(Icons.arrow_upward), + right(Icons.arrow_forward); + + const ArrowDirection(this.icon); + + final IconData icon; +} diff --git a/lib/models/input_direction.dart b/lib/models/input_direction.dart new file mode 100644 index 0000000..08096c7 --- /dev/null +++ b/lib/models/input_direction.dart @@ -0,0 +1,13 @@ +class InputDirection { + bool up = false; + bool down = false; + bool left = false; + bool right = false; + + void reset() { + up = false; + down = false; + left = false; + right = false; + } +} diff --git a/lib/models/note.dart b/lib/models/note.dart new file mode 100644 index 0000000..bcc6ac6 --- /dev/null +++ b/lib/models/note.dart @@ -0,0 +1,10 @@ +import 'package:sense_the_rhythm/models/arrow_direction.dart'; + +class Note { + final double time; + final ArrowDirection direction; + double position = 0; + bool? wasHit; + + Note({required this.time, required this.direction}); +} diff --git a/lib/game_over_stats.dart b/lib/screens/game_over.dart similarity index 92% rename from lib/game_over_stats.dart rename to lib/screens/game_over.dart index 0e73024..76ea2fb 100644 --- a/lib/game_over_stats.dart +++ b/lib/screens/game_over.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:sense_the_rhythm/arrows.dart'; -import 'package:sense_the_rhythm/level.dart'; -import 'package:sense_the_rhythm/simfile.dart'; +import 'package:sense_the_rhythm/models/note.dart'; +import 'package:sense_the_rhythm/utils/simfile.dart'; +import 'package:sense_the_rhythm/screens/level.dart'; class GameOverStats extends StatelessWidget { const GameOverStats({super.key, required this.simfile, required this.notes}); diff --git a/lib/level.dart b/lib/screens/level.dart similarity index 90% rename from lib/level.dart rename to lib/screens/level.dart index c57f34c..16c7d11 100644 --- a/lib/level.dart +++ b/lib/screens/level.dart @@ -3,10 +3,13 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:audioplayers/audioplayers.dart'; import 'package:flutter/services.dart'; -import 'package:sense_the_rhythm/arrows.dart'; -import 'package:sense_the_rhythm/esense_input.dart'; -import 'package:sense_the_rhythm/game_over_stats.dart'; -import 'package:sense_the_rhythm/simfile.dart'; +import 'package:sense_the_rhythm/models/arrow_direction.dart'; +import 'package:sense_the_rhythm/models/input_direction.dart'; +import 'package:sense_the_rhythm/models/note.dart'; +import 'package:sense_the_rhythm/utils/esense_input.dart'; +import 'package:sense_the_rhythm/utils/simfile.dart'; +import 'package:sense_the_rhythm/widgets/arrows.dart'; +import 'package:sense_the_rhythm/screens/game_over.dart'; class Level extends StatefulWidget { const Level(this.simfile, {super.key}); @@ -16,20 +19,6 @@ class Level extends StatefulWidget { State createState() => _LevelState(); } -class InputDirection { - bool up = false; - bool down = false; - bool left = false; - bool right = false; - - void reset() { - up = false; - down = false; - left = false; - right = false; - } -} - class _LevelState extends State with SingleTickerProviderStateMixin { final player = AudioPlayer(); bool _isPlaying = true; @@ -87,21 +76,23 @@ class _LevelState extends State with SingleTickerProviderStateMixin { setState(() => _duration = duration); }); - _buttonSubscription = ESenseInput.instance.buttonEvents().listen((event) { - if (!event.pressed) { - if (_isPlaying) { - player.pause(); - setState(() { - _isPlaying = false; - }); - } else { - player.resume(); - setState(() { - _isPlaying = true; - }); + if (ESenseInput.instance.connected) { + _buttonSubscription = ESenseInput.instance.buttonEvents().listen((event) { + if (!event.pressed) { + if (_isPlaying) { + player.pause(); + setState(() { + _isPlaying = false; + }); + } else { + player.resume(); + setState(() { + _isPlaying = true; + }); + } } - } - }); + }); + } _positionSubscription = player.onPositionChanged.listen( (p) => setState(() => _position = p), diff --git a/lib/level_selection.dart b/lib/screens/level_selection.dart similarity index 95% rename from lib/level_selection.dart rename to lib/screens/level_selection.dart index 3d3a95a..1b5d0d1 100644 --- a/lib/level_selection.dart +++ b/lib/screens/level_selection.dart @@ -3,12 +3,11 @@ import 'dart:io'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:permission_handler/permission_handler.dart'; -import 'package:sense_the_rhythm/esense_connect_dialog.dart'; -import 'package:sense_the_rhythm/esense_input.dart'; -import 'package:sense_the_rhythm/simfile.dart'; import 'package:shared_preferences/shared_preferences.dart'; - -import 'level.dart'; +import 'package:sense_the_rhythm/utils/esense_input.dart'; +import 'package:sense_the_rhythm/utils/simfile.dart'; +import 'package:sense_the_rhythm/widgets/esense_connect_dialog.dart'; +import 'package:sense_the_rhythm/screens/level.dart'; class LevelSelection extends StatefulWidget { const LevelSelection({super.key}); diff --git a/lib/esense_input.dart b/lib/utils/esense_input.dart similarity index 97% rename from lib/esense_input.dart rename to lib/utils/esense_input.dart index c8fc22a..d909c0d 100644 --- a/lib/esense_input.dart +++ b/lib/utils/esense_input.dart @@ -4,8 +4,8 @@ import 'dart:io'; import 'package:esense_flutter/esense.dart'; import 'package:flutter/material.dart'; import 'package:permission_handler/permission_handler.dart'; -import 'package:sense_the_rhythm/arrows.dart'; -import 'package:sense_the_rhythm/level.dart'; +import 'package:sense_the_rhythm/models/arrow_direction.dart'; +import 'package:sense_the_rhythm/models/input_direction.dart'; class ESenseInput { static final instance = ESenseInput._(); diff --git a/lib/simfile.dart b/lib/utils/simfile.dart similarity index 99% rename from lib/simfile.dart rename to lib/utils/simfile.dart index 7bdf5c0..0af734f 100644 --- a/lib/simfile.dart +++ b/lib/utils/simfile.dart @@ -1,4 +1,3 @@ -import 'dart:ffi'; import 'dart:io'; enum Difficulty { Beginner, Easy, Medium, Hard, Challenge, Edit } diff --git a/lib/widgets/arrow.dart b/lib/widgets/arrow.dart new file mode 100644 index 0000000..1ad0ec4 --- /dev/null +++ b/lib/widgets/arrow.dart @@ -0,0 +1,18 @@ +import 'package:flutter/material.dart'; +import 'package:sense_the_rhythm/models/arrow_direction.dart'; + +class Arrow extends StatelessWidget { + final double position; + final ArrowDirection direction; + + const Arrow({super.key, required this.position, required this.direction}); + + @override + Widget build(BuildContext context) { + return Positioned( + left: MediaQuery.of(context).size.width / 2 - 50, // Center the arrow + bottom: position + 50, + child: Icon(size: 100, color: Colors.redAccent.shade400, direction.icon), + ); + } +} diff --git a/lib/widgets/arrows.dart b/lib/widgets/arrows.dart new file mode 100644 index 0000000..cf04e59 --- /dev/null +++ b/lib/widgets/arrows.dart @@ -0,0 +1,24 @@ +import 'package:flutter/material.dart'; +import 'package:sense_the_rhythm/models/note.dart'; +import 'package:sense_the_rhythm/widgets/arrow.dart'; + +class Arrows extends StatelessWidget { + final List notes; + final double position; + + const Arrows({super.key, required this.notes, required this.position}); + + @override + Widget build(BuildContext context) { + return Stack( + children: notes.map((note) { + double position = + note.position * 10000; // * 20 * MediaQuery.of(context).size.height; + + return Arrow( + position: position, + direction: note.direction, + ); + }).toList()); + } +} diff --git a/lib/esense_connect_dialog.dart b/lib/widgets/esense_connect_dialog.dart similarity index 100% rename from lib/esense_connect_dialog.dart rename to lib/widgets/esense_connect_dialog.dart