added second element type: snow
added simple snow weather
This commit is contained in:
@@ -12,10 +12,12 @@ public class Level {
|
||||
|
||||
private Element[,] _elements;
|
||||
private Level _this;
|
||||
private Main _main;
|
||||
|
||||
public Level(int x, int y) {
|
||||
public Level(int x, int y, Main main) {
|
||||
GD.Print($"Generating level ({x}:{y})");
|
||||
_this = this;
|
||||
_main = main;
|
||||
|
||||
SizeX = x;
|
||||
SizeY = y;
|
||||
@@ -23,7 +25,7 @@ public class Level {
|
||||
_elements = new Element[x, y];
|
||||
for (int i = 0; i < SizeX; i++) {
|
||||
for (int j = 0; j < SizeY; j++) {
|
||||
_elements[i,j] = new Element(i, j, ref _this);
|
||||
_elements[i,j] = new Element(i, j, _this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,16 +41,27 @@ public class Level {
|
||||
}
|
||||
}
|
||||
_frame++;
|
||||
MakeItRain(_main.RainAmount);
|
||||
}
|
||||
|
||||
public void WritePixel(int x, int y, int size) {
|
||||
private void MakeItRain(float rainAmount) {
|
||||
if (GD.Randf() < rainAmount) {
|
||||
WritePixel<Snow>((int)(GD.Randi() % SizeX), 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void WritePixel<T>(int x, int y, int size) {
|
||||
int halfsize = size/2;
|
||||
|
||||
Type type = typeof(T);
|
||||
|
||||
for (int i = -halfsize; i <= halfsize; i++) {
|
||||
for (int j = -halfsize; j <= halfsize; j++) {
|
||||
int X = Mathf.Clamp(x + i, 0, SizeX-1);
|
||||
int Y = Mathf.Clamp(y + j, 0, SizeY-1);
|
||||
_elements[X,Y] = new Dirt(X, Y, ref _this);
|
||||
object o = Activator.CreateInstance(type, X, Y, _this);
|
||||
|
||||
_elements[X,Y] = o as Element;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user