added second element type: snow
added simple snow weather
This commit is contained in:
@@ -6,9 +6,7 @@ public class Dirt : Solid {
|
||||
|
||||
public Dirt(int x, int y, ref Level level) : base(x, y, ref level) {
|
||||
Color = Colors.Brown;
|
||||
Color.R += (GD.Randf() - 1) * MaxColorVariance;
|
||||
Color.G += (GD.Randf() - 1) * MaxColorVariance;
|
||||
Color.B += (GD.Randf() - 1) * MaxColorVariance;
|
||||
Color = AddColorVariance(Color);
|
||||
}
|
||||
|
||||
public override bool Update(int currentFrame) {
|
||||
|
||||
@@ -12,7 +12,7 @@ public class Element {
|
||||
|
||||
private int lastUpdate = -1;
|
||||
|
||||
public Element(int x, int y, ref Level level) {
|
||||
public Element(int x, int y, Level level) {
|
||||
Position.X = x;
|
||||
Position.Y = y;
|
||||
Level = level;
|
||||
@@ -52,4 +52,14 @@ public class Element {
|
||||
/// <returns>free position or V2.zero if nothing was found</returns>
|
||||
protected virtual Vector2I Check(Element source, Vector2I maxDirection) {
|
||||
return Vector2I.Zero;
|
||||
}}
|
||||
}
|
||||
|
||||
protected Color AddColorVariance(Color baseColor) {
|
||||
Color c = baseColor;
|
||||
c.R += (GD.Randf() - 1) * MaxColorVariance;
|
||||
c.G += (GD.Randf() - 1) * MaxColorVariance;
|
||||
c.B += (GD.Randf() - 1) * MaxColorVariance;
|
||||
return c;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,24 +3,29 @@
|
||||
namespace FOU.Scripts.Elements;
|
||||
|
||||
public abstract class Liquid : Element {
|
||||
protected Liquid(int x, int y, ref Level level) : base(x, y, ref level) { }
|
||||
protected Liquid(int x, int y, ref Level level) : base(x, y, level) { }
|
||||
|
||||
|
||||
// TODO: rework this!
|
||||
protected override Vector2I Check(Element source, Vector2I maxDirection) {
|
||||
if (GD.Randi() % 2 != 0)
|
||||
maxDirection.X *= -1;
|
||||
|
||||
Vector2I freePos = Vector2I.Zero;
|
||||
for (int y = 0; y <= maxDirection.Y; y++) { // height
|
||||
for (int y = maxDirection.Y; y > 0; y--) { // height
|
||||
if (source.Position.Y + y >= Level.SizeY) return freePos; // bounds check
|
||||
|
||||
// check if we can further
|
||||
if (Level.Get(source.Position.X, source.Position.Y + y).GetType() == typeof(Element)) {
|
||||
freePos = new Vector2I(source.Position.X, source.Position.Y + y);
|
||||
} else {
|
||||
freePos = Vector2I.Zero;
|
||||
}
|
||||
|
||||
for (int x = -maxDirection.X; x <= maxDirection.X; x++) { // width
|
||||
if (freePos != Vector2I.Zero) break;
|
||||
|
||||
if (source.Position.X + x >= Level.SizeX || source.Position.X + x < 0) return freePos; // bounds check
|
||||
if (source.Position.X + x >= Level.SizeX || source.Position.X + x < 0) continue; // bounds check
|
||||
|
||||
if (Level.Get(source.Position.X + x, source.Position.Y + y).GetType() == typeof(Element)) {
|
||||
freePos = new Vector2I(source.Position.X + x, source.Position.Y + y);
|
||||
|
||||
23
Scripts/Elements/Snow.cs
Normal file
23
Scripts/Elements/Snow.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Godot;
|
||||
|
||||
namespace FOU.Scripts.Elements;
|
||||
|
||||
public class Snow : Solid {
|
||||
public Snow(int x, int y, ref Level level) : base(x, y, ref level) {
|
||||
Color = Colors.White;
|
||||
Color = AddColorVariance(Color);
|
||||
}
|
||||
|
||||
public override bool Update(int currentFrame) {
|
||||
if (!base.Update(currentFrame)) return false;
|
||||
|
||||
Vector2I freePos = Check(this, Vector2I.Down);
|
||||
|
||||
if (freePos != Vector2I.Zero) { // diagonally right
|
||||
Level.Swap(this, freePos);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true; // not necessarily end, subclasses could do some more things
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace FOU.Scripts.Elements;
|
||||
|
||||
public abstract class Solid : Element {
|
||||
protected Solid(int x, int y, ref Level level) : base(x, y, ref level) { }
|
||||
protected Solid(int x, int y, ref Level level) : base(x, y, level) { }
|
||||
|
||||
protected Vector2I Check(Element source, Vector2I maxDirection) {
|
||||
if (GD.Randi() % 2 != 0)
|
||||
|
||||
Reference in New Issue
Block a user