Skip to content

Commit 993b9c1

Browse files
authored
Merge pull request #30 from Project-Funk-Engine/player-adding-notes
Player adding notes
2 parents 9b9a4fb + 34293ff commit 993b9c1

5 files changed

Lines changed: 164 additions & 9 deletions

File tree

scenes/BattleDirector/BattleDirector.cs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public partial class BattleDirector : Node2D
1919
private HealthBar Player;
2020
private HealthBar Enemy;
2121

22+
private NotePlacementBar NotePlacementBar;
23+
2224
private double _timingInterval = .1; //secs
2325

2426
[Signal]
@@ -35,6 +37,7 @@ public struct SongData
3537
}
3638

3739
private SongData _curSong;
40+
3841
//Assume queue structure for notes in each lane.
3942
private readonly Note[][] _laneNotes = new Note[][]
4043
{
@@ -52,6 +55,7 @@ public override void _Ready()
5255

5356
Player = GetNode<HealthBar>("PlayerHP");
5457
Enemy = GetNode<HealthBar>("EnemyHP");
58+
NotePlacementBar = GetNode<NotePlacementBar>("NotePlacementBar");
5559

5660
CM.Connect(nameof(NoteManager.NotePressed), new Callable(this, nameof(OnNotePressed)));
5761
CM.Connect(nameof(NoteManager.NoteReleased), new Callable(this, nameof(OnNoteReleased)));
@@ -64,7 +68,8 @@ public override void _Process(double delta)
6468
double curBeat = TimeKeeper.CurrentTime / (60 / (double)_curSong.Bpm);
6569
for (int i = 0; i < _laneNotes.Length; i++)
6670
{
67-
if (_laneNotes[i].Length <= 0) continue;
71+
if (_laneNotes[i].Length <= 0)
72+
continue;
6873
double beatDif = (curBeat - _laneNotes[i].First().Beat);
6974
if (beatDif > 1)
7075
{
@@ -105,9 +110,7 @@ private void OnNotePressed(NoteArrow.ArrowType type)
105110
CheckNoteTiming(type);
106111
}
107112

108-
private void OnNoteReleased(NoteArrow.ArrowType arrowType)
109-
{
110-
}
113+
private void OnNoteReleased(NoteArrow.ArrowType arrowType) { }
111114

112115
private void handleTiming(NoteArrow.ArrowType type, double beatDif)
113116
{
@@ -122,34 +125,64 @@ private void handleTiming(NoteArrow.ArrowType type, double beatDif)
122125
{
123126
GD.Print("Perfect");
124127
Enemy.TakeDamage(10);
128+
NotePlacementBar.HitNote();
125129
}
126130
else if (beatDif < _timingInterval * 4)
127131
{
128132
GD.Print("Good");
129133
Enemy.TakeDamage(5);
134+
NotePlacementBar.HitNote();
130135
}
131136
else if (beatDif < _timingInterval * 6)
132137
{
133138
GD.Print("Okay");
134139
Enemy.TakeDamage(1);
140+
NotePlacementBar.HitNote();
135141
}
136142
else
137143
{
138144
GD.Print("Miss");
139145
Player.TakeDamage(10);
146+
NotePlacementBar.MissNote();
140147
}
141148
}
142149

143150
private void CheckNoteTiming(NoteArrow.ArrowType type)
144151
{
145152
double curBeat = TimeKeeper.CurrentTime / (60 / (double)_curSong.Bpm);
146153
if (_laneNotes[(int)type].Length == 0)
154+
{
155+
PlayerAddNote(type, (int)curBeat);
147156
return;
157+
}
148158
double beatDif = Math.Abs(curBeat - _laneNotes[(int)type].First().Beat);
149159
if (beatDif > 1)
160+
{
161+
PlayerAddNote(type, (int)curBeat);
150162
return;
163+
}
151164
GD.Print("Note Hit. Dif: " + beatDif);
152165
CM.HandleNote(type);
153166
handleTiming(type, beatDif);
154167
}
168+
169+
private void PlayerAddNote(NoteArrow.ArrowType type, int beat)
170+
{
171+
//TODO: notes currently can only be placed in first loop.
172+
// placed notes are also non-interactable
173+
174+
// can also add some sort of keybind here to also have pressed
175+
// in case the user just presses the note too early and spawns a note
176+
GD.Print(
177+
$"Player trying to place {type} typed note at beat: "
178+
+ beat
179+
+ " Verdict: "
180+
+ NotePlacementBar.CanPlaceNote()
181+
);
182+
if (NotePlacementBar.CanPlaceNote())
183+
{
184+
CM.CreateNote(type, beat);
185+
NotePlacementBar.PlacedNote();
186+
}
187+
}
155188
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using Godot;
3+
4+
public partial class NotePlacementBar : Node
5+
{
6+
const int MaxValue = 100;
7+
int currentBarValue;
8+
int currentCombo;
9+
int comboMult;
10+
int notesToIncreaseCombo;
11+
12+
[Export]
13+
ProgressBar notePlacementBar;
14+
15+
[Export]
16+
TextEdit currentComboMultText;
17+
18+
// Called when the node enters the scene tree for the first time.
19+
public override void _Ready()
20+
{
21+
notePlacementBar.MaxValue = MaxValue;
22+
currentBarValue = 0;
23+
currentCombo = 0;
24+
comboMult = 1;
25+
notesToIncreaseCombo = 4;
26+
}
27+
28+
// Hitting a note increases combo, combo mult, and note placement bar
29+
public void HitNote()
30+
{
31+
currentCombo++;
32+
DetermineComboMult();
33+
currentBarValue += comboMult;
34+
UpdateNotePlacementBar(currentBarValue);
35+
UpdateComboMultText();
36+
}
37+
38+
// Missing a note resets combo
39+
public void MissNote()
40+
{
41+
currentCombo = 0;
42+
DetermineComboMult();
43+
UpdateComboMultText();
44+
}
45+
46+
// Placing a note resets the note placement bar
47+
public void PlacedNote()
48+
{
49+
currentBarValue = 0;
50+
UpdateNotePlacementBar(currentBarValue);
51+
}
52+
53+
public bool CanPlaceNote()
54+
{
55+
if (currentBarValue >= MaxValue)
56+
return true;
57+
return false;
58+
}
59+
60+
private void DetermineComboMult()
61+
{
62+
comboMult = currentCombo / notesToIncreaseCombo;
63+
if (comboMult == 0)
64+
comboMult = 1;
65+
}
66+
67+
public void UpdateNotePlacementBar(int newValue)
68+
{
69+
notePlacementBar.Value = newValue;
70+
}
71+
72+
public void UpdateComboMultText()
73+
{
74+
currentComboMultText.Text = $"x{comboMult.ToString()}";
75+
}
76+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://duhiilcv4tat3"]
2+
3+
[ext_resource type="Script" path="res://scenes/BattleDirector/NotePlacementBar.cs" id="1_456es"]
4+
5+
[node name="NotePlacementBar" type="Control" node_paths=PackedStringArray("notePlacementBar", "currentComboMultText")]
6+
layout_mode = 3
7+
anchors_preset = 15
8+
anchor_right = 1.0
9+
anchor_bottom = 1.0
10+
grow_horizontal = 2
11+
grow_vertical = 2
12+
script = ExtResource("1_456es")
13+
notePlacementBar = NodePath("ProgressBar")
14+
currentComboMultText = NodePath("TextEdit")
15+
16+
[node name="ProgressBar" type="ProgressBar" parent="."]
17+
layout_mode = 0
18+
offset_left = 29.0
19+
offset_top = 50.0
20+
offset_right = 229.0
21+
offset_bottom = 85.0
22+
23+
[node name="TextEdit" type="TextEdit" parent="."]
24+
layout_mode = 0
25+
offset_left = 240.0
26+
offset_top = 50.0
27+
offset_right = 290.0
28+
offset_bottom = 85.0
29+
mouse_filter = 2
30+
text = "x1"
31+
context_menu_enabled = false
32+
shortcut_keys_enabled = false
33+
selecting_enabled = false
34+
deselect_on_focus_loss_enabled = false
35+
drag_and_drop_selection_enabled = false
36+
virtual_keyboard_enabled = false
37+
middle_mouse_paste_enabled = false

scenes/BattleDirector/test_battle_scene.tscn

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
[gd_scene load_steps=4 format=3 uid="uid://b0mrgr7h0ty1y"]
1+
[gd_scene load_steps=5 format=3 uid="uid://b0mrgr7h0ty1y"]
22

33
[ext_resource type="Script" path="res://scenes/BattleDirector/BattleDirector.cs" id="1_cwqqr"]
44
[ext_resource type="PackedScene" uid="uid://dfevfib11kou1" path="res://scenes/ChartViewport/ChartViewport.tscn" id="2_cupb3"]
55
[ext_resource type="PackedScene" uid="uid://bgomxovxs7sr8" path="res://scenes/BattleDirector/HealthBar.tscn" id="3_pp0u0"]
6+
[ext_resource type="PackedScene" uid="uid://duhiilcv4tat3" path="res://scenes/BattleDirector/NotePlacementBar.tscn" id="4_y2yh3"]
67

7-
[node name="ProtoBattleDirector" type="Node2D" node_paths=PackedStringArray("CM", "NM")]
8+
[node name="ProtoBattleDirector" type="Node2D" node_paths=PackedStringArray("CM")]
89
script = ExtResource("1_cwqqr")
910
CM = NodePath("SubViewport")
10-
NM = NodePath("SubViewport/SubViewport/noteManager")
1111

1212
[node name="SubViewport" parent="." instance=ExtResource("2_cupb3")]
1313
offset_left = 80.0
@@ -30,3 +30,5 @@ offset_left = 403.0
3030
offset_top = -4.0
3131
offset_right = 443.0
3232
offset_bottom = 36.0
33+
34+
[node name="NotePlacementBar" parent="." instance=ExtResource("4_y2yh3")]

scenes/ChartViewport/ChartManager.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ private NoteArrow CreateNote(NoteManager.ArrowData arrowData, int beat)
101101
.ToArray();
102102
}
103103
ChartLoopables.AddChild(note);
104+
GD.Print(
105+
$"Adding note: {arrowData.Type}, Current count: {_currentArrows[(int)arrowData.Type].Length}"
106+
);
104107
return note;
105108
}
106109

@@ -115,8 +118,12 @@ public void HandleNote(ArrowType type)
115118

116119
public void OnNotePressed(ArrowType type)
117120
{
118-
if (_currentArrows[(int)type].Length == 0)
119-
return;
121+
// removed this bit of code, since placement only worked on lines that already
122+
// had arrows before the player added any. if needed we can add this back
123+
// once we use charts that have arrows in all 4 rows from the beginning
124+
//if (_currentArrows[(int)type].Length == 0)
125+
//return;
126+
120127
EmitSignal(nameof(NotePressed), (int)type);
121128
}
122129

0 commit comments

Comments
 (0)