Пример #1
0
        public void DrawArena(RLConsole console)
        {
            // Use RogueSharp to calculate the current field-of-view for the player
            var position = Floor.Player.TryGetPosition();

            Floor.FloorMap.ComputeFov(position.X, position.Y, 50, true);

            foreach (var cell in Floor.FloorMap.GetAllCells())
            {
                // When a Cell is in the field-of-view set it to a brighter color
                if (cell.IsInFov)
                {
                    Floor.FloorMap.SetCellProperties(cell.X, cell.Y, cell.IsTransparent, cell.IsWalkable, true);
                    if (cell.IsWalkable)
                    {
                        console.Set(cell.X, cell.Y, RLColor.Gray, null, '.');
                    }
                    else
                    {
                        console.Set(cell.X, cell.Y, RLColor.LightGray, null, '#');
                    }
                }
                // If the Cell is not in the field-of-view but has been explored set it darker
                else
                {
                    if (cell.IsWalkable)
                    {
                        console.Set(cell.X, cell.Y, new RLColor(30, 30, 30), null, '.');
                    }
                    else
                    {
                        console.Set(cell.X, cell.Y, RLColor.Gray, null, '#');
                    }
                }
            }

            // Draw enemies, alert + scan radii
            List <RogueSharp.Cell> alertCells = new List <RogueSharp.Cell>();
            List <RogueSharp.Cell> scanCells  = new List <RogueSharp.Cell>();

            foreach (var e in Floor.InspectMapEntities().Where(e => e != Floor.Player))
            {
                var entityPosition = e.TryGetPosition();
                if (e.TryGetDestroyed())
                {
                    console.Set(entityPosition.X, entityPosition.Y, RLColor.Gray, null, 'D');
                }
                else
                {
                    console.Set(entityPosition.X, entityPosition.Y, RLColor.Red, null, 'E');

                    var componentAI = e.GetComponentOfType <Component_AI>();
                    if (componentAI != null)
                    {
                        var infoCells = componentAI.AlertCells(this.Floor);
                        scanCells.AddRange(infoCells.ScanCells);
                        alertCells.AddRange(infoCells.AlertCells);
                    }
                }
            }
            foreach (var cell in scanCells)
            {
                console.SetBackColor(cell.X, cell.Y, RLColor.LightBlue);
            }
            foreach (var cell in alertCells)
            {
                console.SetBackColor(cell.X, cell.Y, RLColor.LightRed);
            }

            // Draw player
            console.Set(position.X, position.Y, RLColor.Green, null, '@');

            // Highlight examined
            if (this.examineMenu.Examining)
            {
                var examinedPostion = this.examineMenu.ExaminedEntity.TryGetPosition();
                console.SetBackColor(examinedPostion.X, examinedPostion.Y, RLColor.Yellow);
            }

            // Highlight targeting
            if (this.targetMenu.Targeting)
            {
                var playerPosition = Floor.Player.TryGetPosition();
                // TODO: Artemis is crying
                var cellsInRange = Floor.CellsInRadius(playerPosition.X, playerPosition.Y,
                                                       this.inventoryMenu.SelectedItem.GetComponentOfType <Component_Usable>().TargetRange);
                foreach (RogueSharp.Cell cell in cellsInRange)
                {
                    if (cell.IsInFov && cell.IsWalkable)
                    {
                        console.SetBackColor(cell.X, cell.Y, RLColor.LightGreen);
                    }
                }

                console.SetBackColor(this.targetMenu.X, this.targetMenu.Y, RLColor.Green);
            }

            // Draw commands
            foreach (var command in dungeon.ExecutedCommands)
            {
                if (command is GameEvent_PrepareAttack)
                {
                    var cmd         = (GameEvent_PrepareAttack)command;
                    var attackerPos = cmd.CommandEntity.TryGetPosition();
                    var targetPos   = cmd.Target.TryGetPosition();
                    var lineCells   = this.Floor.FloorMap.GetCellsAlongLine(attackerPos.X, attackerPos.Y, targetPos.X,
                                                                            targetPos.Y);
                    foreach (var cell in lineCells)
                    {
                        console.SetBackColor(cell.X, cell.Y, RLColor.LightRed);
                    }
                }
            }
            dungeon.ClearExecutedCommands();
        }