Example #1
0
        public Vector3 Hex2Board(CubeCoordinate hex)
        {
            Vector3 position;

            position.y = spacing.y * (hex.z + 0.5f * hex.x);
            position.x = spacing.x * hex.x;
            position.z = 0;
            return(position);
        }
Example #2
0
 public static IEnumerable <CubeCoordinate> Fan(CubeCoordinate center, int radius)
 {
     for ( ; radius >= 0; --radius)
     {
         foreach (var position in Arc(center, radius))
         {
             yield return(position);
         }
     }
 }
Example #3
0
 ICell IBoard.this[CubeCoordinate coord] {
     get {
         if (cells.TryGetValue(coord, out var cell))
         {
             return(cell);
         }
         else
         {
             return(null);
         }
     }
 }
Example #4
0
        public void Destroy(CubeCoordinate coord)
        {
            if (cells.TryGetValue(coord, out var cell) == false)
            {
                return;
            }

            if (cell.block == null)
            {
                return;
            }

            Destroy(cell.block.gameObject);
            cell.block = null;
        }
Example #5
0
        void IBoard.Spawn(CubeCoordinate coord, int count)
        {
            Debug.Assert(count > 0);

            var spawner = cells[coord].GetComponent <Spawner>();

            Debug.Assert(spawner != null, $"Tried to spawn a block from non-spawner cell, {coord}");

            var offset = FlatTopDirection.N * count;
            var p      = coord;

            for (var i = 0; i < count; ++i)
            {
                var cell = cells[p];
                cell.block = SpawnBlock(spawner.Draw(), p + offset);
                anim.Drop(cell);
                p -= FlatTopDirection.N;
            }
        }
Example #6
0
        public static IEnumerable <CubeCoordinate> Ring(CubeCoordinate center, int radius)
        {
            if (radius <= 0f)
            {
                yield return(center);

                yield break;
            }

            var position = center + (around[4] * radius);

            foreach (var dir in around)
            {
                for (var i = 0; i < radius; ++i)
                {
                    yield return(position);

                    position += dir;
                }
            }
        }
Example #7
0
 void IBoard.Drop(CubeCoordinate from, CubeCoordinate to)
 {
     Swap(cells[from], cells[to]);
     Debug.Assert(cells[to].block != null, $"{from} -> {to}");
     anim.Drop(cells[to]);
 }
Example #8
0
 void IBoard.Swap(CubeCoordinate from, CubeCoordinate to)
 {
     Swap(cells[from], cells[to]);
 }
Example #9
0
 bool IBoard.HasCell(CubeCoordinate coord)
 {
     return(cells.ContainsKey(coord));
 }
Example #10
0
 public int Distance(CubeCoordinate subject)
 {
     return(Distance(this, subject));
 }
Example #11
0
 public Line(CubeCoordinate selected, CubeCoordinate direction)
 {
     this.selected  = selected;
     this.direction = direction;
 }
Example #12
0
        public Vector3 Hex2World(CubeCoordinate hex)
        {
            var local = Hex2Board(hex);

            return(transform.TransformPoint(local));
        }
Example #13
0
 private static bool Less(CubeCoordinate a, CubeCoordinate b)
 {
     return(a.r < b.r);
 }
Example #14
0
 public Burst(CubeCoordinate selected)
 {
     target = selected;
 }