Click here to Skip to main content
15,893,814 members
Articles / Artificial Intelligence

Rotating Sprite Objects on DirectDraw Wrapper for C#

Rate me:
Please Sign up or sign in to vote.
3.00/5 (4 votes)
9 Dec 2004CPOL4 min read 83.8K   637   25  
Evaluate C# on delivering more than 1000 animated sprites on fullscreen 1280x1024.
		public System.Exception AI()
		{
			try
			{
				if (pHead!=null)
				{
					CUnit u=pHead;
					while (u!=null) 
					{
						u.AI(this.m_Engine.m_FrameRate.m_FPS);
						u=u.pNext;
					}
				}
				return null;
			}
			catch(Exception e)
			{
				this.m_Trace.T("CUnitManager::Update>"+e);
				return e;
			}
		}
		public System.Exception DrawLastPosition(Microsoft.DirectX.DirectDraw.Surface s, DDW.ENGINE.CWorld w)
		{
			try
			{
				if (pHead!=null)
				{
					CUnit u=pHead;
					while (u!=null) 
					{
						u.DrawLastPosition(s,w);
						u=u.pNext;
					}
				}
				return null;
			}
			catch(Exception e)
			{
				this.m_Trace.T("CUnitManager::Draw>"+e);
				return e;
			}
		}
		public System.Exception UpdateXYFromLastXY()
		{
			try
			{
				if (pHead!=null)
				{
					CUnit u=pHead;
					while (u!=null) 
					{
						u.UpdateXYFromLastXY();
						u=u.pNext;
					}
				}
				return null;
			}
			catch(Exception e)
			{
				this.m_Trace.T("CUnitManager::UpdateXYFromLastXY>"+e);
				return e;
			}
		}
		public CUnitManager WhoDoesUnitSee(CUnit u0)
		{
			try
			{
				CUnitManager uList=new CUnitManager("WhoDoesUnitSee_List",this.m_Engine);
				double d=0;
				if (pHead!=null)
				{
					CUnit u=pHead;
					while (u!=null) 
					{
						if (u!=u0)
						{
							DDW.ENGINE.CUtils.VECTOR v1 = new DDW.ENGINE.CUtils.VECTOR(u0.m_X,u0.m_Y,u0.m_Angle);
							DDW.ENGINE.CUtils.VECTOR v2 = new DDW.ENGINE.CUtils.VECTOR(u.m_X,u.m_Y,u.m_Angle);
							d=m_Utils.AngleBetweenTwoVectors(v1,v2);
							if (d>-u0.m_ViewingAngle && d<u0.m_ViewingAngle)
							{
								d=m_Utils.DistanceBetweenVectors(v1,v2);
								if (d<u0.m_ViewingDistance)
									uList.Add(u);
							}
						}
						u=u.pNext;
					}
				}
				if (uList.Count()==0)
					uList=null;
				return uList;
			}
			catch(Exception e)
			{
				this.m_Trace.T("CUnitManager::WhoDoesUnitSee>"+e);
				return null;
			}
		}
		public System.Exception MoveTo(double x, double y)
		{
			try
			{
				if (pHead!=null)
				{
					CUnit u=pHead;
					while (u!=null) 
					{
						u.MoveTo(x,y);
						u=u.pNext;
					}
				}
				return null;
			}
			catch(Exception e)
			{
				this.m_Trace.T("CUnitManager::MoveTo>"+e);
				return e;
			}
		}

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
Software Developer (Senior)
Portugal Portugal
Financial Apps addict since early programming ages;
Statistical Apps writer;
Computer gamming and graphics programmer with a 2 commercial titles: Armor PC/PPC, MidWay XBOX/PC/PPC;
Manic Basketball fan and player;
Traveller;

Comments and Discussions