Click here to Skip to main content
15,892,809 members
Articles / Mobile Apps

Bunnyaruga: GAPI, Hekkus, Basics of Deployment

Rate me:
Please Sign up or sign in to vote.
3.63/5 (15 votes)
25 Apr 2004CPOL14 min read 54.1K   247   20  
This article shows an example of a game that uses the GAPI and Hekkus libraries. It also shows a nice and free way of deploying your games/applications without requiring the .NET Framework installed on the end user machines.
namespace Bunnyhug.Bunnyaruga.Sprite
{
	/// <summary>
	/// A rectangle sprite
	/// </summary>
	public class Rectangle
	{
		#region Variables
		private bool removed;
		private System.Drawing.Rectangle location;
		private System.Drawing.Color color;
		private float velocityX;
		private float velocityY;
		private float currentX;
		private float currentY;
		#endregion

		#region Properties
		/// <summary>
		/// Property Location (System.Drawing.Rectangle)
		/// Destination of the rectangle
		/// </summary>
		public System.Drawing.Rectangle Location
		{
			get
			{
				return this.location;
			}
			set
			{
				this.location = value;
			}
		}
		/// <summary>
		/// Property LocationX (int)
		/// </summary>
		public int LocationX
		{
			get
			{
				return this.location.X;
			}
			set
			{
				this.location.X = value;
			}
		}
		/// <summary>
		/// Property LocationY (int)
		/// </summary>
		public int LocationY
		{
			get
			{
				return this.location.Y;
			}
			set
			{
				this.location.Y = value;
			}
		}
		/// <summary>
		/// Property Width (int)
		/// </summary>
		public int Width
		{
			get
			{
				return this.location.Width;
			}
			set
			{
				this.location.Width = value;
			}
		}
		/// <summary>
		/// Property Height (int)
		/// </summary>
		public int Height
		{
			get
			{
				return this.location.Height;
			}
			set
			{
				this.location.Height = value;
			}
		}

		/// <summary>
		/// Property Removed (bool)
		/// Indicates whether this sprite has been removed from the board or not
		/// </summary>
		public bool Removed
		{
			get
			{
				return this.removed;
			}
			set
			{
				this.removed = value;
			}
		}
		/// <summary>
		/// Property VelocityY (float)
		/// The y-axis velocity (pixels/second)
		/// </summary>
		public float VelocityY
		{
			get
			{
				return this.velocityY;
			}
			set
			{
				this.velocityY = value;
			}
		}
		/// <summary>
		/// Property VelocityX (float)
		/// the x-axis velocity (pixels/second)
		/// </summary>
		public float VelocityX
		{
			get
			{
				return this.velocityX;
			}
			set
			{
				this.velocityX = value;
			}
		}
		/// <summary>
		/// Property Color (System.Drawing.Color)
		/// The color of the rectangle
		/// </summary>
		public System.Drawing.Color Color
		{
			get
			{
				return this.color;
			}
			set
			{
				this.color = value;
			}
		}
		/// <summary>
		/// Property CurrentY (float)
		/// </summary>
		public float CurrentY
		{
			get
			{
				return this.currentY;
			}
			set
			{
				this.currentY = value;
			}
		}
		/// <summary>
		/// Property CurrentX (float)
		/// </summary>
		public float CurrentX
		{
			get
			{
				return this.currentX;
			}
			set
			{
				this.currentX = value;
			}
		}
		#endregion

		#region Constructor
		/// <summary>
		/// Constructor
		/// </summary>
		public Rectangle()
		{
			this.Location = new System.Drawing.Rectangle(0,0,0,0);
			this.Removed = false;
			this.Color = System.Drawing.Color.Black;
			this.VelocityX = 0;
			this.VelocityY = 0;
			this.CurrentX = 0;
			this.CurrentY = 0;
		}
		#endregion

		#region Clicked
		/// <summary>
		/// Returns true if the point p is contained within the sprite
		/// </summary>
		/// <param name="p"></param>
		/// <returns></returns>
		public bool Clicked(System.Drawing.Point p)
		{
			bool result = false;
			if (this.CurrentX <= p.X &&
				(this.CurrentX + this.Width) >= p.X &&
				this.CurrentY <= p.Y &&
				(this.CurrentY + this.Height) >= p.Y)
			{
				result = true;			
			}
			return result;
		}
		#endregion

		#region Collision
		/// <summary>
		/// Returns true if the two sprites have collided
		/// </summary>
		/// <param name="p"></param>
		/// <returns></returns>
		public static bool Collision(Bunnyhug.Bunnyaruga.Sprite.Rectangle s1, Bunnyhug.Bunnyaruga.Sprite.Rectangle s2)
		{
			float left1, left2;
			float right1, right2;
			float top1, top2;
			float bottom1, bottom2;

			left1 = s1.CurrentX;
			left2 = s2.CurrentX;
			right1 = left1 + s1.Width;
			right2 = left2 + s2.Width;
			top1 = s1.CurrentY;
			top2 = s2.CurrentY;
			bottom1 = top1 + s1.Height;
			bottom2 = top2 + s2.Height;

			if (bottom1 < top2) return false;
			if (top1 > bottom2) return false;

			if (right1 < left2) return false;
			if (left1 > right2) return false;

			return true;
		}
		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions