added dynamic resolution

This commit is contained in:
2023-10-17 12:48:49 +02:00
parent fe40e33d36
commit 094b805ff7
3 changed files with 11 additions and 3 deletions

View File

@@ -5,6 +5,7 @@
[node name="Main" type="Node2D"]
script = ExtResource("1_k1i8e")
BrushSize = 10
TextureResolution = 0.33
[node name="CanvasLayer" type="CanvasLayer" parent="."]

View File

@@ -31,7 +31,7 @@ public class Element {
}
public override string ToString() {
return $"{X}:{Y}";
return $"{GetType()} {X}:{Y}";
}
protected bool CheckBelow(int x, int y) {

View File

@@ -3,12 +3,15 @@ using Godot;
public partial class Main : Node2D {
[Export] public int BrushSize = 5;
[Export] public float TextureResolution = 0.5f;
private TextureRect mLevelDrawer;
private Level mLevel;
public override void _Ready() {
mLevel = new Level((int)GetViewportRect().Size.X, (int)GetViewportRect().Size.Y);
mLevel = new Level((int)(GetViewportRect().Size.X * TextureResolution),
(int)(GetViewportRect().Size.Y * TextureResolution)
);
mLevelDrawer = GetNode<TextureRect>("CanvasLayer/LevelDrawer");
}
@@ -22,7 +25,11 @@ public partial class Main : Node2D {
if (@event is InputEventMouseButton eventMouseButton) {
Vector2 mouse = GetViewport().GetMousePosition();
mLevel.WritePixel((int)mouse.X, (int)mouse.Y, BrushSize);
float mappedX = mouse.X / GetViewportRect().Size.X * mLevel.SizeX;
float mappedY = mouse.Y / GetViewportRect().Size.Y * mLevel.SizeY;
mLevel.WritePixel((int)mappedX, (int)mappedY, BrushSize);
}
}
}