11using System ;
2+ using System . Collections . Generic ;
3+ using System . Diagnostics ;
4+ using System . Linq ;
25using Godot ;
36
47/**
@@ -14,6 +17,10 @@ public partial class BattleDirector : Node2D
1417 public NoteManager NM ;
1518
1619 //TODO: Slowly add data based on what it needs.
20+ private double _startTime ;
21+ private double _currentTime ;
22+ private double _timingInterval = .1 ; //secs
23+
1724 public struct SongData
1825 {
1926 public int Bpm ;
@@ -22,14 +29,32 @@ public struct SongData
2229 }
2330
2431 private SongData _curSong ;
25- private Note [ ] _notes ;
32+ private Dictionary < string , Note [ ] > LaneNotes ;
33+ private Note [ ] _notes = Array . Empty < Note > ( ) ;
2634
2735 public override void _Ready ( )
2836 {
37+ LaneNotes = new ( )
38+ {
39+ { "arrowUp" , Array . Empty < Note > ( ) } ,
40+ { "arrowLeft" , Array . Empty < Note > ( ) } ,
41+ { "arrowDown" , Array . Empty < Note > ( ) } ,
42+ { "arrowRight" , Array . Empty < Note > ( ) } ,
43+ } ;
2944 AddExampleNote ( ) ;
3045
3146 CM . PrepChart ( _curSong , _notes ) ;
3247 //TODO: Hook up signals
48+ NM . Connect ( nameof ( NoteManager . NotePressed ) , new Callable ( this , nameof ( OnNotePressed ) ) ) ;
49+ NM . Connect ( nameof ( NoteManager . NoteReleased ) , new Callable ( this , nameof ( OnNoteReleased ) ) ) ;
50+
51+ _startTime = ( double ) Time . GetTicksMsec ( ) / 1000 ;
52+ }
53+
54+ public override void _Process ( double delta )
55+ {
56+ _currentTime += delta ;
57+ //GD.Print($"Current Time: {_currentTime}");
3358 }
3459
3560 private void AddExampleNote ( )
@@ -42,7 +67,67 @@ private void AddExampleNote()
4267 NumLoops = 5 ,
4368 } ;
4469 //Add note
45- _notes = new Note [ 1 ] ;
46- _notes [ 0 ] = new Note ( NoteArrow . ArrowType . Left , 32 ) ;
70+ for ( int i = 0 ; i < 5 ; i ++ )
71+ {
72+ Note exampleNote = new Note ( NoteArrow . ArrowType . Left , i + 9 ) ;
73+ AddNoteToLane ( exampleNote ) ;
74+ }
75+ }
76+
77+ private void AddNoteToLane ( Note note )
78+ {
79+ _notes = _notes . Append ( note ) . ToArray ( ) ;
80+ LaneNotes [ NM . Arrows [ note . Type ] . Key ] = LaneNotes [ NM . Arrows [ note . Type ] . Key ]
81+ . Append ( note )
82+ . ToArray ( ) ;
83+ }
84+
85+ private void OnNotePressed ( string key )
86+ {
87+ GD . Print ( "Note pressed: " + key + " at " + _currentTime + " seconds." ) ;
88+ CheckNoteTiming ( key ) ;
89+ }
90+
91+ private void OnNoteReleased ( NoteArrow . ArrowType arrowType )
92+ {
93+ GD . Print ( "Note released: " + arrowType + " at " + _currentTime + " seconds." ) ;
94+ }
95+
96+ private void CheckNoteTiming ( string arrowString )
97+ {
98+ //Assume queue structure for notes
99+ //Know current time, calculate beat timing
100+ var curBeat = _currentTime / ( 60 / ( double ) _curSong . Bpm ) ;
101+ if ( LaneNotes [ arrowString ] . Length == 0 )
102+ return ;
103+ double beatDif = Math . Abs ( curBeat - LaneNotes [ arrowString ] . First ( ) . Beat ) ;
104+ GD . Print ( beatDif ) ;
105+ if ( beatDif > 1 )
106+ return ;
107+ GD . Print ( "Note Hit." ) ;
108+ //Cycle note queue
109+ LaneNotes [ arrowString ] = LaneNotes [ arrowString ]
110+ . Skip ( 1 )
111+ . Concat ( LaneNotes [ arrowString ] . Take ( 1 ) )
112+ . ToArray ( ) ; //TODO: No stackoverflow code
113+ //Change note visual
114+ CM . TriggerArrow ( ) ;
115+ //Do timing stuff
116+ if ( beatDif < _timingInterval * 2 )
117+ {
118+ GD . Print ( "Perfect" ) ;
119+ }
120+ else if ( beatDif < _timingInterval * 4 )
121+ {
122+ GD . Print ( "Good" ) ;
123+ }
124+ else if ( beatDif < _timingInterval * 6 )
125+ {
126+ GD . Print ( "Okay" ) ;
127+ }
128+ else
129+ {
130+ GD . Print ( "Miss" ) ;
131+ }
47132 }
48133}
0 commit comments