hierarchy rework
fixed swap
This commit is contained in:
@@ -46,7 +46,7 @@ public class Level {
|
||||
|
||||
private void MakeItRain(float rainAmount) {
|
||||
if (GD.Randf() < rainAmount) {
|
||||
WritePixel<Snow>((int)(GD.Randi() % SizeX), 0, 1);
|
||||
WritePixel<Water>((int)(GD.Randi() % SizeX), 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,20 +69,25 @@ public class Level {
|
||||
public Image DrawLevel() {
|
||||
for (int x = 0; x < SizeX; x++) {
|
||||
for (int y = 0; y < SizeY; y++) {
|
||||
// if (_elements[x,y] == null) continue;
|
||||
|
||||
mImage.SetPixel(x,y, _elements[x,y].Color);
|
||||
}
|
||||
}
|
||||
return mImage;
|
||||
}
|
||||
|
||||
public void Swap(Element what, Vector2I swapTo) {
|
||||
Element old = Get(swapTo);
|
||||
Set(old, what.Position);
|
||||
Set(what, swapTo);
|
||||
public void Swap(Element what, Element swapTo) {
|
||||
Element swap = new Element(what);
|
||||
|
||||
what.Position = swapTo.Position;
|
||||
_elements[swapTo.Position.X, swapTo.Position.Y] = what;
|
||||
|
||||
swapTo.Position = swap.Position;
|
||||
_elements[swap.Position.X, swap.Position.Y] = swapTo;
|
||||
}
|
||||
|
||||
public void Swap(Element what, Vector2I pos) {
|
||||
Swap(what, Get(pos));
|
||||
}
|
||||
|
||||
public Element Get(Vector2I where) {
|
||||
if (where.X < 0 || where.X >= SizeX) return null;
|
||||
@@ -98,10 +103,10 @@ public class Level {
|
||||
return _elements[x,y];
|
||||
}
|
||||
|
||||
private void Set(Element what, Vector2I where) {
|
||||
if (what == null) return;
|
||||
public bool IsEmpty(Vector2I pos) {
|
||||
if (pos.X < 0 || pos.X >= SizeX) return false;
|
||||
if (pos.Y < 0 || pos.Y >= SizeY) return false;
|
||||
|
||||
what.Position = where;
|
||||
_elements[where.X, where.Y] = what;
|
||||
return Get(pos).GetType() == typeof(Element);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user