Пример #1
0
 public RoomPlan(Rectangle rect, RoomGenerator generator, int index)
 {
     Index = index;
     Rect = rect;
     Generator = generator;
     Doors = new Dictionary<RoomPlan, Rectangle>();
 }
Пример #2
0
        /// <summary>
        /// Creates a new RoomVisibility instance to track the visibility
        /// of tiles within a specified room.
        /// </summary>
        /// <param name="room">Room to track the visibility of.</param>
        public RoomVisibility(Rectangle rect)
        {
            Rect = rect;
            LastVisibleTime = 0;

            _mask = new ulong[Rect.Width, Rect.Height];
            _tiles = new TileAppearance[Rect.Width, Rect.Height];
        }
Пример #3
0
        /// <summary>
        /// Creates an widget.
        /// </summary>
        /// <param name="name">Name of the widget.</param>
        /// <param name="pos">Position of the widget.</param>
        /// <param name="width">Size of the widget.</param>
        /// <param name="height">Size of the widget.</param>
        /// <param name="isSelectable">If true widget can be selected.</param>
        /// <param name="fc">Foreground color (default gray).</param>
        /// <param name="bc">Background color (default black).</param>
        public Widget(string name, Position pos, int width, int height, bool isSelectable,
            ConsoleColor fc = ConsoleColor.Gray, ConsoleColor bc = ConsoleColor.Black)
        {
            this.Name = name;

            this.rectangle = new Rectangle(pos, new Position(pos.X + width, pos.Y + height));

            this.ForegroundColor = fc;
            this.BackgroundColor = bc;

            _isSelectable = isSelectable;
        }
Пример #4
0
        /// <summary>
        /// Finds the smallest rectangle that encloses both this
        /// instance and another given rectangle.
        /// </summary>
        /// <param name="rect">Rectangle to find the union of.</param>
        /// <returns>A rectangle that encloses both this instance and
        /// the given rectangle.</returns>
        public Rectangle Union(Rectangle rect)
        {
            if (Area == 0) return rect;
            if (rect.Area == 0) return this;

            var tl = new Position(
                Math.Min(this.Left, rect.Left),
                Math.Min(this.Top, rect.Top));

            var br = new Position(
                Math.Max(this.Right, rect.Right),
                Math.Max(this.Bottom, rect.Bottom));

            return new Rectangle(tl, br);
        }
Пример #5
0
 public bool IsAdjacent(Rectangle rect)
 {
     return (this.Left == rect.Right || rect.Left == this.Right)
         != (this.Top == rect.Bottom || rect.Top == this.Bottom);
 }
Пример #6
0
 /// <summary>
 /// Tests to see if the given rectangle intersects with this one.
 /// </summary>
 /// <param name="rect">Rectangle to perform an intersection
 /// test with.</param>
 /// <returns>True if the rectangle has a non-zero intersection
 /// area with this one, and false otherwise.</returns>
 public bool Intersects(Rectangle rect)
 {
     return this.Right > rect.Left && this.Bottom > rect.Top
         && rect.Right > this.Left && rect.Bottom > this.Top;
 }
Пример #7
0
        /// <summary>
        /// Finds the rectangle describing the intersection between
        /// this and another rectangle if one exists, and otherwise
        /// an empty rectangle.
        /// </summary>
        /// <param name="rect">Rectangle to find the intersection with.</param>
        /// <returns>The intersecting rectangle if one exists, and
        /// otherwise the zero rectangle.</returns>
        public Rectangle Intersection(Rectangle rect)
        {
            if (!Intersects(rect) && !IsAdjacent(rect)) return Rectangle.Zero;

            var tl = new Position(
                Math.Max(this.Left, rect.Left),
                Math.Max(this.Top, rect.Top));

            var br = new Position(
                Math.Min(this.Right, rect.Right),
                Math.Min(this.Bottom, rect.Bottom));

            return new Rectangle(tl, br);
        }
Пример #8
0
 public void AddDoor(RoomPlan room, Rectangle rect)
 {
     Doors.Add(room, rect.Intersection(Rect) - Rect.TopLeft);
 }
Пример #9
0
 public abstract IEnumerable<Room> Generate(Level level, Rectangle rect, Rectangle[] doors, Random rand);
Пример #10
0
        /// <summary>
        /// A map of the 16 possible neighbouring tile solidity
        /// states to the characters that should be used when
        /// drawing walls.
        /// 
        /// TODO: Move to a definition file, allowing for different
        ///       types of walls?
        /// </summary>
        /// <summary>
        /// Renders the tiles deemed visible within the room corresponding
        /// to this visibility mask to the specified location on the screen.
        /// </summary>
        /// <param name="vis">Visibility mask to draw from.</param>
        /// <param name="rect">Clipping rectangle in level-space.</param>
        /// <param name="screenPos">Position on the screen that the top-left
        /// of the rectangle should be drawn to.</param>
        /// <param name="attribs">Attributes to be used when drawing tiles
        /// and entities.</param>
        public static void Draw(this RoomVisibility vis, Rectangle rect, Position screenPos, DrawAttributes attribs, ulong time)
        {
            var subRect = vis.Rect.Intersection(rect);
            var roomPos = vis.Rect.TopLeft;

            if (subRect.Width * subRect.Height <= 0) return;

            // Move the screen position and clipping rectangle to room-space.
            screenPos += roomPos - rect.TopLeft;
            rect = subRect - roomPos;

            foreach (var tile in vis.GetVisible(time)) {
                if (rect.Intersects(tile.Position)) {
                    tile.Draw(screenPos + tile.Position, attribs, true);
                }
            }

            foreach (var tile in vis.GetRemembered(time)) {
                if (rect.Intersects(tile.Position)) {
                    tile.Draw(screenPos + tile.Position, new DrawAttributes(0), false);
                }
            }
        }