@@ -15,14 +15,17 @@ public partial class BattleDirector : Node2D
1515 private HealthBar Enemy ;
1616
1717 [ Export ]
18- public ChartManager CM ;
18+ private ChartManager CM ;
1919
2020 [ Export ]
21- public InputHandler IH ;
21+ private InputHandler IH ;
2222
2323 [ Export ]
2424 private NotePlacementBar NotePlacementBar ;
2525
26+ [ Export ]
27+ private AudioStreamPlayer Audio ;
28+
2629 private double _timingInterval = .1 ; //secs
2730
2831 [ Signal ]
@@ -44,7 +47,7 @@ public struct SongData
4447 #region Note Handling
4548 //Assume queue structure for notes in each lane.
4649 //Can eventually make this its own structure
47- private NoteArrow [ ] [ ] _laneData ;
50+ private NoteArrow [ ] [ ] _laneData = Array . Empty < NoteArrow [ ] > ( ) ;
4851 private int [ ] _laneLastBeat = new int [ ]
4952 { //Temporary (hopefully) measure to bridge from note queue structure to ordered array
5053 0 ,
@@ -70,9 +73,9 @@ private bool AddNoteToLane(Note note, bool isActive = true)
7073 {
7174 note . Beat %= CM . BeatsPerLoop ;
7275 //Don't add dupe notes
73- if ( _notes . Any ( nt => nt . Type == note . Type && nt . Beat == note . Beat ) )
76+ if ( note . Beat == 0 || _notes . Any ( nt => nt . Type == note . Type && nt . Beat == note . Beat ) )
7477 {
75- return false ;
78+ return false ; //Beat at 0 is too messy.
7679 }
7780 _notes = _notes . Append ( note ) . ToArray ( ) ;
7881 //Get noteArrow from CM
@@ -87,19 +90,24 @@ private bool AddNoteToLane(Note note, bool isActive = true)
8790 private void AddExampleNotes ( )
8891 {
8992 GD . Print ( CM . BeatsPerLoop ) ;
90- for ( int i = 0 ; i < 1 ; i ++ )
93+ for ( int i = 1 ; i < 15 ; i ++ )
94+ {
95+ Note exampleNote = new Note ( NoteArrow . ArrowType . Up , i * 4 ) ;
96+ AddNoteToLane ( exampleNote ) ;
97+ }
98+ for ( int i = 1 ; i < 15 ; i ++ )
9199 {
92- Note exampleNote = new Note ( NoteArrow . ArrowType . Down , i ) ;
100+ Note exampleNote = new Note ( NoteArrow . ArrowType . Left , 4 * i + 1 ) ;
93101 AddNoteToLane ( exampleNote ) ;
94102 }
95- for ( int i = 0 ; i < 4 ; i ++ )
103+ for ( int i = 0 ; i < 10 ; i ++ )
96104 {
97- Note exampleNote = new Note ( NoteArrow . ArrowType . Up , i + 20 ) ;
105+ Note exampleNote = new Note ( NoteArrow . ArrowType . Right , 3 * i + 32 ) ;
98106 AddNoteToLane ( exampleNote ) ;
99107 }
100- for ( int i = 0 ; i < 1 ; i ++ )
108+ for ( int i = 0 ; i < 3 ; i ++ )
101109 {
102- Note exampleNote = new Note ( NoteArrow . ArrowType . Left , CM . BeatsPerLoop ) ;
110+ Note exampleNote = new Note ( NoteArrow . ArrowType . Down , 8 * i + 16 ) ;
103111 AddNoteToLane ( exampleNote ) ;
104112 }
105113 }
@@ -109,9 +117,16 @@ public override void _Ready()
109117 _curSong = new SongData
110118 {
111119 Bpm = 120 ,
112- SongLength = 100 ,
120+ SongLength = Audio . Stream . GetLength ( ) ,
113121 NumLoops = 5 ,
114122 } ;
123+
124+ var timer = GetTree ( ) . CreateTimer ( AudioServer . GetTimeToNextMix ( ) ) ;
125+ timer . Timeout += Begin ;
126+ }
127+
128+ private void Begin ( )
129+ {
115130 CM . PrepChart ( _curSong ) ;
116131 _laneData = new NoteArrow [ ] [ ]
117132 {
@@ -142,11 +157,13 @@ public override void _Ready()
142157
143158 CM . Connect ( nameof ( InputHandler . NotePressed ) , new Callable ( this , nameof ( OnNotePressed ) ) ) ;
144159 CM . Connect ( nameof ( InputHandler . NoteReleased ) , new Callable ( this , nameof ( OnNoteReleased ) ) ) ;
160+
161+ Audio . Play ( ) ;
145162 }
146163
147164 public override void _Process ( double delta )
148165 {
149- TimeKeeper . CurrentTime += delta ;
166+ TimeKeeper . CurrentTime = Audio . GetPlaybackPosition ( ) ;
150167 CheckMiss ( ) ;
151168 }
152169
@@ -212,14 +229,14 @@ private void HandleTiming(NoteArrow.ArrowType type, double beatDif)
212229 if ( beatDif < _timingInterval * 1 )
213230 {
214231 GD . Print ( "Perfect" ) ;
215- Enemy . TakeDamage ( 1 ) ;
232+ Enemy . TakeDamage ( 3 ) ;
216233 NotePlacementBar . HitNote ( ) ;
217234 NotePlacementBar . ComboText ( "Perfect!" ) ;
218235 }
219236 else if ( beatDif < _timingInterval * 2 )
220237 {
221238 GD . Print ( "Good" ) ;
222- Enemy . TakeDamage ( 0 ) ;
239+ Enemy . TakeDamage ( 1 ) ;
223240 NotePlacementBar . HitNote ( ) ;
224241 NotePlacementBar . ComboText ( "Good" ) ;
225242 }
0 commit comments