Files
peggle-roguelike/GridMap.cs
T
2026-05-28 00:06:51 -04:00

35 lines
1.4 KiB
C#

using Godot;
using System;
using System.Collections.Generic;
public partial class GridMap : Node2D
{
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");
_gridMarkers[i].Add(newGridMarker);
AddChild(newGridMarker);
}
}
_gridMarker.QueueFree();
}
}