Esempio n. 1
0
        protected override void Redraw()
        {
            base.Redraw();
            Canvas.Clear();
            var level = _player.Get <GameObject>().Level;

            ViewOffset = new Point(Math.Min(Math.Max(_player.Get <GameObject>().X - Canvas.Size.Width / 2, 0),
                                            level.Width - Canvas.Size.Width),
                                   Math.Min(Math.Max(_player.Get <GameObject>().Y - Canvas.Size.Height / 2, 0),
                                            level.Height - Canvas.Size.Height));

            //draw map
            var sight = _player.Get <SightComponent>();

            sight.CalculateSight();
            for (int x = 0; x < Canvas.Size.Width; x++)
            {
                for (int y = 0; y < Canvas.Size.Height; y++)
                {
                    Point screenPosition = new Point(x, y);
                    Point location       = ViewOffset + screenPosition;

                    if (!level.IsInBounds(location))
                    {
                        continue;
                    }

                    var texture = _assets[level.GetTerrain(location).Asset];
                    if (texture == null)
                    {
                        Logger.WarnFormat("Texture not found for asset: {0}!", level.GetTerrain(location).Asset);
                        continue;
                    }

                    if (IsPointWithinPanel(screenPosition))
                    {
                        if (!Program.SeeAll.Enabled)
                        {
                            if (sight.IsVisible(location))
                            {
                                PrintChar(screenPosition, texture);
                            }
                        }
                        else
                        {
                            PrintChar(screenPosition, texture);
                        }
                    }
                }
            }

            // draw entities
            foreach (var entity in _entities.OrderBy(e => e.Get <Sprite>().ZOrder))
            {
                Point screenPosition = entity.Get <GameObject>().Location - ViewOffset;

                var texture = _assets[entity.Get <Sprite>().Asset];
                if (texture == null)
                {
                    Logger.WarnFormat("Texture not found for asset: {0}!", entity.Get <Sprite>().Asset);
                    continue;
                }

                if (IsPointWithinPanel(screenPosition))
                {
                    if (!Program.SeeAll.Enabled)
                    {
                        if (sight.IsVisible(entity.Get <GameObject>().Location))
                        {
                            if (entity.Get <VisibleComponent>().VisibilityIndex > 0)
                            {
                                PrintChar(screenPosition, texture);
                            }
                        }
                    }
                    else
                    {
                        PrintChar(screenPosition, texture);
                    }
                }
            }
        }