Skip to content

Commit 61f18db

Browse files
committed
Initial Complete Chart Looping
Needs to be integrated with other systems Needs intended visuals Logic has all been ironed out. (In theory)
1 parent 560d062 commit 61f18db

4 files changed

Lines changed: 132 additions & 55 deletions

File tree

project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config_version=5
1111
[application]
1212

1313
config/name="Funk Engine"
14-
run/main_scene="res://scenes/main.tscn"
14+
run/main_scene="res://scenes/ChartViewport/test_scene.tscn"
1515
config/features=PackedStringArray("4.3", "C#", "Forward Plus")
1616
config/icon="res://icon.svg"
1717

scenes/ChartViewport/ChartBg.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
using Godot;
21
using System;
2+
using Godot;
33

44
public partial class ChartBg : TextureRect
55
{
6-
[Export] public float Bounds = 700f;
7-
[Export] public float Speed = 5;
8-
6+
[Export]
7+
public float Bounds = 700f;
98

10-
// Called every frame. 'delta' is the elapsed time since the previous frame.
11-
public override void _Process(double delta)
12-
{
13-
if (Position.X <= -Bounds)
14-
{
15-
Position = new Vector2(Bounds, Position.Y);
16-
}
17-
Position += Speed * Vector2.Left;
9+
[Export]
10+
public float Speed = 5;
1811

19-
}
12+
// Called every frame. 'delta' is the elapsed time since the previous frame.
13+
public override void _Process(double delta)
14+
{
15+
if (Position.X <= -Bounds)
16+
{
17+
Position = new Vector2(Bounds, Position.Y);
18+
}
19+
Position += Speed * Vector2.Left * (float)delta;
20+
}
2021
}
Lines changed: 93 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,115 @@
1-
using Godot;
21
using System;
2+
using Godot;
33

44
//Lets say this inits all the initial notes and manages the chart BG.
5-
5+
66
//What does this do?
77
//Input, visual looping, timing, battle stuff, combo, note creation
8-
8+
99
//Focus on the looping
1010
/*
1111
1212
This should manage creating sprites for notes???
1313
This should manage subview camera pos and zoom.
1414
1515
Movement should primarily be done from a parent node
16+
!!Backgrounds need to be big enough/notes and beats spaced enough that when a note goes off screen, it can be teleported in position offscreen
1617
BackGround probably needs 2 sprites or parallax:
17-
Get a set length, based on viewport and loop/song length (Const PLAYWIDTH)
18-
Once one BG hits a certain left pos return it to the right pos
18+
Get a set length, based on viewport and loop/song length (Const PLAYWIDTH)
19+
Once one BG hits a certain left pos return it to the right pos
1920
2021
Notes are similar, but only need 1 representation.
21-
Once hits left bounds return to right bounds
22-
(Something else should probably manage refreshing, input, etc)
23-
Can probably use an object pool
22+
Once hits left bounds return to right bounds
23+
(Something else should probably manage refreshing, input, etc)
24+
Can probably use an object pool
2425
2526
If timing based input checking:
26-
This is enough, notes are visually just sprites
27-
Collision based - This might need to manage that, or have a sister manager that does, notes need more stuff on their own
27+
This is enough, notes are visually just sprites
28+
Collision based - This might need to manage that, or have a sister manager that does, notes need more stuff on their own
2829
*/
2930

