Click here to Skip to main content
15,896,063 members
Articles / Programming Languages / C#

Mars Mission (2) : Explore the Solar System

Rate me:
Please Sign up or sign in to vote.
4.97/5 (36 votes)
20 Nov 2010CPOL19 min read 50.7K   2.2K   45  
strategy/action game defending the solar system : interplanetary space
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Mars_Mission
{
	public class classExplosion
	{
		public static classShrapnel[] cShrapnel_Active = new classShrapnel[0];

		public static void makeExplosion(ref classCollisionDetectionObject cCDO_Origin, double dblExplosiveForce, int intSizeExplosion)
		{
			//intSizeExplosion = 1;
			int intStartInsert = cShrapnel_Active.Length;
			Array.Resize<classShrapnel>(ref cShrapnel_Active, cShrapnel_Active.Length + intSizeExplosion);
			for (int intCounter = 0; intCounter < intSizeExplosion; intCounter++)
			{
				cShrapnel_Active[intStartInsert + intCounter] = new classShrapnel(ref cCDO_Origin, dblExplosiveForce, intSizeExplosion);
			}
		}
		
		public static void clearShrapnel()
		{
			cShrapnel_Active = new classShrapnel[0];
		}

		public static void AnimateActiveShrapnel()
		{
			for (int intShrapnelCounter = 0; intShrapnelCounter < cShrapnel_Active.Length; intShrapnelCounter++)
			{
				while (intShrapnelCounter < cShrapnel_Active.Length && cShrapnel_Active[intShrapnelCounter].intLifeSpan <= 0)
				{
					cShrapnel_Active[intShrapnelCounter] = cShrapnel_Active[cShrapnel_Active.Length - 1];
					Array.Resize<classShrapnel>(ref cShrapnel_Active, cShrapnel_Active.Length - 1);
				}

				if (intShrapnelCounter < cShrapnel_Active.Length)
				{
					classCollisionDetectionObject cCDO = cShrapnel_Active[intShrapnelCounter].cCDO;
					cCDO.angle += cCDO.dblTurningRate;
					cCDO.dptEnd.X = cCDO.dptPos.X + cCDO.dptVel.X;
					cCDO.dptEnd.Y = cCDO.dptPos.Y + cCDO.dptVel.Y;
					switch (cShrapnel_Active[intShrapnelCounter].cCDO.eLoc)
					{
						case enuLocation.Base:
						case enuLocation.Cave:
						case enuLocation.Surface:
							cCDO.cLandscapeCell.cLandscape.gravityEffects(ref cCDO);
							classCollisionResult cResult =  cCDO.cLandscapeCell.cLandscape.moveLandscape(ref cCDO);
							cCDO.dptPos = cCDO.dptEnd.Copy();
							if (cResult.eCollision == enuCollisionResult.crash)
								cShrapnel_Active[intShrapnelCounter].intLifeSpan -= 1;
							break;
						default:
							cShrapnel_Active[intShrapnelCounter].intLifeSpan--;
							break;
					}
					
				}
			}
		}

		public class classShrapnel
		{
			static public classRotatedImage[] cRotImages;
			static classSortedImages[] cSortedImages;
			enum enuShrapnelTypes { Shuttle, Fighter, standard, _numShrapnelTypes };
			public int intLifeSpan = 10;

			public classCollisionDetectionObject cCDO;
			public classRotatedImage cBmp;
			enuShrapnelTypes eShrapnelType;

			public classShrapnel(ref classCollisionDetectionObject cCDO_Origin, double dblExplosiveForce, int intSize)
			{
				cCDO = cCDO_Origin.Copy();
				cCDO.radius /= intSize;
				cCDO.dblTurningRate = classMath.rnd.NextDouble() * (Math.PI / 32);

				cCDO.dptVel.X += (classMath.rnd.NextDouble() * 2 * dblExplosiveForce) - dblExplosiveForce;
				cCDO.dptVel.Y += (classMath.rnd.NextDouble() * 2 * dblExplosiveForce) - dblExplosiveForce;
				intLifeSpan = 5;

				switch (cCDO.eTypeObject)
				{
					case classCollisionDetectionObject.enuTypeObject.Ship:
						switch (cCDO.cIAmShip.eModel)
						{
							case enuShipModels.shuttle:
								eShrapnelType = enuShrapnelTypes.Shuttle;
								break;

							case enuShipModels.fighter:
								eShrapnelType = enuShrapnelTypes.Fighter;
								break;

							default:
								eShrapnelType = enuShrapnelTypes.standard;
								break;
						}
						break;

					default:
						eShrapnelType = enuShrapnelTypes.standard;
						break;
				}
				cCDO.eTypeObject = classCollisionDetectionObject.enuTypeObject.Shrapnel;
				
				setImage();
			}

			void setImage()
			{
				if (cSortedImages == null)
				{
					cSortedImages = new classSortedImages[(int)enuShrapnelTypes._numShrapnelTypes];
					for (enuShrapnelTypes eTypeCounter = (enuShrapnelTypes)0; eTypeCounter < enuShrapnelTypes._numShrapnelTypes; eTypeCounter++)
					{
						string strType = eTypeCounter.ToString().ToUpper();
						cSortedImages[(int)eTypeCounter] = new classSortedImages();
						cSortedImages[(int)eTypeCounter].cRotatedImages = new classRotatedImage[0];
						for (int intRotImageCounter = 0; intRotImageCounter < cRotImages.Length; intRotImageCounter++)
						{
							string strFilename = cRotImages[intRotImageCounter].strMyFilename.ToUpper().Substring("shrapnel_".Length);
							if (strFilename.Length > strType.Length)
							{
								if (strFilename.Substring(0, strType.Length) == strType)
								{
									Array.Resize<classRotatedImage>(ref cSortedImages[(int)eTypeCounter].cRotatedImages, cSortedImages[(int)eTypeCounter].cRotatedImages.Length + 1);
									cSortedImages[(int)eTypeCounter].cRotatedImages[cSortedImages[(int)eTypeCounter].cRotatedImages.Length - 1] = cRotImages[intRotImageCounter];
								}
							}
						}
					}
				}
				cBmp = cSortedImages[(int)eShrapnelType].cRotatedImages[classMath.getRndInt(cSortedImages[(int)eShrapnelType].cRotatedImages.Length)];
			}
		
		}

		class classSortedImages
		{
			public classRotatedImage[] cRotatedImages;
		}

	}
}

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
CEO unemployable
Canada Canada
Christ Kennedy grew up in the suburbs of Montreal and is a bilingual Quebecois with a bachelor’s degree in computer engineering from McGill University. He is unemployable and currently living in Moncton, N.B. writing his next novel.

Comments and Discussions