Exemple #1
0
    private void loadLevelTMX(string aFileName)
    {
        TmxMap tmxMap     = new TmxMap(aFileName);
        int    mapWidth   = tmxMap.Width;
        int    mapHeight  = tmxMap.Height;
        int    tileWidth  = tmxMap.TileWidth;
        int    tileHeight = tmxMap.TileHeight;
        int    scale      = 2;

        setMapWidth(tmxMap.Width);
        setMapHeight(tmxMap.Height);
        setTileWidth(tileWidth * scale);
        setTileHeight(tileHeight * scale);

        mMap = new List <List <CTile> >();
        string tileSetPath = tmxMap.Tilesets[0].Image.Source.Replace("Assets/Resources/", "");

        tileSetPath = tileSetPath.Replace(".png", "");
        mTiles      = Resources.LoadAll <Sprite> (tileSetPath);
        for (int y = 0; y < mapHeight; y++)
        {
            List <CTile> row = new List <CTile>();

            for (int x = 0; x < mapWidth; x++)
            {
                CTile tile = new CTile((x * mTileWidth), (y * mTileHeight), 0, mTiles[AIR_INDEX], scale);
                tile.setVisible(true);
                tile.render();
                row.Add(tile);
            }

            mMap.Add(row);
        }

        for (int i = 0; i < tmxMap.Layers[0].Tiles.Count; i++)
        {
            int y = i / mapWidth;
            int x = i % mapWidth;
            // TODO: PONER UNA SOLA LINEA
            int index = tmxMap.Layers[0].Tiles[i].Gid;         // 0 a 21
            getTile(x, y).setTileIndex(index);

            //getTile (x, y).setWalkable (mWalkable [index]); NO APLICA.
            getTile(x, y).setImage(mTiles[index - 1]);           // 0 a 21
        }

        foreach (var spawnPoint in tmxMap.ObjectGroups["Enemy Spawns"].Objects)
        {
            CEnemyManager.inst().spawnEnemy((float)spawnPoint.X * scale, (float)spawnPoint.Y * scale, Int32.Parse(spawnPoint.Type));
        }
    }