コード例 #1
0
ファイル: MapGenerator.cs プロジェクト: noesmos/BF2
        public GameObject[,] DrawWorld(float[,] map, GameObject pfTile)
        {
            int width  = map.GetLength(0);
            int length = map.GetLength(1);

            // Create game objects for eahc Tile.
            GameObject[,] world = new GameObject[width, length];

            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < length; z++)
                {
                    Vector3 pos = new Vector3(x * 1.56f, map[x, z] / 4, z * 1.8f + ((x % 2 == 0) ? 0f : 0.9f)); // Optimize Later
                    // Assign values to each Tile.
                    world[x, z] = Instantiate(pfTile, pos, Quaternion.identity) as GameObject;
                    Vector2        gridID   = new Vector2(x, z);
                    HexCoordinates hexCoord = HexCoordinates.FromOffsetCoordinate(x, z);
                    GameObject     go       = world[x, z];
                    go.name = hexCoord.ToString();// gridID.ToString();
                    go.transform.Rotate(0.0f, 30.0f, 0.0f, Space.Self);

                    Tile grt = world[x, z].GetComponent <Tile>();
                    grt.Elevation = map[x, z];// Mathf.Sqrt( Mathf.Pow(map[x, z], 2)/2);
                    grt.Position  = pos;
                    grt.GridID    = gridID;
                    grt.HexCoord  = hexCoord;

                    GameObject     child      = go.transform.GetChild(0).gameObject;
                    SpriteRenderer coreSprite = child.GetComponent <SpriteRenderer>();
                    coreSprite.color = new Color((0 + grt.Elevation / 4), (1 - grt.Elevation / 4), 0); // optimize later
                }
            }

            worldLocal = world;
            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < length; z++)
                {
                    GameObject go  = world[x, z];
                    Tile       grt = go.GetComponent <Tile>();
                    grt.Neighbours = GetNeighbours(grt.GridID);
                }
            }
            return(world);
        }
コード例 #2
0
 public static Vector3 HexDifference(HexCoordinates from, HexCoordinates to)
 {
     return(new Vector3(from.X - to.X, from.Y - to.Y, from.Z - to.Z));
 }
コード例 #3
0
 public static int ManhattanDistance(HexCoordinates from, HexCoordinates to)
 {
     return((Mathf.Abs(from.X - to.X) + Mathf.Abs(from.Y - to.Y) + Mathf.Abs(from.Z - to.Z)) / 2);
 }
コード例 #4
0
        public Tile GetNeighbourInDirection(Vector3 direction)
        {
            HexCoordinates neighbourHex = HexCoord.GetNeighBourHexCoordinates(direction);

            return(GetNeighbourTileByHexCoordinate(neighbourHex));
        }
コード例 #5
0
 private static int GetTileDistance(Tile from, Tile to)
 {
     return(HexCoordinates.ManhattanDistance(from.HexCoord, to.HexCoord)); // add considerations to terrain features and elevation later
 }