fourth commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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<List<GridMarker>> _gridMarkers = new();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
_playArea = GetNode<Area2D>("PlayArea");
|
||||
_gridMarker = GetNode<GridMarker>("GridMarker");
|
||||
CollisionShape2D bounds = _playArea.GetNode<CollisionShape2D>("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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user