diff --git a/.idea/.idea.AceField New Horizon/.idea/vcs.xml b/.idea/.idea.AceField New Horizon/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/.idea.AceField New Horizon/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Scenes/Root.tscn b/Scenes/Root.tscn
index ec9820e..6fe2e0d 100644
--- a/Scenes/Root.tscn
+++ b/Scenes/Root.tscn
@@ -19,4 +19,4 @@ Grid = NodePath("../GridSystem")
[node name="Player" parent="." instance=ExtResource("3_oss8w")]
position = Vector2(602, 324)
-scale = Vector2(0.5, 0.5)
+scale = Vector2(0.35, 0.35)
diff --git a/Scripts/System/PlacementManager.cs b/Scripts/System/PlacementManager.cs
index 810c05e..b3275d4 100644
--- a/Scripts/System/PlacementManager.cs
+++ b/Scripts/System/PlacementManager.cs
@@ -24,13 +24,29 @@ public partial class PlacementManager : Node2D
AddChild(_ghostBuilding);
}
- _ghostBuilding.Position = GridUtils.GridToWorld(_hoveredCell);
- _ghostBuilding.SetGhostMode(true);
+ var placementPos = GridUtils.GridToWorld(_hoveredCell);
+ var spaceState = GetWorld2D().DirectSpaceState;
+ var centerPos = placementPos + new Vector2(GridUtils.TileSize / 2f, GridUtils.TileSize / 2f);
+
+ var query = new PhysicsPointQueryParameters2D
+ {
+ Position = centerPos,
+ CollideWithBodies = true,
+ CollideWithAreas = true,
+ CollisionMask = uint.MaxValue // check against all layers/masks
+ // Exclude = new Godot.Collections.Array() // optional, see below
+ };
+
+ var collision = spaceState.IntersectPoint(query, 8);
+ var canPlace = Grid.IsCellFree(_hoveredCell) && collision.Count == 0;
+
+ _ghostBuilding.Position = placementPos;
+ _ghostBuilding.SetGhostMode(canPlace);
// Left click to place
- if (!Input.IsActionPressed("build_tile") || !Grid.IsCellFree(_hoveredCell)) return;
+ if (!Input.IsActionPressed("build_tile") || !canPlace) return;
- _ghostBuilding.SetGhostMode(false);
+ _ghostBuilding.FinalizePlacement();
Grid.OccupyCell(_hoveredCell, _ghostBuilding);
_ghostBuilding = (BaseTile)BuildingScene.Instantiate();
diff --git a/Scripts/Tiles/BaseTile.cs b/Scripts/Tiles/BaseTile.cs
index 915c330..06df515 100644
--- a/Scripts/Tiles/BaseTile.cs
+++ b/Scripts/Tiles/BaseTile.cs
@@ -1,30 +1,45 @@
using Godot;
-namespace AceFieldNewHorizon.Scripts.Tiles;
-
-public partial class BaseTile : Node2D
+namespace AceFieldNewHorizon.Scripts.Tiles
{
- protected CollisionShape2D CollisionShape;
- protected Sprite2D Sprite;
-
- public override void _Ready()
+ public partial class BaseTile : Node2D
{
- // Get references (optional: you can also Export and assign in editor)
- CollisionShape = GetNode("CollisionShape2D");
- Sprite = GetNode("Sprite2D");
- }
+ private CollisionShape2D _collisionShape;
+ private Sprite2D _sprite;
- public void SetGhostMode(bool ghost)
- {
- if (CollisionShape != null)
- CollisionShape.Disabled = ghost;
-
- if (Sprite != null)
+ public override void _Ready()
{
- if (ghost)
- Sprite.Modulate = new Color(1, 1, 1, 0.5f); // semi-transparent
- else
- Sprite.Modulate = Colors.White;
+ _collisionShape = GetNodeOrNull("CollisionShape2D");
+ _sprite = GetNodeOrNull("Sprite2D");
+ }
+
+ ///
+ /// Switch between ghost and placed mode.
+ ///
+ /// If in ghost mode, true = green, false = red. If placed, always white.
+ public void SetGhostMode(bool canPlace)
+ {
+ if (_collisionShape != null)
+ _collisionShape.Disabled = true; // always disabled in ghost mode
+
+ if (_sprite != null)
+ {
+ // Ghost preview coloring
+ _sprite.Modulate = canPlace ? new Color(1, 1, 1, 0.2f) : // white semi-transparent
+ new Color(1, 0, 0, 0.2f); // red semi-transparent
+ }
+ }
+
+ ///
+ /// Call when placement is finalized.
+ ///
+ public void FinalizePlacement()
+ {
+ if (_collisionShape != null)
+ _collisionShape.Disabled = false;
+
+ if (_sprite != null)
+ _sprite.Modulate = Colors.White; // reset to normal
}
}
}
\ No newline at end of file
diff --git a/project.godot b/project.godot
index 62a8eeb..f7e292b 100644
--- a/project.godot
+++ b/project.godot
@@ -15,6 +15,10 @@ run/main_scene="uid://c22aprj452aha"
config/features=PackedStringArray("4.4", "C#", "GL Compatibility")
config/icon="res://icon.svg"
+[display]
+
+window/stretch/mode="viewport"
+
[dotnet]
project/assembly_name="AceField New Horizon"