@@ -62,7 +62,7 @@ public float ObstacleSpawnChance
62
62
/// <summary>
63
63
/// The current chunks the manager is dealing with
64
64
/// </summary>
65
- public List < Chunk > Chunks ;
65
+ public Queue < Chunk > Chunks ;
66
66
67
67
/// <summary>
68
68
/// The right side of the chunk that is furthest right
@@ -107,7 +107,7 @@ public float ObstacleSpawnChance
107
107
108
108
public ChunkManager ( Rectangle viewport )
109
109
{
110
- Chunks = new List < Chunk > ( ) ;
110
+ Chunks = new Queue < Chunk > ( ) ;
111
111
_screenWidth = viewport . Width ;
112
112
_startingViewport = viewport ;
113
113
}
@@ -135,11 +135,11 @@ public void Update(int leftOfScreen, int rightOfScreen)
135
135
// check if the first chunk is outside of the screen, if it is then destroy it
136
136
if ( Chunks . Count > 0 )
137
137
{
138
- bool firstChunkIsOutsideScreen = Chunks [ 0 ] . DestinationRectangle . Right < leftOfScreen ;
138
+ bool firstChunkIsOutsideScreen = Chunks . Peek ( ) . DestinationRectangle . Right < leftOfScreen ;
139
139
140
140
if ( firstChunkIsOutsideScreen )
141
141
{
142
- DestroyChunkAt ( 0 ) ;
142
+ DestroyChunk ( ) ;
143
143
GenerateRandomChunk ( ) ;
144
144
}
145
145
}
@@ -172,7 +172,7 @@ public void Add(Chunk chunk)
172
172
Right = chunk . BoundingBox . Right ;
173
173
174
174
// Add chunk
175
- Chunks . Add ( chunk ) ;
175
+ Chunks . Enqueue ( chunk ) ;
176
176
}
177
177
178
178
public CollisionReason CheckCollision ( Rectangle playerBoundingBox )
@@ -349,18 +349,18 @@ private void GenerateRandomChunk()
349
349
350
350
private void GenerateStart ( )
351
351
{
352
- while ( _startingViewport . Right + _defaultChunkWidth * 2 > Right )
352
+ while ( _startingViewport . Right + _defaultChunkWidth > Right + _defaultChunkWidth )
353
353
{
354
354
GenerateNormalChunk ( ) ;
355
355
}
356
356
}
357
357
358
- private void DestroyChunkAt ( int index )
358
+ private void DestroyChunk ( )
359
359
{
360
360
// Try and remove the chunk at the specified index
361
- if ( Chunks != null && Chunks . Count - 1 >= index )
361
+ if ( Chunks != null && Chunks . Count > 0 )
362
362
{
363
- Chunks . RemoveAt ( index ) ;
363
+ Chunks . Dequeue ( ) ;
364
364
Left = Chunks . First ( ) . BoundingBox . Left ;
365
365
}
366
366
}
0 commit comments