Files
FOU/Scripts/Main.cs
2023-11-05 20:09:18 +01:00

39 lines
1.1 KiB
C#

using FOU.Scripts;
using FOU.Scripts.Elements;
using Godot;
public partial class Main : Node2D {
[Export] public int BrushSize = 5;
[Export] public float TextureResolution = 0.5f;
[Export] public float RainAmount = 0.01f;
private TextureRect mLevelDrawer;
private Level mLevel;
public override void _Ready() {
mLevel = new Level((int)(GetViewportRect().Size.X * TextureResolution),
(int)(GetViewportRect().Size.Y * TextureResolution), this
);
mLevelDrawer = GetNode<TextureRect>("CanvasLayer/LevelDrawer");
}
public override void _Process(double delta) {
mLevel.Update();
mLevelDrawer.Texture = ImageTexture.CreateFromImage(mLevel.DrawLevel());
}
public override void _Input(InputEvent @event) {
if (@event is InputEventMouseButton eventMouseButton) {
Vector2 mouse = GetViewport().GetMousePosition();
float mappedX = mouse.X / GetViewportRect().Size.X * mLevel.SizeX;
float mappedY = mouse.Y / GetViewportRect().Size.Y * mLevel.SizeY;
GD.Print($"click: {mouse}");
mLevel.WritePixel<Dirt>((int)mappedX, (int)mappedY, BrushSize);
}
}
}