Exemplo n.º 1
0
        public bool GetHexData(Hex hex, bool wrapIfNull, out TileObject obj)
        {
            if (wrapIfNull && !TileData.ContainsKey(hex) && !HexUtils.HexOutOfBounds(size, hex, wrapIfNull))
            {
                hex = HexUtils.WrapOffset(hex, size.x);
            }

            return(TileData.TryGetValue(hex, out obj));
        }
Exemplo n.º 2
0
        private void Generate()
        {
            GameObject line = new GameObject();
            var        lr   = line.AddComponent <LineRenderer>();

            lr.positionCount = 5;
            lr.SetPosition(0, new Vector3(0, 0, -1));
            lr.SetPosition(1, new Vector3(m_world.pixelW, 0, -1));
            lr.SetPosition(2, new Vector3(m_world.pixelW, m_world.pixelH, -1));
            lr.SetPosition(3, new Vector3(0, m_world.pixelH, -1));
            lr.SetPosition(4, new Vector3(0, 0, -1));
            lr.startWidth = 2;
            lr.endWidth   = 2;

            for (int i = 0; i < m_world.settings.plates; i++)
            {
                int x = m_rand.NextInt(0, m_world.pixelW);
                int y = m_rand.NextInt(0, m_world.pixelH);

                Hex hex = m_layout.PixelToHex(new Point(x, y)).HexRound();

                Plate p = new Plate(this, hex, UnityEngine.Random.ColorHSV())
                {
                    elevation     = Random.Range(0f, 255f),
                    movementSpeed = m_rand.NextFloat(MIN_SPD, MAX_SPD),
                    direction     = (HexDirection)Random.Range(0, HexConstants.DIRECTIONS - 1),
                };
                m_world.AddPlate(p);
            }

            /*
             *  ------------------------------------------------------
             *      Setting hexes to plates
             *  ------------------------------------------------------
             */
            foreach (var pair in m_world.TileData)
            {
                int closestId = 0;
                int closest   = int.MaxValue;
                for (int i = 0; i < m_world.settings.plates; i++)
                {
                    int dist = pair.Key.Distance(m_world.plates[i].center);

                    if (closest > dist)
                    {
                        closest   = dist;
                        closestId = i;
                    }
                }
                for (int i = 0; i < m_world.settings.plates; i++)
                {
                    int dist = pair.Key.Distance(HexUtils.WrapOffset(m_world.plates[i].center, m_world.size.x));

                    if (closest > dist)
                    {
                        closest   = dist;
                        closestId = i;
                    }
                }
                pair.Value.hexData.plateId    = m_world.GetPlates()[closestId].id;
                pair.Value.hexData.oldPlateId = m_world.GetPlates()[closestId].id;
                m_world.GetPlates()[closestId].AddHex(pair.Key);
            }
        }
Exemplo n.º 3
0
 public TileObject GetWrappedHex(Hex hex)
 {
     return(TileData[HexUtils.WrapOffset(hex, size.x)]);
 }