Skip to content

Commit 1ff43a6

Browse files
committed
note placement bar implemented and working - placed notes are uninteractable
1 parent 62da2f7 commit 1ff43a6

5 files changed

Lines changed: 132 additions & 5 deletions

File tree

scenes/BattleDirector/BattleDirector.cs

Lines changed: 21 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]
@@ -53,6 +55,7 @@ public override void _Ready()
5355

5456
Player = GetNode<HealthBar>("PlayerHP");
5557
Enemy = GetNode<HealthBar>("EnemyHP");
58+
NotePlacementBar = GetNode<NotePlacementBar>("NotePlacementBar");
5659

5760
CM.Connect(nameof(NoteManager.NotePressed), new Callable(this, nameof(OnNotePressed)));
5861
CM.Connect(nameof(NoteManager.NoteReleased), new Callable(this, nameof(OnNoteReleased)));
@@ -122,21 +125,25 @@ 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

@@ -145,27 +152,37 @@ private void CheckNoteTiming(NoteArrow.ArrowType type)
145152
double curBeat = TimeKeeper.CurrentTime / (60 / (double)_curSong.Bpm);
146153
if (_laneNotes[(int)type].Length == 0)
147154
{
148-
PlayerAddNote(type, (int)curBeat, 100); // 100 is temp, replace with current combo
155+
PlayerAddNote(type, (int)curBeat);
149156
return;
150157
}
151158
double beatDif = Math.Abs(curBeat - _laneNotes[(int)type].First().Beat);
152159
if (beatDif > 1)
153160
{
154-
PlayerAddNote(type, (int)curBeat, 100); // 100 is temp, replace with current combo
161+
PlayerAddNote(type, (int)curBeat);
155162
return;
156163
}
157164
GD.Print("Note Hit. Dif: " + beatDif);
158165
CM.HandleNote(type);
159166
handleTiming(type, beatDif);
160167
}
161168

162-
private void PlayerAddNote(NoteArrow.ArrowType type, int beat, int currentCombo)
169+
private void PlayerAddNote(NoteArrow.ArrowType type, int beat)
163170
{
171+
//TODO: notes currently can only be placed in first loop.
172+
// placed notes are also non-interactable
173+
164174
// can also add some sort of keybind here to also have pressed
165175
// in case the user just presses the note too early and spawns a note
166-
if (currentCombo >= 100)
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())
167183
{
168184
CM.CreateNote(type, beat);
185+
NotePlacementBar.PlacedNote();
169186
}
170187
}
171188
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
currentBarValue = 0;
22+
currentCombo = 0;
23+
comboMult = 1;
24+
notesToIncreaseCombo = 4;
25+
}
26+
27+
// Hitting a note increases combo, combo mult, and note placement bar
28+
public void HitNote()
29+
{
30+
currentCombo++;
31+
DetermineComboMult();
32+
currentBarValue += comboMult;
33+
UpdateNotePlacementBar(currentBarValue);
34+
UpdateComboMultText();
35+
}
36+
37+
// Missing a note resets combo
38+
public void MissNote()
39+
{
40+
currentCombo = 0;
41+
DetermineComboMult();
42+
UpdateComboMultText();
43+
}
44+
45+
// Placing a note resets the note placement bar
46+
public void PlacedNote()
47+
{
48+
currentBarValue = 0;
49+
UpdateNotePlacementBar(currentBarValue);
50+
}
51+
52+
public bool CanPlaceNote()
53+
{
54+
if (currentBarValue >= MaxValue)
55+
return true;
56+
return false;
57+
}
58+
59+
private void DetermineComboMult()
60+
{
61+
comboMult = currentCombo / notesToIncreaseCombo;
62+
if (comboMult == 0)
63+
comboMult = 1;
64+
}
65+
66+
public void UpdateNotePlacementBar(int newValue)
67+
{
68+
notePlacementBar.Value = newValue;
69+
}
70+
71+
public void UpdateComboMultText()
72+
{
73+
currentComboMultText.Text = $"x{comboMult.ToString()}";
74+
}
75+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
text = "x1"

scenes/BattleDirector/test_battle_scene.tscn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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

78
[node name="ProtoBattleDirector" type="Node2D" node_paths=PackedStringArray("CM", "NM")]
89
script = ExtResource("1_cwqqr")
@@ -30,3 +31,5 @@ offset_left = 403.0
3031
offset_top = -4.0
3132
offset_right = 443.0
3233
offset_bottom = 36.0
34+
35+
[node name="NotePlacementBar" parent="." instance=ExtResource("4_y2yh3")]

scenes/ChartViewport/ChartManager.cs

Lines changed: 3 additions & 0 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

0 commit comments

Comments
 (0)