gameobject.cs

来自「c#编程的一百个初级合 经典例子」· CS 代码 · 共 71 行

CS
71
字号
using System;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace BrickOut
{
	/// <summary>
	/// 
	/// </summary>
	public class GameObject
	{
        protected Image TheImage = null;
        public Point Position = new Point(50, 50);
        protected Rectangle ImageBounds = new Rectangle(0,0, 10, 10);
        protected Rectangle MovingBounds = new Rectangle();

      public GameObject(string fileName)
       {
        TheImage = Image.FromFile(fileName);
        ImageBounds.Width = TheImage.Width;
        ImageBounds.Height = TheImage.Height;
       }
        
        public  int Width
        {
            get 
            {
                 return ImageBounds.Width;
            }
        }

        public  int Height
            {
               get 
                {
                 return ImageBounds.Height;
                }
            }


       public virtual int GetWidth()
        {
             return ImageBounds.Width;
        }
        
       public Image GetImage()
        {
            return TheImage;
        }

        public virtual Rectangle GetBounds()
        {
            return MovingBounds;
        }

        public void UpdateBounds()
        {
            MovingBounds = ImageBounds;
            MovingBounds.Offset(Position);
        }
    
        public virtual void Draw(Graphics g)
        {
            UpdateBounds();
            g.DrawImage(TheImage, MovingBounds, 0, 0, ImageBounds.Width, ImageBounds.Height, GraphicsUnit.Pixel);
        }


	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?