Skip to content

Commit 5585c4b

Browse files
committed
More effectively handle looping
Notes no longer loop with increased beat
1 parent e3070c2 commit 5585c4b

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

scenes/BattleDirector/BattleDirector.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public partial class BattleDirector : Node2D
2020
[Export]
2121
public InputHandler IH;
2222

23+
[Export]
2324
private NotePlacementBar NotePlacementBar;
2425

2526
private double _timingInterval = .1; //secs
@@ -118,7 +119,6 @@ public override void _Ready()
118119

119120
Player = GetNode<HealthBar>("PlayerHP");
120121
Enemy = GetNode<HealthBar>("EnemyHP");
121-
NotePlacementBar = GetNode<NotePlacementBar>("NotePlacementBar");
122122

123123
CM.Connect(nameof(InputHandler.NotePressed), new Callable(this, nameof(OnNotePressed)));
124124
CM.Connect(nameof(InputHandler.NoteReleased), new Callable(this, nameof(OnNoteReleased)));
@@ -130,8 +130,7 @@ public override void _Process(double delta)
130130
CheckMiss();
131131
}
132132

133-
#region Input
134-
133+
#region Input&Timing
135134
private void OnNotePressed(NoteArrow.ArrowType type)
136135
{
137136
CheckNoteTiming(type);
@@ -142,22 +141,23 @@ private void OnNoteReleased(NoteArrow.ArrowType arrowType) { }
142141
//Check all lanes for misses from missed inputs
143142
private void CheckMiss()
144143
{
145-
double curBeat = TimeKeeper.CurrentTime / (60 / (double)_curSong.Bpm);
144+
double curBeat = TimeKeeper.CurrentTime / (60 / (double)_curSong.Bpm) % CM.BeatsPerLoop;
146145
for (int i = 0; i < _laneData.Length; i++)
147146
{
148147
if (_laneData[i].Length <= 0)
149148
continue;
150149
double beatDif = (curBeat - GetFirstNote((NoteArrow.ArrowType)i).Beat);
151-
if (beatDif > 1)
150+
if (beatDif > 1 && _laneData[i].First().Visible) //Can change, currently using visible as a stand in for already activated.
152151
{
152+
_laneData[i].First().NoteHit();
153153
HandleTiming((NoteArrow.ArrowType)i, Math.Abs(beatDif));
154154
}
155155
}
156156
}
157157

158158
private void CheckNoteTiming(NoteArrow.ArrowType type)
159159
{
160-
double curBeat = TimeKeeper.CurrentTime / (60 / (double)_curSong.Bpm);
160+
double curBeat = TimeKeeper.CurrentTime / (60 / (double)_curSong.Bpm) % CM.BeatsPerLoop;
161161
if (_laneData[(int)type].Length == 0)
162162
return;
163163
double beatDif = Math.Abs(curBeat - GetFirstNote(type).Beat);
@@ -170,9 +170,7 @@ private void CheckNoteTiming(NoteArrow.ArrowType type)
170170

171171
private void HandleTiming(NoteArrow.ArrowType type, double beatDif)
172172
{
173-
//Cycle note queue
174-
CycleNote(type).Beat += CM.BeatsPerLoop;
175-
//Do timing stuff
173+
CycleNote(type);
176174
if (beatDif < _timingInterval * 2)
177175
{
178176
GD.Print("Perfect");

scenes/BattleDirector/test_battle_scene.tscn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
[ext_resource type="PackedScene" uid="uid://bgomxovxs7sr8" path="res://scenes/BattleDirector/HealthBar.tscn" id="3_pp0u0"]
66
[ext_resource type="PackedScene" uid="uid://duhiilcv4tat3" path="res://scenes/BattleDirector/NotePlacementBar.tscn" id="4_y2yh3"]
77

8-
[node name="ProtoBattleDirector" type="Node2D" node_paths=PackedStringArray("CM", "IH")]
8+
[node name="ProtoBattleDirector" type="Node2D" node_paths=PackedStringArray("CM", "IH", "NotePlacementBar")]
99
script = ExtResource("1_cwqqr")
1010
CM = NodePath("SubViewport")
1111
IH = NodePath("SubViewport/SubViewport/noteManager")
12+
NotePlacementBar = NodePath("NotePlacementBar")
1213

1314
[node name="SubViewport" parent="." instance=ExtResource("2_cupb3")]
1415
offset_left = 80.0

scenes/NoteManager/scripts/NoteArrow.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ public override void _Process(double delta)
3737
) + Bounds;
3838
if (newPos.X > Position.X)
3939
{
40-
Visible = true;
40+
OnLoop();
4141
}
4242
Position = newPos;
4343
}
4444

45+
public void OnLoop()
46+
{
47+
Visible = true;
48+
}
49+
4550
public void NoteHit()
4651
{
4752
Visible = false;

0 commit comments

Comments
 (0)