init
This commit is contained in:
44
Scripts/Level.cs
Normal file
44
Scripts/Level.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using FOU.Scripts.Elements;
|
||||
using Godot;
|
||||
|
||||
namespace FOU.Scripts;
|
||||
|
||||
public class Level {
|
||||
private int mSizeX;
|
||||
private int mSizeY;
|
||||
private Image mImage;
|
||||
|
||||
private Element[,] mPixels;
|
||||
|
||||
public Level(int x, int y) {
|
||||
GD.Print($"Generating level ({x}:{y})");
|
||||
|
||||
mSizeX = x;
|
||||
mSizeY = y;
|
||||
|
||||
mPixels = new Element[x, y];
|
||||
mImage = Image.Create(mSizeX, mSizeY, false, Image.Format.Rgb8);
|
||||
mImage.Fill(Colors.Black);
|
||||
}
|
||||
|
||||
public void WritePixel(int x, int y, int size) {
|
||||
for (int i = -size/2; i < size/2; i++) {
|
||||
for (int j = -size/2; j < size/2; j++) {
|
||||
int X = Mathf.Clamp(x + i, 0, mSizeX);
|
||||
int Y = Mathf.Clamp(y + j, 0, mSizeY);
|
||||
mPixels[X,Y] = new Dirt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Image DrawLevel() {
|
||||
for (int x = 0; x < mSizeX; x++) {
|
||||
for (int y = 0; y < mSizeY; y++) {
|
||||
if (mPixels[x,y] == null) continue;
|
||||
|
||||
mImage.SetPixel(x,y, mPixels[x,y].Color);
|
||||
}
|
||||
}
|
||||
return mImage;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user