Exemple #1
0
    public void LoadMap(Texture2D newMap)
    {
        EmptyMap();

        //for now load all the tiles
        Color32[] pixels = newMap.GetPixels32();
        width  = newMap.width;
        height = newMap.height;

        tiles = new GameTile[width, height];

        //CreateBackground ();
        //TODO:
        //when these maps are eventually loaded separately, we'll need to know how big the total world is first
        //then update the map with offsets, but for now assume this one map is the entire map
        path.InitializeGrid(width, height);

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                Color32 currentPixel   = pixels[(y * width) + x];
                Color32 fullColorPixel = GetFullColor(currentPixel);

                tiles[x, y] = new GameTile();
                if (fullColorPixel.Equals(publicTileData[1].fileColor) && currentPixel.a > 0)
                {
                    LoadTile(x, y, 1);
                }
                else
                {
                    if (fullColorPixel.Equals(playerSpawnColor))
                    {
                        player.transform.position      = new Vector3(x, y, 0);
                        Camera.main.transform.position = new Vector3(x, y, Camera.main.transform.position.z);
                    }

                    LoadTile(x, y, 0);
                    if (currentPixel.a > 0 && colorIds.ContainsKey(fullColorPixel))
                    {
                        blocker.AddFreeTile(colorIds[fullColorPixel], new Vector3(x, y, 0), currentPixel.a);
                    }
                }
            }
        }

        path.AddNeighbors();
        blocker.SortSpawnLists();

        UpdateBitmaskTiles();
    }