Пример #1
0
    public CTileMap(string aFileName)
    {
        loadLevelTMX(aFileName);

        // Create the empty tile. Used to be returned when accessing out of the array.
        mEmptyTile = new CTile(0, 0, 0, mTiles [AIR_INDEX], 4);
        mEmptyTile.setVisible(false);
        mEmptyTile.setWalkable(true);

        registerSingleton();
    }
Пример #2
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));
        }
    }
Пример #3
0
    // Info con los items.
    //private CItemInfo mItemInfo;

    public CTileMap()
    {
        mTiles     = new Sprite [NUM_TILES];
        mTiles [0] = Resources.Load <Sprite> ("Sprites/tiles/tile000");
        mTiles [1] = Resources.Load <Sprite> ("Sprites/tiles/tile001");
        mTiles [2] = Resources.Load <Sprite> ("Sprites/tiles/tile002");
        mTiles [3] = Resources.Load <Sprite> ("Sprites/tiles/tile003");
        mTiles [4] = Resources.Load <Sprite> ("Sprites/tiles/tile004");
        mTiles [5] = Resources.Load <Sprite> ("Sprites/tiles/tile005");

        // TODO: CARGAR TODO JUNTO CON LOADALL.

        buildLevel(1);

        mEmptyTile = new CTile(0, 0, 0, mTiles [0]);
        mEmptyTile.setVisible(false);
        mEmptyTile.setWalkable(true);
    }
Пример #4
0
    //Se cargan los sprites de los tiles
    //TODO hacer manager de assets
    public CTileMap()
    {
        mMapObject      = new GameObject();
        mMapObject.name = "Mapa";
        mTiles          = new Sprite[NUM_TILES];
        mTiles[0]       = Resources.Load <Sprite>("Sprites/tiles/tile000");
        mTiles[1]       = Resources.Load <Sprite>("Sprites/tiles/tile001");
        //mTiles[2] = Resources.Load<Sprite>("Sprites/tiles/wall002");

        /*mTiles[3] = Resources.Load<Sprite>("Sprites/tiles/tile003");
        *  mTiles[4] = Resources.Load<Sprite>("Sprites/tiles/tile004");
        *  mTiles[5] = Resources.Load<Sprite>("Sprites/tiles/tile005");*/

        //TODO: Cargar todo junto con LOADALL
        buildLevel(1);

        mEmptyTile = new CTile(0, 0, 0, mTiles[0]);
        mEmptyTile.setVisible(false);
        mEmptyTile.setWalkable(true);
    }