/** @fn void SwitchModule( MODULE_IDENTIFIER nID ) * @brief change the current module */ private void SwitchModule(MODULE_IDENTIFIER nID) { //Find the module with the matching ID foreach (XNAModule theModule in m_vModules) { if (nID == theModule.ID) { m_Inputs.ResetInput();// ClearInput(); //m_soundManager.StopAll(); m_fElapsedDelay = 0; //Launch the loader m_loader.LoadModule(theModule); ///////////////////////// //Warning, potential thread synch issue here. m_font.Init(Graphics.GraphicsDevice.Viewport.Width, Graphics.GraphicsDevice.Viewport.Height, m_loader.Content.Load <SpriteFont>(@"Content\Font\DebugFont")); break; } } }
public void Cleanup() { toSwithcTo = MODULE_IDENTIFIER.MID_THIS; endGameTimer = 0.0f; if (AllObjects != null) { AllObjects.Clear(); } if (AllBarriers != null) { AllBarriers.Clear(); } if (TriggerList != null) { TriggerList.Clear(); } if (ObjSpawnList != null) { ObjSpawnList.Clear(); } if (MineSpawnList != null) { MineSpawnList.Clear(); } }
/** @fn void Update( GameTime gameTime ) * @brief Update the module scene * @param gameTime [in] information about the time between frames */ protected override void Update(GameTime gameTime) { //m_soundManager.Update(); //Calculate the elapsed time in seconds float fElapsedTime = (float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f; m_fTotalTime += fElapsedTime; if (m_currentModule == null) { //If current module is null, then one should be loading.. update the loader m_loader.Update(gameTime, fElapsedTime); } else { UpdateFPS(fElapsedTime); UpdateInput(fElapsedTime); #if WINDOWS /////////////////////////// //Handle escape keyboard press on windows builds if (m_Inputs.IsKeyDown(Keys.Escape)) { Exit(); } #endif //Update the module MODULE_IDENTIFIER moduleID = m_currentModule.Update(m_fTotalTime, fElapsedTime); base.Update(gameTime); if (moduleID != MODULE_IDENTIFIER.MID_GAME_MODULE && moduleID != MODULE_IDENTIFIER.MID_THIS) { for (int i = 0; i < 4; i++) { GamePad.SetVibration((PlayerIndex)i, 0.0f, 0.0f); } } //Check if the module requested a change, if so, change it. if (moduleID != MODULE_IDENTIFIER.MID_THIS) { SwitchModule(moduleID); } } }
/** @fn CXNAModule( MODULE_IDENTIFIER nID ) * @brief Constructor * @param nID [in] the ID of the module */ public XNAModule(MODULE_IDENTIFIER nID) { m_nModuleID = nID; m_parentApp = null; m_lstTextureResources = new List <string>(); m_lstModelResources = new List <string>(); m_lstShaderResources = new List <string>(); m_lstFontResources = new List <string>(); m_dtTextures = new Dictionary <string, Texture2D>(); m_dtModels = new Dictionary <string, Model>(); m_dtShaders = new Dictionary <string, Effect>(); m_dtFonts = new Dictionary <string, SpriteFont>(); m_bUseLoadScreen = true; }
public void Update(float elapsedTime) { ArrayList triggerToDelete = new ArrayList(); ArrayList subToDelete = new ArrayList(); ArrayList shadowsToDelete = new ArrayList(); ArrayList minesToDelete = new ArrayList(); theOffset.UpdateVariables(); theOffset.theExplosion(); //loop through each main list foreach (ArrayList listMain in AllObjects) { //loop through each sub list of objects foreach (Object listSub in (ArrayList)listMain) { //Object thisObject = listSub; if (listSub.WhatAmI() == "Player") { theOffset.followTarget((-1 * (listSub.Position)) //+ m_ParentApp.theOffset.varienceDisplacement + new Vector2(768, 0)); //768 is an arbitrary number that allows //m_ParentApp.theOffset.setMapDisplacement(-1*(listSub.Position)); } if (!listSub.Update(elapsedTime, AllBarriers)) { //Object thisObject = listSub; if (!listSub.Update(elapsedTime, AllBarriers)) { //if (String.Compare(listSub.GetType().FullName, "LambMines.Clutter") == 0) //{ for (int i = 0; i < TriggerList.Count; i++) { if (((TriggerObject)TriggerList[i]).referenceObj == listSub) { triggerToDelete.Add(TriggerList[i]); } } //} } if (String.Compare(listSub.GetType().FullName, "LambMines.Mine") == 0) { minesToDelete.Add(listSub); continue; } if (String.Compare(listSub.GetType().FullName, "LambMines.Explosion") == 0) { theOffset.setExplosion(false); } subToDelete.Add(listSub); } } } //confirm that the list dows not contain dangling participles. for (int i = 0; i < TriggerList.Count; i++) { //TriggerList.RemoveAt(i);. bool found = false; for (int fap = 0; fap < TriggerList.Count; fap++) { //loop through each main list foreach (ArrayList listMain in AllObjects) { //loop through each sub list of objects foreach (Object listSub in (ArrayList)listMain) { if (((TriggerObject)TriggerList[i]).referenceObj == listSub) { //triggerToDelete.Add(TriggerList[i]); found = true; } } } } if (!found) { TriggerList.RemoveAt(i); i--; continue; } } for (int j = 0; j < ObjSpawnList.Count;) { ((ArrayList)AllObjects[(int)RenderLevel.RL_SHADOWS]).Add(ObjSpawnList[j]); ObjSpawnList.Remove(ObjSpawnList[j]); } for (int k = 0; k < MineSpawnList.Count;) { ((ArrayList)AllObjects[(int)RenderLevel.RL_MINES]).Add(MineSpawnList[k]); TriggerList.Add(new TriggerObject(45.0f, (Mine)MineSpawnList[k])); MineSpawnList.Remove(MineSpawnList[k]); } //go from the reverse of the list because we are removing entries. for (int i = 0; i < triggerToDelete.Count; i++) { TriggerList.Remove(triggerToDelete[i]); } for (int i = 0; i < minesToDelete.Count; i++) { ((ArrayList)AllObjects[(int)RenderLevel.RL_MINES]).Remove(minesToDelete[i]); } for (int i = 0; i < subToDelete.Count; i++) { ((ArrayList)AllObjects[(int)RenderLevel.RL_OBJECTS]).Remove(subToDelete[i]); } if (isGameOver) { if (playerWon) { toSwithcTo = MODULE_IDENTIFIER.MID_WIN_MODULE; } else { toSwithcTo = MODULE_IDENTIFIER.MID_LOSE_MODULE; } } }