mirror of
https://github.com/TheRavenwoodArts/LunaLightXMG.git
synced 2026-07-30 23:35:02 -07:00
Added comments to CreateRandomPlatforms().
This commit is contained in:
+11
-2
@@ -101,6 +101,7 @@ namespace LunaLightXMG
|
|||||||
public static List<Platform> CreateRandomPlatforms(int numberOfPlatforms)
|
public static List<Platform> CreateRandomPlatforms(int numberOfPlatforms)
|
||||||
{
|
{
|
||||||
List<Platform> platforms = new List<Platform>();
|
List<Platform> platforms = new List<Platform>();
|
||||||
|
// Static platforms
|
||||||
platforms.Add(new Platform(new Vector2(16, 132), 16, 16));
|
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(128, 132), 16, 16));
|
||||||
platforms.Add(new Platform(new Vector2(176, 132), 16, 16));
|
platforms.Add(new Platform(new Vector2(176, 132), 16, 16));
|
||||||
@@ -112,16 +113,19 @@ namespace LunaLightXMG
|
|||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
|
||||||
|
// Create platforms at random x,y coordinate until a valid position is found.
|
||||||
while (!validPosition)
|
while (!validPosition)
|
||||||
{
|
{
|
||||||
x = random.Next(1, 18) * 16; // Random x multiple of 16 between 16 and 288
|
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
|
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);
|
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)
|
if (!validPosition)
|
||||||
{
|
{
|
||||||
x += 16;
|
x += 16;
|
||||||
|
// If all spaces are taken in that row, move to the above row.
|
||||||
if (x > 288)
|
if (x > 288)
|
||||||
{
|
{
|
||||||
x = 16;
|
x = 16;
|
||||||
@@ -129,12 +133,17 @@ namespace LunaLightXMG
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Add valid platform to the platforms list.
|
||||||
platforms.Add(new Platform(new Vector2(x, y + 4), 16, 16));
|
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)
|
if (x + 16 < 288)
|
||||||
{
|
{
|
||||||
for (int j = 1; j < 3; j++)
|
for (int j = 1; j < 3; j++)
|
||||||
{
|
{
|
||||||
platforms.Add(new Platform(new Vector2(x + (j*16), y + 4), 16, 16));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user