using UnityEngine; namespace TowerDevil { // Coordinates are local to the board's top edge, with +Y pointing up in uGUI. internal static class BoardLayout { internal const float Width = 750, FrontCell = 106, Gap = 14; const int Count = Run.Size; const float BackCell = FrontCell * .88f; const float Step = (FrontCell - BackCell) / (Count - 1); internal static float Size(float row) => BackCell + Step * Mathf.Clamp(row, 0, Count - 1); internal static float Top(int row) => row * (BackCell + Gap) + Step * row * (row - 1) * .5f; internal static float Height => Top(Count - 1) + FrontCell; internal static Vector2 Center(float row, float col) { // Project the logical half-row boundaries to the midpoint of each gutter. int band = Mathf.Clamp(Mathf.FloorToInt(row + .5f), 0, Count - 1); float y = Top(band) + Size(band) * .5f + (row - band) * (Size(band) + Gap); if (row >= Count - .5f) y -= Gap * .5f; else if (row > Count - 1) y -= (row - Count + 1) * Gap; return new Vector2(Width * .5f + (col - (Count - 1) * .5f) * Size(row), -y); } internal static bool TryCell(Vector2 point, out int row, out int col) { col = -1; for (row = 0; row < Count; row++) { float size = Size(row), y = -point.y - Top(row); if (y < 0 || y >= size - 3) continue; float x = point.x - (Width - Count * size) * .5f; col = Mathf.FloorToInt(x / size); float within = x - col * size; return col >= 0 && col < Count && within >= 1.5f && within < size - 1.5f; } return false; } } }