Example #1
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = (Position != null ? Position.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Radius.GetHashCode();
         hashCode = (hashCode * 397) ^ (ContinentId != null ? ContinentId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ TileX.GetHashCode();
         hashCode = (hashCode * 397) ^ TileY.GetHashCode();
         return(hashCode);
     }
 }
Example #2
0
 public override int GetHashCode()
 {             // based on http://stackoverflow.com/questions/5221396/what-is-an-appropriate-gethashcode-algorithm-for-a-2d-point-struct-avoiding
     unchecked // Overflow is fine, just wrap
     {
         int hash = 17;
         hash = hash * 23 + TileX.GetHashCode();
         hash = hash * 23 + X.GetHashCode();
         hash = hash * 23 + TileY.GetHashCode();
         hash = hash * 23 + Y.GetHashCode();
         return(hash);
     }
 }
Example #3
0
 public TileX[,] getMap()
 {
     if (Tileset == null)
     {
         return(null);
     }
     else
     {
         TileX[,] res = new TileX[Tileset.TilesSize.Width, Tileset.TilesSize.Height];
         for (int i = 0; i < Tileset.TilesSize.Width; i++)
         {
             for (int j = 0; j < Tileset.TilesSize.Height; j++)
             {
                 res[i, j] = new TileX();
             }
         }
         foreach (GameObject obj in childList)
         {
             Vector2 po = Tileset.PositionToTileIndex(obj.transform.position.X, obj.transform.position.Y);
             res[(int)po.X, (int)po.Y] = new TileX(1, TileState.Occupied);
         }
         return(res);
     }
 }
Example #4
0
    //Create Tile Game Objects
    void BuildBaseTiles()
    {
        //Temp
        //map = biomes[0];

        //init counter
        int counter = 0;

        //Base tile locations
        string[] baseTiles = { "Tile Assets/0", "Tile Assets/1", "Tile Assets/2", "Tile Assets/3", "Tile Assets/4", "Tile Assets/5" };


        //cycle map x & y
        for (int x = 0; x < mapSize; x++)
        {
            for (int y = 0; y < mapSize; y++)
            {
                //print out tile type
                Debug.Log(map[x, y]);

                //create new tile as game object
                GameObject tile = new GameObject();

                //name new tile
                tile.name = "Tile " + counter.ToString();

                //Set Tag and sprite strings based on tile type
                string tag = "Plains";
                string sp  = "Tile Assets/0";
                switch (map [x, y])
                {
                case (int)TileType.Plains:
                    tag = "Plains";
                    sp  = baseTiles[0];
                    break;

                case (int)TileType.Desert:
                    tag = "Desert";
                    sp  = baseTiles[1];
                    break;

                case (int)TileType.Swamp:
                    tag = "Swamp";
                    sp  = baseTiles[2];
                    break;

                case (int)TileType.Forest:
                    tag = "Forest";
                    sp  = baseTiles[3];
                    break;

                case (int)TileType.Hills:
                    tag = "Hills";
                    sp  = ((int)primeTile < 3) ? baseTiles [(int)primeTile] : baseTiles [0];
                    break;

                case (int)TileType.River:
                    tag = "River";
                    sp  = baseTiles[4];
                    break;

                case (int)TileType.Mountains:
                    tag = "Mountains";
                    sp  = ((int)primeTile < 3) ? baseTiles [(int)primeTile] : baseTiles [0];
                    break;

                case (int)TileType.Sea:
                    tag = "Sea";
                    sp  = baseTiles[5];
                    break;

                default:
                    tag = "Sea";
                    sp  = baseTiles[5];
                    break;
                }

                //tag new game object
                tile.tag = tag;

                // create new sprite renderer and add it to tile
                SpriteRenderer sr = tile.AddComponent(typeof(SpriteRenderer)) as SpriteRenderer;

                //Set sprite of sprite renderer
                sr.sprite = Resources.Load <Sprite>(sp);

                //Set tile to child of Map game object
                tile.transform.parent = mapContainer.transform;

                //find tile width based on tile size and pixels per unit. Divided by 2 to center tiles TODO: subtract 0.02f to clear lines
                tileWidth = sr.sprite.rect.width / (2 * sr.sprite.pixelsPerUnit);

                //Get new isometric coordinates from cartisian tile map.
                Vector2 loc = stdMath.IsoLocation(x * tileWidth, y * tileWidth);

                //Set z index to seperate tiles in z space to allow for asset placement. TODO: might set z space to 0, and use z space soley for assets and units.
                float zLoc = x + y;

                //apply location to tile
                tile.transform.position = new Vector3(loc.x, loc.y, zLoc);

                //Attatch tile script
                TileX t = tile.AddComponent(typeof(TileX)) as TileX;

                //initialize tile script variables
                t.tileSR         = sr;
                t.stdMath        = stdMath;
                t.tileType       = map[x, y];
                t.primeType      = (int)primeTile;
                t.TileLoc        = tile.transform.position;
                t.MapLoc         = new Vector2(x, y);
                t.tileWidth      = tileWidth;
                t.tilePixelWidth = sr.sprite.rect.width;
                t.tilePPU        = sr.sprite.pixelsPerUnit;
                t.tileSize       = sr.sprite.rect.width / sr.sprite.pixelsPerUnit;
                t.zBack          = zLoc + 0.0001f;
                t.zFront         = zLoc - 0.9999f;
                t.SetupTile();

                //increment bounds
                mapBounds.Encapsulate(sr.bounds);

                //increment counter
                counter++;
            }
        }
    }