1- using Godot ;
1+ using System ;
2+ using System . Linq ;
3+ using Godot ;
24
35namespace FunkEngine ;
46
7+ public struct SongData
8+ {
9+ public int Bpm ;
10+ public double SongLength ;
11+ public int NumLoops ;
12+ }
13+
14+ public struct ArrowData
15+ {
16+ public Color Color ;
17+ public string Key ;
18+ public NoteChecker Node ;
19+ public ArrowType Type ;
20+ }
21+
522public enum ArrowType
623{
724 Up = 0 ,
@@ -10,14 +27,6 @@ public enum ArrowType
1027 Right = 3 ,
1128}
1229
13- public enum BattleEffectTrigger
14- {
15- NotePlaced ,
16- NoteHit ,
17- SelfNoteHit ,
18- OnPickup ,
19- }
20-
2130public enum Timing
2231{
2332 Miss = 0 ,
@@ -27,6 +36,22 @@ public enum Timing
2736 Perfect = 4 ,
2837}
2938
39+ public struct BattleConfig
40+ {
41+ public MapRooms RoomType { get ; private set ; }
42+ public MapGrid . Room CurRoom { get ; private set ; }
43+ public SongData CurSong { get ; set ; }
44+ public int TodoEnemyAndChart ;
45+ }
46+
47+ public enum BattleEffectTrigger
48+ {
49+ NotePlaced ,
50+ NoteHit ,
51+ SelfNoteHit ,
52+ OnPickup ,
53+ }
54+
3055public enum Stages
3156{
3257 Title ,
@@ -35,19 +60,127 @@ public enum Stages
3560 Map ,
3661}
3762
38- public struct SongData
63+ public enum MapRooms
3964{
40- public int Bpm ;
41- public double SongLength ;
42- public int NumLoops ;
65+ Battle ,
66+ Chest ,
67+ Boss ,
4368}
4469
45- public struct ArrowData
70+ public class MapGrid
4671{
47- public Color Color ;
48- public string Key ;
49- public NoteChecker Node ;
50- public ArrowType Type ;
72+ private int [ , ] _map ;
73+ private Room [ ] _rooms ;
74+ private int _curIdx = 0 ;
75+ private int _curRoom = 0 ;
76+
77+ public Room [ ] GetRooms ( )
78+ {
79+ return _rooms ;
80+ }
81+
82+ public class Room
83+ {
84+ public Room ( int idx , int x , int y )
85+ {
86+ Idx = idx ;
87+ X = x ;
88+ Y = y ;
89+ }
90+
91+ public void SetType ( MapRooms type )
92+ {
93+ Type = type ;
94+ }
95+
96+ public void AddChild ( int newIdx )
97+ {
98+ if ( Children . Contains ( newIdx ) )
99+ return ;
100+ Children = Children . Append ( newIdx ) . ToArray ( ) ;
101+ }
102+
103+ public int Idx { get ; private set ; }
104+ public int [ ] Children { get ; private set ; } = Array . Empty < int > ( ) ;
105+ public int X { get ; private set ; }
106+ public int Y { get ; private set ; }
107+ public MapRooms Type { get ; private set ; }
108+ }
109+
110+ public void InitMapGrid ( int width , int height , int paths )
111+ {
112+ _curIdx = 0 ;
113+ _rooms = Array . Empty < Room > ( ) ;
114+ _map = new int [ width , height ] ; //x,y
115+
116+ int startX = ( width / 2 ) ;
117+ _rooms = _rooms . Append ( new Room ( _curIdx , startX , 0 ) ) . ToArray ( ) ;
118+ _map [ startX , 0 ] = _curIdx ++ ;
119+
120+ for ( int i = 0 ; i < paths ; i ++ )
121+ {
122+ GeneratePath_r ( startX , 0 , width , height ) ;
123+ }
124+ CreateCommonChildren ( width , height ) ;
125+ AddBossRoom ( width , height ) ;
126+ }
127+
128+ //Start at x, y, assume prev room exists. Picks new x pos within +/- 1, attaches recursively
129+ private void GeneratePath_r ( int x , int y , int width , int height )
130+ {
131+ int nextX = StageProducer . GlobalRng . RandiRange (
132+ Math . Max ( x - 1 , 0 ) ,
133+ Math . Min ( x + 1 , width - 1 )
134+ ) ;
135+ if ( _map [ nextX , y + 1 ] == 0 )
136+ {
137+ _rooms = _rooms . Append ( new Room ( _curIdx , nextX , y + 1 ) ) . ToArray ( ) ;
138+ _map [ nextX , y + 1 ] = _curIdx ;
139+ _rooms [ _map [ x , y ] ] . AddChild ( _curIdx ++ ) ;
140+ _rooms [ ^ 1 ] . SetType ( MapRooms . Battle ) ;
141+ if ( y > 0 && y % 3 == 0 )
142+ {
143+ _rooms [ ^ 1 ] . SetType ( MapRooms . Chest ) ;
144+ }
145+ }
146+ else
147+ {
148+ _rooms [ _map [ x , y ] ] . AddChild ( _map [ nextX , y + 1 ] ) ;
149+ }
150+ if ( y < height - 2 )
151+ {
152+ GeneratePath_r ( nextX , y + 1 , width , height ) ;
153+ }
154+ }
155+
156+ //Asserts that if there is a room at the same x, but y+1 they are connected
157+ private void CreateCommonChildren ( int width , int height )
158+ {
159+ foreach ( Room room in _rooms )
160+ {
161+ Vector2I curPos = new Vector2I ( room . X , room . Y ) ;
162+ if ( room . Y + 1 >= height )
163+ continue ;
164+ if ( _map [ curPos . X , curPos . Y + 1 ] == 0 )
165+ continue ;
166+ GD . Print ( "Added child on same X." ) ;
167+ room . AddChild ( _map [ curPos . X , curPos . Y + 1 ] ) ;
168+ }
169+ }
170+
171+ //Adds a boss room at the end of rooms, all max height rooms connect to it.
172+ private void AddBossRoom ( int width , int height )
173+ {
174+ _rooms = _rooms . Append ( new Room ( _curIdx , width / 2 , height ) ) . ToArray ( ) ;
175+ _rooms [ _curIdx ] . SetType ( MapRooms . Boss ) ;
176+ for ( int i = 0 ; i < width ; i ++ ) //Attach all last rooms to a boss room
177+ {
178+ if ( _map [ i , height - 1 ] != 0 )
179+ {
180+ _rooms [ _map [ i , height - 1 ] ] . AddChild ( _curIdx ) ;
181+ }
182+ }
183+ }
51184}
52185
53186public interface IBattleEvent
0 commit comments