Esempio n. 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ggo">GroundGameObject</param>
 /// <param name="walkedSteps">WalkedSteps</param>
 /// <param name="pos">Position</param>
 public Node(GroundGameObject ggo, int walkedSteps, Point pos)
 {
     this.ggo         = ggo;
     this.pos         = pos;
     this.walkedSteps = walkedSteps;
     inOpenSet        = evaluvated = false;
 }
Esempio n. 2
0
    /// <summary>
    /// Finds all neighbour hexes and returns them in an array.
    /// </summary>
    /// <param name="posX">X coordinate for unit</param>
    /// <param name="posY">Y coordinate for unit</param>
    /// <returns>Array with neighbour hexes</returns>
    private GroundGameObject[] findNeighboursHex(int posX, int posY)
    {
        GroundGameObject[] neighbours = new GroundGameObject[6];
        int logPos = 0;

        for (int x = 0; x < 3; x++)
        {
            for (int y = 0; y < 3; y++)
            {
                //ignore self
                if (x == 1 && y == 1)
                {
                    continue;
                }
                //ignores two positions based on if y is odd or even
                //this is to simulate the hex grid
                else if (posY % 2 == 0 && x == 2 && (y == 0 || y == 2))
                {
                    continue;
                }
                else if (posY % 2 == 1 && x == 0 && (y == 0 || y == 2))
                {
                    continue;
                }
                //adds neighbour if inside bounds
                if (posX + x - 1 >= 0 && posX + x - 1 < width &&
                    posY + y - 1 >= 0 && posY + y - 1 < height)
                {
                    neighbours[logPos] = field[posX + x - 1, posY + y - 1].GetComponent <GroundGameObject>();
                    logPos++;
                }
            }
        }
        return(neighbours);
    }
Esempio n. 3
0
    /// <summary>
    /// Fills 2d array for groundtiles
    /// </summary>
    public void populateField()
    {
        field = new GameObject[width, height];
        float gx = 0, gy = 0;
        float sx = 1.0f, sy = 1.0f;

        for (int x = 0; x < width; x++)
        {
            float scaleFactorY  = 0.1f;
            float scaleFactorX  = 0.1f;
            float totalRemovedX = 0;
            for (int y = 0; y < height; y++)
            {
                GameObject go = Instantiate(hexagon);
                go.name = "Ground x=" + x + " y=" + y;
                GroundGameObject ggo = go.GetComponent <GroundGameObject>();
                ggo.GraphicalBattlefield = this;
                ggo.LogicalPos           = new Point(x, y);
                field[x, y] = go;
                go.transform.SetParent(parent.transform);

                float fromCenter = ((width / 2) - x) / (width + 0.0f);
                totalRemovedX += (0.5f * fromCenter * ((1 - sx)));
                gx            += (0.5f * fromCenter * ((1 - sx)));
                if (y % 2 == 0)
                {
                    go.transform.localPosition = new Vector2(gx + OFFSETX, gy + OFFSETY);
                }
                else
                {
                    go.transform.localPosition = new Vector2(gx + OFFSETX + ODDOFFSETX, gy + OFFSETY + ODDOFFSETY);
                }
                sy           -= scaleFactorY;
                scaleFactorY *= .6f;

                sx           -= scaleFactorX;
                scaleFactorX *= .3f;

                go.transform.localScale = new Vector3(sx, sy, 1);
                gy += 0.42f - (0.43f * (1 - sy)); // Scaling y axis with the percent scaled down.
            }
            gx -= totalRemovedX;
            gx += 0.43f;
            sy  = sx = 1f;
            gy  = 0;
        }
    }