Skip to content

Commit 10c3223

Browse files
committed
fixed chunk missing on title screen
1 parent 34fa3f2 commit 10c3223

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Jump/Jump/ChunkManager.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public float ObstacleSpawnChance
6262
/// <summary>
6363
/// The current chunks the manager is dealing with
6464
/// </summary>
65-
public List<Chunk> Chunks;
65+
public Queue<Chunk> Chunks;
6666

6767
/// <summary>
6868
/// The right side of the chunk that is furthest right
@@ -107,7 +107,7 @@ public float ObstacleSpawnChance
107107

108108
public ChunkManager(Rectangle viewport)
109109
{
110-
Chunks = new List<Chunk>();
110+
Chunks = new Queue<Chunk>();
111111
_screenWidth = viewport.Width;
112112
_startingViewport = viewport;
113113
}
@@ -135,11 +135,11 @@ public void Update(int leftOfScreen, int rightOfScreen)
135135
// check if the first chunk is outside of the screen, if it is then destroy it
136136
if (Chunks.Count > 0)
137137
{
138-
bool firstChunkIsOutsideScreen = Chunks[0].DestinationRectangle.Right < leftOfScreen;
138+
bool firstChunkIsOutsideScreen = Chunks.Peek().DestinationRectangle.Right < leftOfScreen;
139139

140140
if (firstChunkIsOutsideScreen)
141141
{
142-
DestroyChunkAt(0);
142+
DestroyChunk();
143143
GenerateRandomChunk();
144144
}
145145
}
@@ -172,7 +172,7 @@ public void Add(Chunk chunk)
172172
Right = chunk.BoundingBox.Right;
173173

174174
// Add chunk
175-
Chunks.Add(chunk);
175+
Chunks.Enqueue(chunk);
176176
}
177177

178178
public CollisionReason CheckCollision(Rectangle playerBoundingBox)
@@ -349,18 +349,18 @@ private void GenerateRandomChunk()
349349

350350
private void GenerateStart()
351351
{
352-
while (_startingViewport.Right + _defaultChunkWidth*2 > Right)
352+
while (_startingViewport.Right + _defaultChunkWidth > Right + _defaultChunkWidth)
353353
{
354354
GenerateNormalChunk();
355355
}
356356
}
357357

358-
private void DestroyChunkAt(int index)
358+
private void DestroyChunk()
359359
{
360360
// Try and remove the chunk at the specified index
361-
if (Chunks != null && Chunks.Count-1 >= index)
361+
if (Chunks != null && Chunks.Count > 0)
362362
{
363-
Chunks.RemoveAt(index);
363+
Chunks.Dequeue();
364364
Left = Chunks.First().BoundingBox.Left;
365365
}
366366
}

0 commit comments

Comments
 (0)