Beispiel #1
0
        public void Follow()
        {
            Description2D entityDescription = Following as Description2D;

            if (entityDescription == null)
            {
                return;
            }

            Rectangle fBounds = new Rectangle(Following.Position, new Size(0, 0));

            if (entityDescription != null)
            {
                fBounds.Width  = entityDescription.Sprite?.Width ?? 0;
                fBounds.Height = entityDescription.Sprite?.Height ?? 0;
            }

            if (fBounds.X < Bounds.X + ScrollLeft)
            {
                Bounds.X = fBounds.X - ScrollLeft;
            }
            else if (fBounds.X + fBounds.Width > Bounds.X + Bounds.Width - ScrollRight)
            {
                Bounds.X = fBounds.X + fBounds.Width + ScrollRight - Bounds.Width;
            }

            if (fBounds.Y < Bounds.Y + ScrollTop)
            {
                Bounds.Y = fBounds.Y - ScrollTop;
            }
            else if (fBounds.Y + fBounds.Height > Bounds.Y + Bounds.Height - ScrollBottom)
            {
                Bounds.Y = fBounds.Y + fBounds.Height + ScrollBottom - Bounds.Height;
            }
        }
Beispiel #2
0
 public void Draw(Graphics gfx, Description2D description)
 {
     if (description != null)
     {
         if (description.HasImage())
         {
             Rectangle dest = new Rectangle((int)(description.X + description.DrawOffsetX) - (description?.Sprite.X ?? 0), (int)(description.Y + description.DrawOffsetY) - (description?.Sprite.Y ?? 0), description.Width, description.Height);
             gfx.DrawImage(description.Image(), dest, new Rectangle(0, 0, description.Width, description.Height), GraphicsUnit.Pixel);
         }
     }
 }
Beispiel #3
0
 public void Draw(int buffer, IDescription description)
 {
     if (description is TileMap)
     {
         Draw(this.sbuffer[buffer].Context, description as TileMap);
     }
     else
     {
         Description2D d2d = description as Description2D;
         Graphics      gfx = d2d.DrawInOverlay ? this.soverlay[buffer].Context : this.sbuffer[buffer].Context;
         Draw(gfx, d2d);
     }
 }
Beispiel #4
0
 public double Direction(Description2D other)
 {
     return(Math.Atan2(other.Y - Y, other.X - X));
 }
Beispiel #5
0
 public double Distance(Description2D other)
 {
     return(Math.Sqrt((X - other.X) * (X - other.X) + (Y - other.Y) * (Y - other.Y)));
 }
Beispiel #6
0
 virtual public bool IsCollision(Description2D other)
 {
     return(this.Bounds.IntersectsWith(other.Bounds));
 }