3031
public partial class ChartManager : SubViewportContainer
3132
{
32-
33-
//Simulated variables, remove later
34-
private const int Bpm = 120;
35-
private const double SongLength = 160; //secs
36-
37-
//Arbitrary vars, play with these
38-
private const double ChartLength = 1400;
39-
private const int NumLoops = 5; //TODO: Loops should be based on measures of a song?
40-
41-
//Nodes from scene
42-
[Export] public CanvasGroup ChartLoopables;
43-
44-
private double _loopLen; //secs
45-
private int _beatsPerLoop;
46-
47-
public override void _Ready()
48-
{
49-
_loopLen = SongLength / NumLoops;
50-
_beatsPerLoop = (int)(_loopLen / (60f / Bpm));
51-
52-
53-
}
54-
55-
public override void _Process(double delta)
56-
{
57-
//ChartLoopables.Position += 10 * Vector2.Left;
58-
}
33+
//Simulated variables, remove later
34+
private const int Bpm = 120;
35+
private const double SongLength = 160; //secs
36+
37+
//Arbitrary vars, play with these
38+
private const double ChartLength = 1400;
39+
private const int NumLoops = 5; //TODO: Loops should be based on measures of a song?
40+
41+
//Nodes from scene
42+
[Export]
43+
public CanvasGroup ChartLoopables;
44+
45+
private double _loopLen; //secs
46+
private int _beatsPerLoop;
47+
48+
public override void _Ready()
49+
{
50+
_loopLen = SongLength / NumLoops;
51+
_beatsPerLoop = (int)(_loopLen / (60f / Bpm));
52+
53+
ChartLoopables = GetNode<CanvasGroup>("%ChartLoopables");
54+
55+
speedL = 700 / _loopLen; // px/s
56+
GD.Print(speedL);
57+
58+
foreach (Node child in ChartLoopables.GetChildren())
59+
{
60+
if (child is ChartBg)
61+
{
62+
ChartBg chartBg = (ChartBg)child;
63+
chartBg.Speed = (float)speedL;
64+
}
65+
}
66+
67+
InitTestNote();
68+
}
69+
70+
public override void _Process(double delta)
71+
{
72+
//ChartLoopables.Position += 10 * Vector2.Left;
73+
ProcessTestNote(delta);
74+
}
75+
76+
//Test code TODO: REMOVE LATER
77+
private Sprite2D[] _testNotes = new Sprite2D[4];
78+
private float[] _testBeats = { 60, 30, 32, 10 };
79+
private double speedL;
80+
81+
/*The logic:
82+
*Spawn in pos is a proportion (intended beat/beats per loop) = (intended pos/track length in px) ->
83+
* intended pos = intended beat / bpl * track length
84+
*
85+
* Respawn (probably obj pool, or for now new instantiation)
86+
* When a note's pos is at its intended initial pos, queue up and spawn the next note of its beat at intended pos + track length
87+
*/
88+
public void InitTestNote()
89+
{
90+
_testNotes[0] = GetNode<Sprite2D>("%TestNote");
91+
_testNotes[1] = GetNode<Sprite2D>("%TestNote2");
92+
_testNotes[2] = GetNode<Sprite2D>("%TestNote3");
93+
_testNotes[3] = GetNode<Sprite2D>("%TestNote4");
94+
int i = 0;
95+
foreach (Sprite2D note in _testNotes)
96+
{
97+
note.Position = new Vector2(_testBeats[i] / _beatsPerLoop * 700, 150);
98+
i++;
99+
}
100+
}
101+
102+
public void ProcessTestNote(double delta)
103+
{
104+
int i = 0;
105+
foreach (Sprite2D note in _testNotes)
106+
{
107+
if (note.Position.X <= (_testBeats[i] / _beatsPerLoop * 700) - 700)
108+
{
109+
note.Position = new Vector2(_testBeats[i] / _beatsPerLoop * 700, 150);
110+
}
111+
note.Position += Vector2.Left * (float)speedL * (float)delta;
112+
i++;
113+
}
114+
}
59115
}

scenes/ChartViewport/ChartViewport.tscn

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,38 @@ texture = ExtResource("1_0wnka")
2929
unique_name_in_owner = true
3030

3131
[node name="ChartBG1" type="TextureRect" parent="SubViewport/ChartLoopables"]
32-
modulate = Color(0.439216, 1, 1, 0.545098)
32+
modulate = Color(2, 2, 2, 1)
3333
offset_top = -46.0
34-
offset_right = 700.0
34+
offset_right = 701.0
3535
offset_bottom = 254.0
3636
texture = ExtResource("1_0wnka")
3737
script = ExtResource("3_runyu")
3838

3939
[node name="ChartBG2" type="TextureRect" parent="SubViewport/ChartLoopables"]
40-
modulate = Color(0.439216, 1, 1, 0.545098)
40+
modulate = Color(2, 2, 2, 1)
4141
offset_left = 700.0
4242
offset_top = -46.0
43-
offset_right = 1400.0
43+
offset_right = 1401.0
4444
offset_bottom = 254.0
4545
texture = ExtResource("1_0wnka")
4646
script = ExtResource("3_runyu")
47+
48+
[node name="TestNote" type="Sprite2D" parent="SubViewport/ChartLoopables"]
49+
unique_name_in_owner = true
50+
scale = Vector2(0.3, 0.3)
51+
texture = ExtResource("1_0wnka")
52+
53+
[node name="TestNote2" type="Sprite2D" parent="SubViewport/ChartLoopables"]
54+
unique_name_in_owner = true
55+
scale = Vector2(0.3, 0.3)
56+
texture = ExtResource("1_0wnka")
57+
58+
[node name="TestNote3" type="Sprite2D" parent="SubViewport/ChartLoopables"]
59+
unique_name_in_owner = true
60+
scale = Vector2(0.3, 0.3)
61+
texture = ExtResource("1_0wnka")
62+
63+
[node name="TestNote4" type="Sprite2D" parent="SubViewport/ChartLoopables"]
64+
unique_name_in_owner = true
65+
scale = Vector2(0.3, 0.3)
66+
texture = ExtResource("1_0wnka")

0 commit comments

Comments
 (0)