コード例 #1
0
ファイル: MapRendererLibTCod.cs プロジェクト: vrum/roguelike
        /// <summary>
        /// Render the map, with TL in map at mapOffset. Screenviewport is the screen viewport in tile dimensions (for now)
        /// </summary>
        /// <param name="mapToRender"></param>
        /// <param name="mapOffset"></param>
        /// <param name="screenViewport"></param>
        public static void RenderMap(TileEngine.TileMap mapToRender, Point mapOffset, Rectangle screenViewport)
        {
            //For libtcod
            //tileID = ascii char
            //flags = color

            //Get screen handle
            RootConsole rootConsole = RootConsole.GetInstance();

            if (mapOffset.x >= mapToRender.Columns || mapOffset.y >= mapToRender.Rows)
            {
                throw new Exception("Point outside map " + mapOffset);
            }

            //Calculate visible area of map
            int maxColumn = mapOffset.x + screenViewport.Width - 1;
            int maxRow    = mapOffset.y + screenViewport.Height - 1;

            if (maxColumn >= mapToRender.Columns)
            {
                maxColumn = mapToRender.Columns - 1;
            }
            if (maxRow >= mapToRender.Rows)
            {
                maxRow = mapToRender.Rows - 1;
            }

            //Render layers in order
            foreach (TileEngine.TileLayer layer in mapToRender.Layer)
            {
                for (int y = mapOffset.y; y <= maxRow; y++)
                {
                    for (int x = mapOffset.x; x <= maxColumn; x++)
                    {
                        TileEngine.TileCell thisCell = layer.Rows[y].Columns[x];

                        if (thisCell.TileID == -1)
                        {
                            continue;
                        }

                        //Flags is a color for libtcod
                        LibtcodColorFlags colorFlags = thisCell.TileFlag as LibtcodColorFlags;
                        if (colorFlags == null)
                        {
                            rootConsole.ForegroundColor = ColorPresets.White;
                            rootConsole.BackgroundColor = ColorPresets.Black;
                        }
                        else
                        {
                            if (colorFlags.BackgroundColor == null)
                            {
                                rootConsole.BackgroundColor = ColorPresets.Black;
                            }
                            else
                            {
                                rootConsole.BackgroundColor = colorFlags.BackgroundColor;
                            }

                            rootConsole.ForegroundColor = colorFlags.ForegroundColor;
                        }

                        //Id is the char
                        char screenChar = Convert.ToChar(thisCell.TileID);

                        //Screen coords
                        int screenX = screenViewport.X + (x - mapOffset.x);
                        int screenY = screenViewport.Y + (y - mapOffset.y);

                        rootConsole.PutChar(screenX, screenY, screenChar);
                    }
                }
            }

            //Reset colors - this matters for systems that don't use the tile renderer
            rootConsole.ForegroundColor = ColorPresets.White;
            rootConsole.BackgroundColor = ColorPresets.Black;
        }
コード例 #2
0
ファイル: Screen.cs プロジェクト: Sinellil/roguelike-cs
        /// <summary>
        /// Fully rebuild the layered, tiled map. All levels, excluding animations
        /// </summary>
        private void BuildTiledMap()
        {
            Dungeon dungeon = Game.Dungeon;
            Player player = dungeon.Player;

            tileMap = new TileEngine.TileMap(7, ViewableHeight, ViewableWidth);

            int levelToDisplay = LevelToDisplay;

            //Draw the map screen

            //Draw terrain (must be done first since sets some params)
            //First level in tileMap
            DrawMap(levelToDisplay, dungeon.Levels);

            //Draw locks
            DrawLocks(levelToDisplay, dungeon.Locks);

            //Draw fixed features
            DrawFeatures(levelToDisplay, dungeon.Features);

            //Draw items (will appear on top of staircases etc.)
            DrawItems(levelToDisplay, dungeon.Items);

            //Draw creatures
            DrawCreatures(levelToDisplay, dungeon.Monsters);

            //Draw PC
            DrawPC(levelToDisplay, player);

            //Draw targetting cursor
            if (targettingMode)
                DrawTargettingCursor();
        }