public void ImportMap(LevelDoc lvld)
 {
     TemplatePos[] atpos = GetTemplatePositions();
     ArrayList alsTiles = new ArrayList();
     foreach (TemplatePos tpos in atpos) {
         int txOrigin = 64 - tpos.m_mixt.XTileCount - tpos.m_txOrigin;
         int tyOrigin = tpos.m_tyOrigin;
         bool[,] afDraw = new bool[tpos.m_mixt.YTileCount, tpos.m_mixt.XTileCount];
         for (int ty = 0; ty < tpos.m_mixt.YTileCount; ty++) {
             for (int tx = 0; tx < tpos.m_mixt.XTileCount; tx++) {
                 afDraw[ty, tx] = tpos.m_afMapped[ty, tpos.m_mixt.XTileCount - tx - 1];
             }
         }
         Tile tile = new Tile(tpos.m_mixt.Index.ToString(), txOrigin, tyOrigin, afDraw, null);
         alsTiles.Add(tile);
     }
     lvld.AddMapItems((IMapItem[])alsTiles.ToArray(typeof(IMapItem)));
 }
Beispiel #2
0
 public override Object Clone()
 {
     Tile tile = new Tile(m_strName, (int)m_tx, (int)m_ty, m_afVisible, m_afOccupancy);
     return (Object)tile;
 }
        static void ImportTileMap(TileMap tmap, TileSet tset, TemplateDoc tmpd, LevelDoc lvld)
        {
            // The TileMap is a list of indexes into a tile set. A Tileset is a list of tiles compiled
            // from Templates. Reverse the tilemap into Templates, and set into lvld.

            bool[,] afCellTaken = new bool[64, 64];
            ArrayList alsTemplPos = new ArrayList();
            Template[] atmpl = tmpd.GetTemplates();
            for (int ty = 0; ty < tmap.Height; ty++) {
                for (int tx = 0; tx < tmap.Width; tx++) {
                    // Cell mapped already?
                    if (afCellTaken[ty, tx]) {
                        continue;
                    }

                    // Cell not mapped. Create TemplatePos.
                    int iTile = tmap.GetTileIndex(tx, ty);
                    TileData tdata = tset.GetTileData(iTile);
                    Template tmpl = atmpl[tdata.iTemplate];

                    // Don't bother with background tiles
                    if (tmpl == tmpd.GetBackgroundTemplate()) {
                        continue;
                    }

                    int txOrigin = tx - tdata.txTemplate;
                    int tyOrigin = ty - tdata.tyTemplate;
                    bool[,] afMapped = new bool[tmpl.Cty, tmpl.Ctx];

                    for (int tyTmpl = 0; tyTmpl < tmpl.Cty; tyTmpl++) {
                        for (int txTmpl = 0; txTmpl < tmpl.Ctx; txTmpl++) {
                            int txT = txOrigin + txTmpl;
                            int tyT = tyOrigin + tyTmpl;
                            if (txT < 0 || txT >= 64 || tyT < 0 || tyT >= 64) {
                                continue;
                            }
                            if (afCellTaken[tyT, txT]) {
                                continue;
                            }
                            int iTileT = tmap.GetTileIndex(txT, tyT);
                            if (iTileT != -1) {
                                TileData tdataT = tset.GetTileData(iTileT);
                                if (tdataT.iTemplate != tdata.iTemplate) {
                                    continue;
                                }
                                if (tdataT.txTemplate != txTmpl || tdataT.tyTemplate != tyTmpl) {
                                    continue;
                                }
                            }
                            afMapped[tyTmpl, txTmpl] = true;
                            afCellTaken[tyT, txT] = true;
                        }
                    }
                    alsTemplPos.Add(new TemplatePos(tmpl, txOrigin, tyOrigin, afMapped));
                }
            }

            // Figure out the bounds.

            Rectangle rcBounds = new Rectangle((64 - tmap.Width) / 2, (64 - tmap.Height) / 2,
                    tmap.Width, tmap.Height);
            lvld.Bounds = rcBounds;

            // The list of TemplatePos's has been created. Add to LevelDoc.

            ArrayList alsTiles = new ArrayList();
            foreach (TemplatePos tpos in alsTemplPos) {
                Tile tile = new Tile(tpos.tmpl.Name,
                        tpos.txOrigin + rcBounds.Left,
                        tpos.tyOrigin + rcBounds.Top,
                        tpos.afMapped, tpos.tmpl.OccupancyMap);
                alsTiles.Add(tile);
            }
            lvld.AddMapItems((IMapItem[])alsTiles.ToArray(typeof(IMapItem)));
        }
        public bool Load(String strFile)
        {
            try {
                // At least make sure the file is valid before anything
                TilesDataSet dsTiles = new TilesDataSet();
                dsTiles.ReadXml(strFile);

                // Remove current tiles
                while (Count != 0)
                    RemoveTile(this[0]);

                // Use this TileDataSet and load tiles
                m_dsTiles = dsTiles;
                foreach (TilesDataSet.TilesRow row in m_dsTiles.Tiles) {
                    Tile tile = new Tile(row);
                    m_alsTiles.Add(tile);
                    OnTileAdded(tile);
                }
                return true;
            } catch {
                return false;
            }
        }
 // Event firing
 private void OnTileRemoved(Tile tile)
 {
     if (TileRemoved != null)
         TileRemoved(tile);
 }
 private void OnTileAdded(Tile tile)
 {
     if (TileAdded != null)
         TileAdded(tile);
 }
 public void RemoveTile(Tile tile)
 {
     if (!m_alsTiles.Contains(tile))
         return;
     m_dsTiles.Tiles.RemoveTilesRow(tile.Row);
     m_alsTiles.Remove(tile);
     OnTileRemoved(tile);
 }
 public Tile NewTile(String strFileBitmap)
 {
     TilesDataSet.TilesRow row = m_dsTiles.Tiles.NewTilesRow();
     Tile tile = new Tile(row);
     if (tile.Import(strFileBitmap)) {
         m_dsTiles.Tiles.AddTilesRow(row);
         m_alsTiles.Add(tile);
         OnTileAdded(tile);
         return tile;
     }
     return null;
 }