|
1 | | -using Godot; |
2 | 1 | using System; |
| 2 | +using Godot; |
3 | 3 |
|
4 | 4 | //Lets say this inits all the initial notes and manages the chart BG. |
5 | | - |
| 5 | + |
6 | 6 | //What does this do? |
7 | 7 | //Input, visual looping, timing, battle stuff, combo, note creation |
8 | | - |
| 8 | + |
9 | 9 | //Focus on the looping |
10 | 10 | /* |
11 | 11 |
|
12 | 12 | This should manage creating sprites for notes??? |
13 | 13 | This should manage subview camera pos and zoom. |
14 | 14 |
|
15 | 15 | 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 |
16 | 17 | 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 |
19 | 20 |
|
20 | 21 | 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 |
24 | 25 |
|
25 | 26 | 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 |
28 | 29 | */ |
29 | 30 |
|
30 | 31 | public partial class ChartManager : SubViewportContainer |
31 | 32 | { |
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 | + } |
59 | 115 | } |
0 commit comments