From 094b805ff77350d8782624064b96528e033b29c3 Mon Sep 17 00:00:00 2001 From: rogo Date: Tue, 17 Oct 2023 12:48:49 +0200 Subject: [PATCH] added dynamic resolution --- Scenes/main.tscn | 1 + Scripts/Elements/Element.cs | 2 +- Scripts/Main.cs | 11 +++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Scenes/main.tscn b/Scenes/main.tscn index 2b6958e..c663d8a 100644 --- a/Scenes/main.tscn +++ b/Scenes/main.tscn @@ -5,6 +5,7 @@ [node name="Main" type="Node2D"] script = ExtResource("1_k1i8e") BrushSize = 10 +TextureResolution = 0.33 [node name="CanvasLayer" type="CanvasLayer" parent="."] diff --git a/Scripts/Elements/Element.cs b/Scripts/Elements/Element.cs index 3933e02..e8c4253 100644 --- a/Scripts/Elements/Element.cs +++ b/Scripts/Elements/Element.cs @@ -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) { diff --git a/Scripts/Main.cs b/Scripts/Main.cs index d409459..0105cc5 100644 --- a/Scripts/Main.cs +++ b/Scripts/Main.cs @@ -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("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); } } }