added dynamic resolution
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
[node name="Main" type="Node2D"]
|
[node name="Main" type="Node2D"]
|
||||||
script = ExtResource("1_k1i8e")
|
script = ExtResource("1_k1i8e")
|
||||||
BrushSize = 10
|
BrushSize = 10
|
||||||
|
TextureResolution = 0.33
|
||||||
|
|
||||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
return $"{X}:{Y}";
|
return $"{GetType()} {X}:{Y}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool CheckBelow(int x, int y) {
|
protected bool CheckBelow(int x, int y) {
|
||||||
|
|||||||
@@ -3,12 +3,15 @@ using Godot;
|
|||||||
|
|
||||||
public partial class Main : Node2D {
|
public partial class Main : Node2D {
|
||||||
[Export] public int BrushSize = 5;
|
[Export] public int BrushSize = 5;
|
||||||
|
[Export] public float TextureResolution = 0.5f;
|
||||||
|
|
||||||
private TextureRect mLevelDrawer;
|
private TextureRect mLevelDrawer;
|
||||||
private Level mLevel;
|
private Level mLevel;
|
||||||
|
|
||||||
public override void _Ready() {
|
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");
|
mLevelDrawer = GetNode<TextureRect>("CanvasLayer/LevelDrawer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +25,11 @@ public partial class Main : Node2D {
|
|||||||
if (@event is InputEventMouseButton eventMouseButton) {
|
if (@event is InputEventMouseButton eventMouseButton) {
|
||||||
|
|
||||||
Vector2 mouse = GetViewport().GetMousePosition();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user