style: refactored into folder structure
This commit is contained in:
parent
f98162b6d8
commit
cd061eceeb
|
@ -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<Note> 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),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
|
|
12
lib/models/arrow_direction.dart
Normal file
12
lib/models/arrow_direction.dart
Normal file
|
@ -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;
|
||||
}
|
13
lib/models/input_direction.dart
Normal file
13
lib/models/input_direction.dart
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
10
lib/models/note.dart
Normal file
10
lib/models/note.dart
Normal file
|
@ -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});
|
||||
}
|
|
@ -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});
|
|
@ -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<Level> 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<Level> with SingleTickerProviderStateMixin {
|
||||
final player = AudioPlayer();
|
||||
bool _isPlaying = true;
|
||||
|
@ -87,21 +76,23 @@ class _LevelState extends State<Level> 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),
|
|
@ -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});
|
|
@ -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._();
|
|
@ -1,4 +1,3 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
|
||||
enum Difficulty { Beginner, Easy, Medium, Hard, Challenge, Edit }
|
18
lib/widgets/arrow.dart
Normal file
18
lib/widgets/arrow.dart
Normal file
|
@ -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),
|
||||
);
|
||||
}
|
||||
}
|
24
lib/widgets/arrows.dart
Normal file
24
lib/widgets/arrows.dart
Normal file
|
@ -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<Note> 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());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue