@@ -10,11 +10,14 @@ public partial class StageProducer : Node
1010 public static RandomNumberGenerator GlobalRng = new RandomNumberGenerator ( ) ;
1111 private ulong _seed ;
1212 private ulong _lastRngState ;
13+ private bool _isInitialized = false ;
1314
1415 private Stages _curStage = Stages . Title ;
1516 private Node _curScene ;
17+ public static MapGrid . Room CurRoom { get ; private set ; }
18+ public static Vector2I MapSize { get ; private set ; } = new Vector2I ( 7 , 6 ) ; //For now, make width an odd number
1619
17- private MapGrid _map = new MapGrid ( ) ;
20+ public static MapGrid Map { get ; } = new MapGrid ( ) ;
1821
1922 //Hold here to persist between changes
2023 //TODO: Allow for permanent changes and battle temporary stat changes.
@@ -27,6 +30,11 @@ public class MapGrid
2730 private int _curIdx = 0 ;
2831 private int _curRoom = 0 ;
2932
33+ public Room [ ] GetRooms ( )
34+ {
35+ return _rooms ;
36+ }
37+
3038 public class Room
3139 {
3240 public Room ( int idx , int x , int y )
@@ -48,10 +56,10 @@ public void AddChild(int newIdx)
4856 Children = Children . Append ( newIdx ) . ToArray ( ) ;
4957 }
5058
51- private int Idx ;
52- private int [ ] Children = Array . Empty < int > ( ) ;
53- private int X ;
54- private int Y ;
59+ public int Idx { get ; private set ; }
60+ public int [ ] Children { get ; private set ; } = Array . Empty < int > ( ) ;
61+ public int X { get ; private set ; }
62+ public int Y { get ; private set ; }
5563 private string Type ;
5664 }
5765
@@ -61,15 +69,15 @@ public void InitMapGrid(int width, int height, int paths)
6169 _rooms = Array . Empty < Room > ( ) ;
6270 _map = new int [ width , height ] ; //x,y
6371
64- int startX = GlobalRng . RandiRange ( 0 , width - 1 ) ; //TODO: Replace with seeding
72+ int startX = ( width / 2 ) ;
6573 _rooms = _rooms . Append ( new Room ( _curIdx , startX , 0 ) ) . ToArray ( ) ;
6674 _map [ startX , 0 ] = _curIdx ++ ;
6775
6876 for ( int i = 0 ; i < paths ; i ++ )
6977 {
7078 GeneratePath_r ( startX , 0 , width , height ) ;
7179 }
72-
80+ CreateCommonChildren ( width , height ) ;
7381 AddBossRoom ( width , height ) ;
7482 }
7583
@@ -93,9 +101,25 @@ private void GeneratePath_r(int x, int y, int width, int height)
93101 }
94102 }
95103
104+ //Asserts that if there is a room at the same x, but y+1 they are connected
105+ private void CreateCommonChildren ( int width , int height )
106+ {
107+ foreach ( Room room in _rooms )
108+ {
109+ Vector2I curPos = new Vector2I ( room . X , room . Y ) ;
110+ if ( room . Y + 1 >= height )
111+ continue ;
112+ if ( _map [ curPos . X , curPos . Y + 1 ] == 0 )
113+ continue ;
114+ GD . Print ( "Added child on same X." ) ;
115+ room . AddChild ( _map [ curPos . X , curPos . Y + 1 ] ) ;
116+ }
117+ }
118+
119+ //Adds a boss room at the end of rooms, all max height rooms connect to it.
96120 private void AddBossRoom ( int width , int height )
97121 {
98- _rooms = _rooms . Append ( new Room ( _curIdx , 0 , height ) ) . ToArray ( ) ;
122+ _rooms = _rooms . Append ( new Room ( _curIdx , width / 2 , height ) ) . ToArray ( ) ;
99123 _rooms [ _curIdx ] . SetType ( "Boss" ) ;
100124 for ( int i = 0 ; i < width ; i ++ ) //Attach all last rooms to a boss room
101125 {
@@ -109,10 +133,19 @@ private void AddBossRoom(int width, int height)
109133
110134 public void StartGame ( )
111135 {
112- _map . InitMapGrid ( 2 , 2 , 1 ) ;
136+ Map . InitMapGrid ( MapSize . X , MapSize . Y , 3 ) ;
113137 _seed = GlobalRng . Seed ;
114138 _lastRngState = GlobalRng . State ;
115139 PlayerStats = new PlayerStats ( ) ;
140+
141+ CurRoom = Map . GetRooms ( ) [ 0 ] ;
142+ _isInitialized = true ;
143+ }
144+
145+ public void TransitionFromRoom ( int nextRoomIdx )
146+ {
147+ //CurRoom = Map.GetRooms()[nextRoomIdx];
148+ TransitionStage ( Stages . Battle ) ;
116149 }
117150
118151 public void TransitionStage ( Stages nextStage )
@@ -121,12 +154,19 @@ public void TransitionStage(Stages nextStage)
121154 switch ( nextStage )
122155 {
123156 case Stages . Title :
157+ _isInitialized = false ;
124158 GetTree ( ) . ChangeSceneToFile ( "res://scenes/SceneTransitions/TitleScreen.tscn" ) ;
125159 break ;
126160 case Stages . Battle :
127- StartGame ( ) ;
128161 GetTree ( ) . ChangeSceneToFile ( "res://scenes/BattleDirector/test_battle_scene.tscn" ) ;
129162 break ;
163+ case Stages . Map :
164+ GetTree ( ) . ChangeSceneToFile ( "res://scenes/Maps/cartographer.tscn" ) ;
165+ if ( ! _isInitialized )
166+ {
167+ StartGame ( ) ;
168+ }
169+ break ;
130170 case Stages . Quit :
131171 GD . Print ( "Exiting game" ) ;
132172 GetTree ( ) . Quit ( ) ;
0 commit comments