public void DrawObjects() { foreach (KeyValuePair <Int32, List <PhysicalObject> > CurrList in cObjGroups) { foreach (PhysicalObject CurrObj in CurrList.Value) { CurrObj.Draw(); } } return; }
public void UpdateGraphicsDevice(GraphicsDevice GraphDev) { cGraphDev = GraphDev; foreach (KeyValuePair <Int32, List <PhysicalObject> > CurrList in cObjGroups) { foreach (PhysicalObject CurrObj in CurrList.Value) { CurrObj.UpdateGaphicsDevice(cGraphDev); } } return; }
public void UpdateObjects(GameTime CurrTime) { List <Int32> aIdxToRemove = new List <int>(); List <PhysicalObject> CurrList; List <Int32> aIdxList; PhysicalObject CurrObj; Int32 nCtr; //Get the keys in a separatex collection so updates to key list won't cause problems aIdxList = new List <int>(cObjGroups.Keys); //Loop through all of hte lists calling for updates foreach (Int32 CurrKey in aIdxList) { CurrList = cObjGroups[CurrKey]; aIdxToRemove.Clear(); //Loop through all objects in this list for (nCtr = 0; nCtr < CurrList.Count; nCtr++) { CurrObj = CurrList[nCtr]; if (CurrObj.Update(CurrTime) == false) { aIdxToRemove.Add(nCtr); //Save this index to be purged later } } //Any Updates that return false must be removed,go backwards to avoid removed keys //messing up the indexing for (nCtr = aIdxToRemove.Count - 1; nCtr >= 0; nCtr--) { CurrList.RemoveAt(aIdxToRemove[nCtr]); } } return; }
public override bool Update(GameTime CurrTime) { Vector2 vNewPos; int nCtr, nBestTargetID = -1; float nBestTargetDist = 0, nCurrDist; List <PhysicalObject> aTargetList = cObjMgr[cnTargetGroupID]; bool bRetVal = true; base.Update(CurrTime); if (ctCreated == -1) //Just created, mark the time { ctCreated = CurrTime.TotalGameTime.TotalMilliseconds; } switch (ceProjType) { case eProjectileType_t.Tracking: //Find a target to track for (nCtr = 0; nCtr < aTargetList.Count; nCtr++) { nCurrDist = MGMath.SquaredDistanceBetweenPoints(CenterPoint, aTargetList[nCtr].CenterPoint); if (nBestTargetID == -1) //No target picked { nBestTargetID = nCtr; nBestTargetDist = nCurrDist; } else if (nCurrDist < nBestTargetDist) { nBestTargetID = nCtr; nBestTargetDist = nCurrDist; } } if (nBestTargetID != -1) //Found a valid target, steer toward it { nCurrDist = AITools.SteerTowardTarget(CenterPoint, aTargetList[nBestTargetID].CenterPoint, ObjectRotation, cnMaxTurn); //Set the new movement direction, but don't change the speed SetMovement(nCurrDist, cnMaxSpeed); } if (CurrTime.TotalGameTime.TotalMilliseconds - ctCreated > ctTimeToLive) { //Lived its full life, time to pop bRetVal = false; } break; case eProjectileType_t.Straight: default: //No logic, just flies straight if (cGraphDev.Viewport.Width < CenterPoint.X + Width) //remove it when off screen { bRetVal = false; } if (cGraphDev.Viewport.Height < CenterPoint.Y + Height) //remove it when off screen { bRetVal = false; } if (CenterPoint.X < -1 * Width) { bRetVal = false; } if (CenterPoint.Y < -1 * Height) { bRetVal = false; } break; } //Look for collisions with all possible targets foreach (PhysicalObject CurrObj in aTargetList) { if (CurrObj.TestCollision(this) == true) { //Hit a target! (tell it that it was hit) CurrObj.ReportCollision(CurrTime, this); bRetVal = false; break; } } //Apply the current speed vNewPos = CenterPoint; vNewPos.X += Speed.X; vNewPos.Y += Speed.Y; CenterPoint = vNewPos; if ((ParticleHandler != null) && (bRetVal == false)) { //Missile is expiring, throw some particles for (nCtr = 0; nCtr < 10; nCtr++) { ParticleHandler.AddParticle(new DustParticle(CenterPoint, Rand, cGraphDev, cImgAtlas, "spaceEffects_008.png")); } } //Return True to keep this alive, false to have it removed return(bRetVal); }