Click here to Skip to main content
15,895,777 members
Articles / Mobile Apps

Pocket 1945 - A C# .NET CF Shooter

Rate me:
Please Sign up or sign in to vote.
4.90/5 (101 votes)
2 Jun 2004CPOL10 min read 269.2K   2.7K   152  
An article on Pocket PC game development.
using System;
using System.Drawing;
using System.Drawing.Imaging;

namespace Pocket1945
{
	/// <summary>
	/// This class is a base sprite class. All game objects like 
	/// enemy planes, background elements etc. inherit this class.
	/// The class implements IDrawable since all sprites must be able to 
	/// be drawn on the screen.	
	/// </summary>
	public abstract class Sprite : IDrawable
	{							
		protected int x;
		protected int y;
		protected Size spriteSize;		
		protected Point collitionPoint;
		protected Rectangle collitionRectangle;
		protected ImageAttributes imgAttribs;

		/// <summary>
		/// Abstract method all child classes must override. This 
		/// method returns the index of the sprite from the SpritList 
		/// bitmap array.
		/// </summary>
		/// <returns>The index to use to access the SpriteList bitmap array.</returns>
		public abstract int GetSpriteIndex();
				
		/// <summary>
		/// Method returning true if the sprite is currently off the screen.
		/// The method is virtual so that child classess can make it's own implementation
		/// of the method.
		/// </summary>
		/// <returns>True if the sprite is off the screen.</returns>
		public virtual bool IsOffScreen()
		{
			return(x > GameForm.GameArea.Width || x + spriteSize.Width < 0 || y > GameForm.GameArea.Height || y + spriteSize.Height < 0);
		}

		/// <summary>
		/// Method returning the collition bounds of the sprite.
		/// </summary>
		/// <returns>A rectangle representing the collition area of the sprite.</returns>
		public virtual Rectangle GetCollitionRectangle()
		{			
			collitionRectangle.X = x + collitionPoint.X;
			collitionRectangle.Y = y + collitionPoint.Y;
			return collitionRectangle;
		}

		/// <summary>
		/// Implementation of IDrawable. This method draws the sprite.
		/// </summary>
		/// <param name="g">The graphics object the sprite is using to draw itself.</param>
		public abstract void Draw(Graphics g);

		/// <summary>
		/// Instanciates a new Sprite class.
		/// </summary>
		public Sprite()
		{
			x = 0;
			y = 0;	
			spriteSize = new Size(0, 0);
			collitionPoint = new Point(0, 0);
			collitionRectangle = new Rectangle(x, y, spriteSize.Width, spriteSize.Height);
			
			imgAttribs = new ImageAttributes();			
			imgAttribs.SetColorKey(Color.FromArgb(0, 66, 173), Color.FromArgb(0, 66, 173));
		}
	}
}

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
Norway Norway
I'm a C# developer from Norway. I'm a co-founder of a small ISV called GreIT AS. Our company site can be found at http://www.greit.no (all information in norwegian).

My everyday work consists of building ASP.NET web applications and work on our content management system, Webpakken. I use my spare time on side projects such as Pocket 1945 (http://workspaces.gotdotnet.com/pocket1945), a shooter game for the Pocket PC platform. It’s almost the opposite of my everyday work since games are small, focus on graphics and entertainment, while our CMS is large, focus on businesses and data.

When I’m not sitting in front of the computer I go snowboarding or skateboarding, depending on which time of the year it is.

I also enjoy fly fishing for salmon and trout in the summer. My personal record is a 10.5 KG salmon caught in Lakselva last summer and a 2 KG trout caught some where secret place in Finnmark. A bragging picture of me holding the salmon can be found at http://jonas.greit.no/pictures/salmon.jpg .

I did start blogging some time back, but I haven’t been to good at updating my blogg. I just got so much stuff going on that it’s hard to find time to add blogg posts. You can view my blogg at http://jonas.greit.no, just don’t expect too much.

Comments and Discussions