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))); }
static void ImportWalls(TerrainMap trmap, LevelDoc lvld) { ArrayList alsmi = new ArrayList(); for (int ty = 0; ty < trmap.Map.GetLength(0); ty++) { for (int tx = 0; tx < trmap.Map.GetLength(1); tx++) { if (trmap.Map[ty, tx] == TerrainTypes.Wall) { IMapItem mi = new Wall(100, lvld.Bounds.Left + tx, lvld.Bounds.Top + ty); alsmi.Add(mi); } } } lvld.AddMapItems((IMapItem[])alsmi.ToArray(typeof(IMapItem))); }
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))); }