mirror of
https://github.com/TheRavenwoodArts/LunaLightXMG.git
synced 2026-07-30 23:35:02 -07:00
146 lines
5.9 KiB
C#
146 lines
5.9 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
|
|
namespace LunaLightXMG
|
|
{
|
|
public class Platform
|
|
{
|
|
public Vector2 Position { get; private set; }
|
|
public BoundingBox BoundingBox { get; private set; }
|
|
|
|
public Platform(Vector2 position, int width, int height)
|
|
{
|
|
Position = position;
|
|
BoundingBox = new BoundingBox(new Rectangle((int)position.X, (int)position.Y, width, height));
|
|
}
|
|
|
|
public void Draw(SpriteBatch spriteBatch, Texture2D texture)
|
|
{
|
|
spriteBatch.Draw(texture, Position, Color.White);
|
|
}
|
|
}
|
|
|
|
public class PlatformGenerator
|
|
{
|
|
private static Random random = new Random();
|
|
|
|
public static Platform[] CreatePlatforms(int numberOfPlatforms)
|
|
{
|
|
// Bottom wall (static)
|
|
List<Platform> bottomPlatforms = new List<Platform>
|
|
{
|
|
new Platform(new Vector2(0, 164), 16, 16),
|
|
new Platform(new Vector2(16, 164), 16, 16),
|
|
new Platform(new Vector2(32, 164), 16, 16),
|
|
new Platform(new Vector2(48, 164), 16, 16),
|
|
new Platform(new Vector2(64, 164), 16, 16),
|
|
new Platform(new Vector2(80, 164), 16, 16),
|
|
new Platform(new Vector2(96, 164), 16, 16),
|
|
new Platform(new Vector2(112, 164), 16, 16),
|
|
new Platform(new Vector2(128, 164), 16, 16),
|
|
new Platform(new Vector2(144, 164), 16, 16),
|
|
new Platform(new Vector2(160, 164), 16, 16),
|
|
new Platform(new Vector2(176, 164), 16, 16),
|
|
new Platform(new Vector2(192, 164), 16, 16),
|
|
new Platform(new Vector2(208, 164), 16, 16),
|
|
new Platform(new Vector2(224, 164), 16, 16),
|
|
new Platform(new Vector2(240, 164), 16, 16),
|
|
new Platform(new Vector2(256, 164), 16, 16),
|
|
new Platform(new Vector2(272, 164), 16, 16),
|
|
new Platform(new Vector2(288, 164), 16, 16),
|
|
new Platform(new Vector2(304, 164), 16, 16)
|
|
};
|
|
|
|
// Left side wall (static)
|
|
List<Platform> leftSidePlatforms = new List<Platform>
|
|
{
|
|
new Platform(new Vector2(0, -28), 16, 16),
|
|
new Platform(new Vector2(0, -12), 16, 16),
|
|
new Platform(new Vector2(0, 4), 16, 16),
|
|
new Platform(new Vector2(0, 20), 16, 16),
|
|
new Platform(new Vector2(0, 36), 16, 16),
|
|
new Platform(new Vector2(0, 52), 16, 16),
|
|
new Platform(new Vector2(0, 68), 16, 16),
|
|
new Platform(new Vector2(0, 84), 16, 16),
|
|
new Platform(new Vector2(0, 100), 16, 16),
|
|
new Platform(new Vector2(0, 116), 16, 16),
|
|
new Platform(new Vector2(0, 132), 16, 16),
|
|
new Platform(new Vector2(0, 148), 16, 16)
|
|
};
|
|
|
|
// Right side wall (static)
|
|
List<Platform> rightSidePlatforms = new List<Platform>
|
|
{
|
|
new Platform(new Vector2(304, -28), 16, 16),
|
|
new Platform(new Vector2(304, -12), 16, 16),
|
|
new Platform(new Vector2(304, 4), 16, 16),
|
|
new Platform(new Vector2(304, 20), 16, 16),
|
|
new Platform(new Vector2(304, 36), 16, 16),
|
|
new Platform(new Vector2(304, 52), 16, 16),
|
|
new Platform(new Vector2(304, 68), 16, 16),
|
|
new Platform(new Vector2(304, 84), 16, 16),
|
|
new Platform(new Vector2(304, 100), 16, 16),
|
|
new Platform(new Vector2(304, 116), 16, 16),
|
|
new Platform(new Vector2(304, 132), 16, 16),
|
|
new Platform(new Vector2(304, 148), 16, 16)
|
|
};
|
|
// Generate random platforms
|
|
List<Platform> randomizedPlatforms = CreateRandomPlatforms(numberOfPlatforms);
|
|
// Combine all platforms
|
|
List<Platform> allPlatforms = new List<Platform>();
|
|
allPlatforms.AddRange(randomizedPlatforms);
|
|
allPlatforms.AddRange(bottomPlatforms);
|
|
allPlatforms.AddRange(leftSidePlatforms);
|
|
allPlatforms.AddRange(rightSidePlatforms);
|
|
|
|
return allPlatforms.ToArray();
|
|
}
|
|
|
|
public static List<Platform> CreateRandomPlatforms(int numberOfPlatforms)
|
|
{
|
|
List<Platform> platforms = new List<Platform>();
|
|
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));
|
|
platforms.Add(new Platform(new Vector2(288, 132), 16, 16));
|
|
|
|
for (int i = 0; i < numberOfPlatforms; i++)
|
|
{
|
|
bool validPosition = false;
|
|
int x = 0;
|
|
int y = 0;
|
|
|
|
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
|
|
|
|
validPosition = !platforms.Exists(p => p.Position.X == x && p.Position.Y == y);
|
|
|
|
if (!validPosition)
|
|
{
|
|
x += 16;
|
|
if (x > 288)
|
|
{
|
|
x = 16;
|
|
y += 16;
|
|
}
|
|
}
|
|
}
|
|
platforms.Add(new Platform(new Vector2(x, y + 4), 16, 16));
|
|
if (x + 16 < 288)
|
|
{
|
|
for (int j = 1; j < 3; j++)
|
|
{
|
|
platforms.Add(new Platform(new Vector2(x + (j*16), y + 4), 16, 16));
|
|
}
|
|
}
|
|
}
|
|
return platforms;
|
|
}
|
|
}
|
|
}
|
|
|