using Godot; using System; using System.Collections.Generic; public partial class GridMap2D : Node2D { [Export] public bool _showMarkers = true; public int _cellSize = 16; public Area2D _playArea; public GridMarker _gridMarker; public List> _gridMarkers = new(); public override void _Ready() { base._Ready(); _playArea = GetNode("PlayArea"); _gridMarker = GetNode("GridMarker"); CollisionShape2D bounds = _playArea.GetNode("Bounds"); int gridCellsX = (int)bounds.Shape.GetRect().Size.X / _cellSize, gridCellsY = (int)bounds.Shape.GetRect().Size.Y / _cellSize; for (int i = 0; i < gridCellsY; i++) { _gridMarkers.Add([]); for (int j = 0; j < gridCellsX; j++) { GridMarker newGridMarker = (GridMarker)_gridMarker.Duplicate(); newGridMarker._address = new Vector2(j, i); newGridMarker.Position = new Vector2(_playArea.Position.X - bounds.Shape.GetRect().Size.X / 2 + (j+.5f)*_cellSize, _playArea.Position.Y - bounds.Shape.GetRect().Size.Y / 2 + (i+.5f)*_cellSize); newGridMarker.Modulate = new Color(((i+j)%2 == 0 ? "#ffffff" : "#000000")+(_showMarkers ? "ff" : "00")); _gridMarkers[i].Add(newGridMarker); AddChild(newGridMarker); } } _gridMarker.QueueFree(); } }