finalized dirt

added base for liquids
This commit is contained in:
2023-10-17 14:29:42 +02:00
parent 9145a6a3f9
commit 31dbbbf070
6 changed files with 113 additions and 29 deletions

View File

@@ -1,4 +1,5 @@
using FOU.Scripts.Elements;
using System;
using FOU.Scripts.Elements;
using Godot;
namespace FOU.Scripts;
@@ -63,13 +64,20 @@ public class Level {
return mImage;
}
public void Swap(Element what, int toSwapX, int toSwapY) {
Element old = Get(toSwapX, toSwapY);
Set(old, what.X, what.Y);
Set(what, toSwapX, toSwapY);
public void Swap(Element what, Vector2I swapTo) {
Element old = Get(swapTo);
Set(old, what.Position);
Set(what, swapTo);
}
public Element Get(Vector2I where) {
if (where.X < 0 || where.X >= SizeX) return null;
if (where.Y < 0 || where.Y >= SizeY) return null;
return _elements[where.X, where.Y];
}
public Element Get(int x, int y) {
if (x < 0 || x >= SizeX) return null;
if (y < 0 || y >= SizeY) return null;
@@ -77,12 +85,10 @@ public class Level {
return _elements[x,y];
}
private void Set(Element what, int x, int y) {
private void Set(Element what, Vector2I where) {
if (what == null) return;
what.X = x;
what.Y = y;
_elements[x,y] = what;
what.Position = where;
_elements[where.X, where.Y] = what;
}
}