WiP: deactivated array elements

This commit is contained in:
2024-11-03 14:56:07 +01:00
parent d1dac0b855
commit 383e1343ef
6 changed files with 52 additions and 31 deletions

View File

@@ -9,35 +9,27 @@ public partial class Main : Node2D {
[Export] public int BrushSize = 5;
[Export] public float TextureResolution = 0.5f;
[Export] public int ChunksPerAxis = 2;
[Export]
public float RainAmount {
get => rainAmount;
set {
rainAmount = value;
mLevel.SetRainAmount(rainAmount);
}
}
[Export] public float RainAmount = 0;
public static Main Instance;
public Level Level;
private TextureRect mLevelDrawer;
private Level mLevel;
private bool enableRain;
private float rainAmount;
public override void _Ready() {
mLevel = new Level(this, (int)(GetViewportRect().Size.X * TextureResolution),
Level = new Level(this, (int)(GetViewportRect().Size.X * TextureResolution),
(int)(GetViewportRect().Size.Y * TextureResolution));
mLevel.SetRainAmount(rainAmount);
Level.SetRainAmount(rainAmount);
mLevelDrawer = GetNode<TextureRect>("CanvasLayer/LevelDrawer");
Instance = this;
}
public override void _Process(double delta) {
mLevel.Update();
mLevelDrawer.Texture = ImageTexture.CreateFromImage(mLevel.DrawLevel());
Level.Update();
mLevelDrawer.Texture = ImageTexture.CreateFromImage(Level.DrawLevel());
}
public override void _UnhandledInput(InputEvent @event) {
@@ -46,14 +38,14 @@ public partial class Main : Node2D {
if (eventMouseButton.IsPressed()) {
Vector2 mouse = GetViewport().GetMousePosition();
float mappedX = mouse.X / (GetViewportRect().Size.X / mLevel.Resolution.X);
float mappedY = mouse.Y / (GetViewportRect().Size.Y / mLevel.Resolution.Y);
float mappedX = mouse.X / (GetViewportRect().Size.X / Level.Resolution.X);
float mappedY = mouse.Y / (GetViewportRect().Size.Y / Level.Resolution.Y);
mLevel.WritePixel<Dirt>((int)mappedX, (int)mappedY, BrushSize);
Level.WritePixel<Dirt>((int)mappedX, (int)mappedY, BrushSize);
}
} else if (@event is InputEventKey keyEvent && keyEvent.Pressed) {
if (keyEvent.Keycode == Key.F9)
mLevel.StartBenchmark();
Level.StartBenchmark();
}
else base._UnhandledInput(@event);
}