Пример #1
0
        public void BuildTileRecursive(HexTile t)
        {
            for (int i = 0; i < t.neighbours.Length; i++)
            {
                HexCoordCubic n = HexCoordCubic.Neighbour(t.HexCoord, i);
                if (!t.neighbours[i] && LegalCoordinates(n))
                {
                    HexTile tn;
                    if (QrList.TryGetValue(n, out tn))
                    {
                        int j = (i + 3) % 6;
                        t.neighbours[i]  = tn;
                        tn.neighbours[j] = t;
                    }
                    else
                    {
                        tn = Instantiate(tilePrefab, transform);
                        tn.Setup(n, flatHead);
                        QrList.Add(n, tn);

                        int j = (i + 3) % 6;
                        t.neighbours[i]  = tn;
                        tn.neighbours[j] = t;
                        BuildTileRecursive(tn);
                    }
                }
            }
        }
Пример #2
0
        public static HexCoordCubic Neighbour(HexCoordCubic origin, HexDirectionFlat dir)
        {
            switch (dir)
            {
            case HexDirectionFlat.UP:
                return(origin + FLAT_UP);

            case HexDirectionFlat.UP_LEFT:
                return(origin + FLAT_UP_LEFT);

            case HexDirectionFlat.DOWN_LEFT:
                return(origin + FLAT_DOWN_LEFT);

            case HexDirectionFlat.DOWN:
                return(origin + FLAT_DOWN);

            case HexDirectionFlat.DOWN_RIGHT:
                return(origin + FLAT_DOWN_RIGHT);

            case HexDirectionFlat.UP_RIGHT:
                return(origin + FLAT_UP_RIGHT);
            }
            //default - should never happen
            return(origin);
        }
Пример #3
0
        public override void OnTileBuilt(HexTile tile)
        {
            HexCoordCubic pos = tile.HexCoord;

            if (Mathf.Approximately(pos.q, qLength.x) ||
                Mathf.Approximately(pos.q, qLength.y) ||
                Mathf.Approximately(pos.r, rLength.x) ||
                Mathf.Approximately(pos.r, rLength.y)
                )
            {
                tile.Terrain = TerrainType.rock;
            }
        }
Пример #4
0
 public bool BuildOrGetTile(HexCoordCubic pos, out HexTile tile)
 {
     if (tileMap.TryGetValue(pos, out tile))
     {
         return(true);
     }
     if (IsValidInMap(pos))
     {
         tile = Instantiate(TilePrefab, transform);
         tile.Setup(pos, flathead);
         tileMap.Add(pos, tile);
         OnTileBuilt(tile);
         return(true);
     }
     return(false);
 }
Пример #5
0
 protected virtual void BuildMap2(HexTile t)
 {
     for (int i = 0; i < t.neighbours.Length; i++)
     {
         HexCoordCubic n = HexCoordCubic.Neighbour(t.HexCoord, i);
         HexTile       tn;
         if (!t.neighbours[i])
         {
             if (BuildOrGetTile(n, out tn))
             {
                 int j = (i + 3) % 6;
                 t.neighbours[i]  = tn;
                 tn.neighbours[j] = t;
                 BuildMap2(tn);
             }
         }
     }
 }
Пример #6
0
        //protected HexTile center;

        public void Setup(HexCoordCubic hexCoord, bool flathead)
        {
            //Debug.Log(string.Format("Setting up hex tile at q {0} r {1} s {2}", hexCoord.q, hexCoord.r, hexCoord.s));
            //this.center = center;
            this.flathead = flathead;
            HexCoord      = hexCoord;
            neighbours    = new HexTile[6];

            name = String.Format("Hextile QRS ( {0} {1} {2} )", hexCoord.q, hexCoord.r, hexCoord.s);

            rend = GetComponentInChildren <Renderer>();
            if (flathead)
            {
                rend.transform.localRotation = Quaternion.Euler(-90, 30, 0);
            }
            else
            {
                rend.transform.localRotation = Quaternion.Euler(-90, 0, 0);
            }
        }
Пример #7
0
        //end recursive cunstructor



        //creates or updates map whenever radius has been changed!
        //public void BuildMap()
        //{
        //	ringList = ringList ?? new List<List<HexTile>>(radius+1);

        //	//Building map from rings
        //	for (int i = 0; i <= radius; i++)
        //	{
        //		if (ringList.Count <= i)
        //			ringList.Add(BuildRing(i));
        //	}

        //	HexTile[] HexList = gameObject.GetComponentsInChildren<HexTile>();
        //	//setting up QrList of the tiles.
        //	int length = radius*2 + 1;
        //	QrList = new List<List<HexTile>>(length);
        //	//QrList.Add

        //	for (int i=-radius; i<= radius; i++)
        //	{
        //		List<HexTile> qList = HexList.Where((HexTile arg1) => arg1.HexCoord.q == i).OrderBy((HexTile arg1) => arg1.HexCoord.r).ToList();
        //		QrList.Add(qList);
        //	}

        //}
        public List <HexTile> BuildRing(int r)
        {
            List <HexTile> ring = new List <HexTile>(r * 6);

            if (r > 0)
            {
                HexCoordCubic tc = HexCoordCubic.FLAT_DOWN_RIGHT * r;
                HexTile       t  = Instantiate(tilePrefab, transform);
                t.Setup(tc, this);
                ring.Add(t);

                //for(HexDirectionFlat dir = HexDirectionFlat.UP; dir <= HexDirectionFlat.UP_RIGHT; dir++)
                for (int i = 0; i < 6; i++)
                {
                    for (int j = 0; j < r; j++)
                    {
                        HexDirectionFlat dir = (HexDirectionFlat)i;
                        tc = HexCoordCubic.Neighbour(tc, dir);
                        t  = Instantiate(tilePrefab, transform);
                        t.Setup(tc, this);
                        ring.Add(t);
                    }
                }
            }
            else
            {
                ring.Add(center);
            }
            return(ring);

//function cube_ring(center, radius):
//    var results = []
//    # this code doesn't work for radius == 0; can you see why?
//    var cube = cube_add(center,
//                        cube_scale(cube_direction(4), radius))
//    for each 0 ≤ i < 6:
//        for each 0 ≤ j < radius:
//            results.append(cube)
//            cube = cube_neighbor(cube, i)
//    return results
        }
Пример #8
0
 public bool LegalCoordinates(HexCoordCubic n)
 {
     return(n.Ring <= radius);
 }
Пример #9
0
 public override bool IsValidInMap(HexCoordCubic pos)
 {
     return(pos.q >= qLength.x && pos.q <= qLength.y && pos.r >= rLength.x && pos.r <= rLength.y);
 }
Пример #10
0
 public override bool IsValidInMap(HexCoordCubic pos)
 {
     return(pos.Ring <= size);
 }
Пример #11
0
        public override bool IsValidInMap(HexCoordCubic pos)
        {
            Vector3 p = pos.ToVector3(flathead);

            return(p.x >= xLength.x && p.x <= xLength.y && p.z >= zLength.x && p.z <= zLength.y);
        }
Пример #12
0
        public static HexCoordCubic Neighbour(HexCoordCubic origin, int dir)
        {
            HexDirectionFlat flatConvert = (HexDirectionFlat)dir;

            return(Neighbour(origin, flatConvert));
        }
Пример #13
0
 public virtual bool IsValidInMap(HexCoordCubic pos)
 {
     return(pos.Ring <= 3);
 }