| 123456789101112131415161718192021222324252627282930313233343536373839 |
- using UnityEngine;
- namespace TowerDevil
- {
- // Coordinates are measured from the back edge of the courtyard; uGUI Y increases upwards.
- internal static class BoardLayout
- {
- internal const float Width = 750, FrontCell = 116;
- const int Count = Run.Size;
- const float BackCell = 107, BackDepth = 91, FrontDepth = 98;
- const float DepthStep = (FrontDepth - BackDepth) / (Count - 1);
- internal static float Size(float row) => Mathf.Lerp(BackCell, FrontCell, row / (Count - 1));
- internal static float Depth(int row) => BackDepth + DepthStep * row;
- internal static float Top(int row) => row * BackDepth + DepthStep * row * (row - 1) * .5f;
- internal static float Height => Top(Count);
- internal static Vector2 Center(float row, float col)
- {
- int band = Mathf.Clamp(Mathf.FloorToInt(row + .5f), 0, Count - 1);
- float y = Top(band) + (row - band + .5f) * Depth(band);
- 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;
- float depth = -point.y;
- for (row = 0; row < Count; row++)
- {
- if (depth < Top(row) || depth >= Top(row + 1)) continue;
- float size = Size(row);
- col = Mathf.FloorToInt((point.x - Width * .5f) / size + Count * .5f);
- return col >= 0 && col < Count;
- }
- return false;
- }
- }
- }
|