Exemplo n.º 1
0
    public void CreateMapDataBase()
    {
        SpriteMap oceanMap = TextureController.GetAnimations("Mediterranean_map", Color.black);

        Color[] mapPixel = oceanMap.GetAnimation(0).GetSprite(0).texture.GetPixels();
        MAPWIDTH  = (int)oceanMap.GetAnimation(0).GetSprite(0).texture.width;
        MAPHEIGHT = (int)oceanMap.GetAnimation(0).GetSprite(0).texture.height;
        using (Database.DatabaseManager db = new Database.DatabaseManager())
        {
            for (int i = 0; i < mapPixel.Length; i++)
            {
                Color        currentColour = mapPixel[i];
                int          currX         = (i % MAPWIDTH) - 1;
                int          currY         = (Mathf.FloorToInt(i / MAPWIDTH)) - 1;
                Tile.Terrain currTerrain;
                if (currX > 0 && currY > 0 && currX < MAPWIDTH - 2 && currY < MAPHEIGHT - 2)
                {
                    if (mapPixel[i] == Color.black)
                    {
                        currTerrain = Tile.Terrain.ocean;
                    }
                    else
                    {
                        int probability = UnityEngine.Random.Range(0, 10);
                        if (probability < 4)
                        {
                            currTerrain = Tile.Terrain.smooth;
                        }
                        else if (probability < 7)
                        {
                            currTerrain = Tile.Terrain.forest;
                        }
                        else if (probability < 9)
                        {
                            currTerrain = Tile.Terrain.rough;
                        }
                        else
                        {
                            currTerrain = Tile.Terrain.mountain;
                        }
                    }
                    db.Tile.Add(new Tile(currX, currY, currTerrain, TestMain.environmentDomain));
                }
            }
            db.SaveChanges();
        }
    }