mirror of
https://github.com/TheRavenwoodArts/LunaLightXMG.git
synced 2026-07-30 22:55:03 -07:00
Added comments to CreateRandomPlatforms().
This commit is contained in:
+10
-1
@@ -101,6 +101,7 @@ namespace LunaLightXMG
|
||||
public static List<Platform> CreateRandomPlatforms(int numberOfPlatforms)
|
||||
{
|
||||
List<Platform> platforms = new List<Platform>();
|
||||
// Static platforms
|
||||
platforms.Add(new Platform(new Vector2(16, 132), 16, 16));
|
||||
platforms.Add(new Platform(new Vector2(128, 132), 16, 16));
|
||||
platforms.Add(new Platform(new Vector2(176, 132), 16, 16));
|
||||
@@ -112,16 +113,19 @@ namespace LunaLightXMG
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
// Create platforms at random x,y coordinate until a valid position is found.
|
||||
while (!validPosition)
|
||||
{
|
||||
x = random.Next(1, 18) * 16; // Random x multiple of 16 between 16 and 288
|
||||
y = random.Next(3, 9) * 16; // Random y multiple of 16 between 48 and 132
|
||||
|
||||
// Check if position is already in the platforms list
|
||||
validPosition = !platforms.Exists(p => p.Position.X == x && p.Position.Y == y);
|
||||
|
||||
// If it's already taken, look at the space to the right.
|
||||
if (!validPosition)
|
||||
{
|
||||
x += 16;
|
||||
// If all spaces are taken in that row, move to the above row.
|
||||
if (x > 288)
|
||||
{
|
||||
x = 16;
|
||||
@@ -129,15 +133,20 @@ namespace LunaLightXMG
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add valid platform to the platforms list.
|
||||
platforms.Add(new Platform(new Vector2(x, y + 4), 16, 16));
|
||||
// If we aren't at the end of the row, add two more platforms.
|
||||
if (x + 16 < 288)
|
||||
{
|
||||
for (int j = 1; j < 3; j++)
|
||||
{
|
||||
int nextX = j * 16;
|
||||
if (!platforms.Exists(p => p.Position.X == nextX && p.Position.Y == y)) {
|
||||
platforms.Add(new Platform(new Vector2(x + (j * 16), y + 4), 16, 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return platforms;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user