/// <summary> /// This method update the scene after a frame has finished rendering /// The method calls an update to every non-static gameobject, updating its physics, collisions etc. /// </summary> /// <param name="evt"></param> protected override void UpdateScene(FrameEvent evt) { //timeElapsed += evt.timeSinceLastFrame; player.Update(evt); if (gameHMD.gameTimeHasReachedZero(totalTime)) //if still time left on clock { gameHMD.updateTimerText(totalTime); //update the clock } else //else game timer has run out so end game { gameHMD.displayGameLoseText(); //display game completed text gamePlaying = false; //disable physics and input inputsManager.DisableInputs(); //disable the player inputs } if (gamePlaying == true) //if the game has not been won / lost { physics.UpdatePhysics(0.01f); //update the physics every 0.01 seconds. This value was tweaked until physics appeared realistic } base.UpdateScene(evt); if (player.GunReloading == true) //if the player is reloading { gameHMD.updateAmmoTextReloading(); //display info saying so in the GUI } else if (player.playerArmoury.ActiveGun != null) //else if the player has a gun equipped { gameHMD.updateAmmoText(player.playerArmoury.ActiveGun.Ammo.Value); //display the ammo count on the gun } if (inputsManager != null && gamePlaying == true) //if the game is playing (not won or lost) and the inputsManager has been created { inputsManager.ProcessInput(evt); // then process player inputs } if (gems.Count > 0) //if gems are instantiated in the game { foreach (Gem gem in gems) //for each gem { gem.Update(evt); //update the gem if (gem.RemoveMe == true) //and if a collision has been detected and the gem must be removed { gemsToRemove.Add(gem); //add the gem to gems to be removed player.Stats.Score.Increase(gem.Increase); //and update the score } } foreach (Gem gem in gemsToRemove) //for each gem that needs to be removed { gems.Remove(gem); //remove the gem from the list of active gems gem.Dispose(); //and dispose of it } gemsToRemove.Clear(); //clear the list now it has been disposed } if (powerUps.Count > 0) //if power up collectables are instantiated in the game { foreach (PowerUp pow in powerUps) //for each powerup { pow.Update(evt); //update the powerup if (pow.RemoveMe == true) //and if a collision has been detected and the power up must be removed { switch (pow.pickUpType) //determine the type of the powerup and apply the necessary buff to the player { case "life": player.Stats.Lives.Increase(pow.Increase); //add a life break; case "time": totalTime += 30; //add 30 seconds to the counter break; case "shield": player.Stats.Shield.Increase(pow.Increase); //add health break; case "health": player.Stats.Health.Increase(pow.Increase); //add shields break; } powerUpsToRemove.Add(pow); //then add the power up to be removed } } foreach (PowerUp pow in powerUpsToRemove) //for each power up that needs to be removed { powerUps.Remove(pow); //remove the power up from the list of active power ups pow.Dispose(); //and dispose of it } powerUpsToRemove.Clear(); //clear the list now it has been disposed } if (collectableGuns.Count > 0) //if collectables are instantiated in the game { foreach (CollectableGun gun in collectableGuns) //for each collectable { gun.Update(evt); //update the collectable if (gun.RemoveMe == true) //and if a collision has been detected and the collectable must be removed { collectableGunsToRemove.Add(gun); //the addition of the gun to the armoury is handled in the Player class, so add the gun to be removed } } foreach (CollectableGun gun in collectableGunsToRemove) //for each gun that needs to be removed { collectableGuns.Remove(gun); //remove the power up from the list of active gun collectables in the game gun.Dispose(); //and dispose of it } collectableGunsToRemove.Clear(); //clear the list now it has been disposed } if (enemies.Count > 0) //if robots are instantiated in the game { foreach (Robot rob in enemies) //for each robot that needs to be removed { rob.Update(evt); //update the robot if (rob.TimeElapsed > 1f) //if the robot has not shot in the last 0.5seconds { rob.TimeElapsed = 0; //reset the timer until shooting again Vector3 position = new Vector3(rob.Model.ControlNode.Position.x, 10, rob.Model.ControlNode.Position.z); //position shooting from Vector3 direction = new Vector3(player.Position.x - rob.Model.ControlNode.Position.x, 0, player.Position.z - rob.Model.ControlNode.Position.z); //direction in which to apply velocity to enemy projectiles towards the player direction = direction.NormalisedCopy; //Console.WriteLine(position); EnemyProjectile projectile = new EnemyProjectile(mSceneMgr, direction, position); projectile.SetPosition(position + 50 * direction); enemyProjectiles.Add(projectile); //add the new projectile to the list of enemy projectiles } if (rob.PlayerCollision) //if the robot collides with the player { if (player.Stats.Shield.Value != 0) //if the player has shields remaining { player.Stats.Shield.Decrease(1); //deduct shields } else //else the player has no shields { player.Stats.Health.Decrease(1); //so lower their health } rob.setPlayercol(false); //and reset that the player and robot are colliding to false } if (rob.BombCollision) //if the robot has collided with a player bomb { rob.Stats.Shield.Decrease(500); //damage both health and shields so the robot dies immediately rob.Stats.Health.Decrease(500); rob.setBombCol(false); //and reset the robot colliding with a bomb to false } if (rob.CannonCollision) //if the robot has collided with a player cannonball { if (rob.Stats.Shield.Value > 0) //if the player has shields { rob.Stats.Shield.Decrease(25); //deduct shields } else //else the player has no shields { rob.Stats.Health.Decrease(50); //so lower their health } rob.setCannonCol(false); //and reset that the robot and cannonball are colliding to false } gameHMD.updateBossText(enemies[0].Stats.Shield.Value, enemies[0].Stats.Health.Value, enemies[0]); //in the third level the health values of the boss are displayed on screen - send these vals to the GUI if (rob.Stats.Health.Value <= 0) //if the robot has no health { enemiesToRemove.Add(rob); //then add it to the remove list } } foreach (Robot rob in enemiesToRemove) //for each robot that needs to be removed { enemies.Remove(rob); //remove it from the current robots list rob.Dispose(); //and dispose of it } enemiesToRemove.Clear(); } foreach (EnemyProjectile proj in enemyProjectiles) { proj.checkDispose(); //check whether the projectile has existed for longer than it's lifetime if (proj.TimeElapsed > 1) //if it has then dispose of it { proj.Dispose(); } if (proj.IsCollidingWith("Player")) //if the robot projectile is colliding with the player { if (player.Stats.Shield.Value != 0) //if the player has shields { player.Stats.Shield.Decrease(100); //deduct shields } else //else the player has no shields { player.Stats.Health.Decrease(50); //so reduce their health } proj.Dispose(); //then dispose of the projectile } } if (player.Stats.Health.Value <= 0 && player.Stats.Lives.Value <= 0) //if no lives or health { gameHMD.displayGameLoseTextLives(); //display game loss text gamePlaying = false; //disable physics and input inputsManager.DisableInputs(); //set all current inputs to false } else if (player.Stats.Health.Value <= 0 && player.Stats.Lives.Value >= 1) //if no health but still has remaining lifes { player.Stats.Health.Reset(); //reset the player's health and shields player.Stats.Shield.Reset(); player.Stats.Lives.Decrease(1); //and reduce their lives by one } if (checkIfLevelComplete()) { if (level <= 2) //if there still is another level to play (e.g. level 3 has not been completed) { initNextLevel(); //init the next level gameHMD.updateLevelText(level); //and update the GUI to represent the new level number } else //else the final level and game has been completed { level++; gameHMD.updateBossText(0, 0, null); //ensure the display shows the boss is dead gameHMD.displayGameWinText(); //display game completed text gamePlaying = false; //disable physics and input inputsManager.DisableInputs(); //set all current inputs to false } } gameHMD.Update(evt); //updte the GUI last after all data has been processed that will be displayed }
/// <summary> /// This method update the scene after a frame has finished rendering /// </summary> /// <param name="evt"></param> protected override void UpdateScene(FrameEvent evt) /////////////Update scene { if (Globals.freezeGame == false) { physics.UpdatePhysics(0.01f); base.UpdateScene(evt); gameHMD.Update(evt); player.Update(evt); mCamera.LookAt(player.Position); //////////////////////////// if (Globals.currentLevel == 1) { if (gemList.Count == 0) { Globals.freezeGame = true; gameHMD.changeLevel(2); } } if (Globals.currentLevel == 2) { if (targetList.Count == 0) { Globals.freezeGame = true; gameHMD.changeLevel(3); } } if (Globals.currentLevel == 3) { if (robotList.Count == 0) { Globals.freezeGame = true; gameHMD.changeLevel(4); } } if (inputsManager.HideMessage && gemList.Count == 0 && Globals.currentLevel == 1) { inputsManager.HideMessage = false; CreateScene2(); Globals.freezeGame = false; gameHMD.Time.Reset(); gameHMD.hideMessage(); } if (inputsManager.HideMessage && targetList.Count == 0 && Globals.currentLevel == 2) { inputsManager.HideMessage = false; CreateScene3(); Globals.freezeGame = false; gameHMD.Time.Reset(); gameHMD.hideMessage(); } if (inputsManager.HideMessage && robotList.Count == 0 && Globals.currentLevel == 3) { // inputsManager.HideMessage = false; //// CreateScene3(); // Globals.freezeGame = false; // gameHMD.Time.Reset(); // gameHMD.hideMessage(); } #region ================ Adding to Remove list ================= foreach (Gem gems in gemList) { gems.Update(evt); if (gems.RemoveMe) { removeList.Add(gems); } } foreach (PowerUp lpu in powerUpList) { lpu.Update(evt); if (lpu.RemoveMe) { removeListPU.Add(lpu); } } foreach (Target tr in targetList) { tr.Update(evt); if (tr.RemoveMe || tr.remove1) { removeTargetList.Add(tr); } } // cg.Update(evt); foreach (Bomb b in bombList) { b.Update(evt); if (b.RemoveMe) { removeListBombs.Add(bombList[0]); } } foreach (CollectableGun cg in collectableGunList) { cg.Update(evt); if (cg.RemoveMe) { removeCollectableGunList.Add(cg); } } foreach (Projectile cg in projectileList) { cg.Update(evt); if (cg.RemoveMe) { removeProjectileList.Add(cg); } } foreach (Robot rb in robotList) { rb.Update(evt); if (rb.RemoveMe || rb.TouchesPlayer) { removeRobotList.Add(rb); } } #endregion #region ============= Removing items =================== foreach (Bomb b in removeListBombs) { bombList.Remove(b); b.Dispose(); } removeListBombs.Clear(); foreach (Gem remGems in removeList) { gemList.Remove(remGems); remGems.Dispose(); } removeList.Clear(); foreach (PowerUp lpu in removeListPU) { powerUpList.Remove(lpu); lpu.Dispose(); } removeListPU.Clear(); foreach (BombDropper bd in removeListBD) { gunList.Remove(bd); bd.Dispose(); } removeListBD.Clear(); foreach (CollectableGun cgr in removeCollectableGunList) { collectableGunList.Remove(cgr); cgr.Dispose(); } removeList.Clear(); foreach (Projectile cgr in removeProjectileList) { projectileList.Remove(cgr); cgr.Dispose(); } removeList.Clear(); foreach (Target tr in removeTargetList) { targetList.Remove(tr); tr.Dispose(); } removeTargetList.Clear(); foreach (Robot rb in removeRobotList) { robotList.Remove(rb); rb.Dispose(); } removeRobotList.Clear(); #endregion } else { //if (inputsManager.CanRestart) //{ // DestroyScene(); // Globals.freezeGame = false; // CreateScene(); //} } }
/// <summary> /// This method updates the scene after a frame has finished rendering /// </summary> /// <param name="evt"></param> protected override void UpdateScene(FrameEvent evt) { if (gameOver || timeOut) { return; } //if (!gameOver) { inputsManager.ProcessInput(evt); } Vector3 temp = playerModel.Position; temp.y = temp.y + 50; // move the camera target higher. mCamera.LookAt(temp); player.Update(evt); //temp.y += 20; for (var a = 0; a < robotNum; a++) { robots[a].Model.GameNode.LookAt(temp, Node.TransformSpace.TS_WORLD, Vector3.UNIT_Z); robots[a].Update(evt); } gameHMD.Update(evt); foreach (GemAmmo gemAmmo in gems_ammo) /// Checks for collision with Ammo Gems { gemAmmo.Update(evt); if (gemAmmo.RemoveMe) { gems_ammo_remover.Add(gemAmmo); //Console.WriteLine(gemAmmo.RemoveMe); } // } foreach (GemAmmo gemAmmo in gems_ammo_remover) { //Physics.RemovePhysObj(gemAmmo.PhysObj); //gemAmmo.PhysObj = null; ((PlayerStats)player.Stats).Score.Increase(50); //Console.WriteLine(((PlayerStats)player.Stats).Score.Value); gems_ammo.Remove(gemAmmo); gemAmmo.GameNode.RemoveAllChildren(); gemAmmo.GameNode.Parent.RemoveChild(gemAmmo.GameNode); gemAmmo.GameNode.DetachAllObjects(); gemAmmo.Dispose(); } gems_ammo_remover.Clear(); foreach (GemHealth gemhealth in gems_health) /// Checks for collision with Health Gems { gemhealth.Update(evt); if (gemhealth.RemoveMe) { gems_health_remover.Add(gemhealth); //Console.WriteLine(gemAmmo.RemoveMe); } // } foreach (GemHealth gemhealth in gems_health_remover) { //Physics.RemovePhysObj(gemAmmo.PhysObj); //gemAmmo.PhysObj = null; ((PlayerStats)player.Stats).Score.Increase(500); //Console.WriteLine(((PlayerStats)player.Stats).Score.Value); gems_health.Remove(gemhealth); gemhealth.GameNode.RemoveAllChildren(); gemhealth.GameNode.Parent.RemoveChild(gemhealth.GameNode); gemhealth.GameNode.DetachAllObjects(); gemhealth.Dispose(); } gems_health_remover.Clear(); bool collide; collide = ((PlayerModel)player.Model).IsCollidingWith("Phys_Cannon_"); if (collide) { Console.WriteLine("Player hit Cannon"); ((PlayerStats)player.Stats).Score.Increase(1000); cannon.Dispose(); //Gun cannonTemp = new Cannon(mSceneMgr, 0, 0, 0); // player.PlayerArmoury.CollectedGuns.Add(cannonTemp); } if (cannon != null) { cannon.Update(evt); } // health.Update(evt); gameHMD.Update(evt); if (gameHMD.Time.Milliseconds > 120000) { gameHMD.MaxTime(); timeOut = true; } // checks for end of level // // temp = playerModel.Position; // temp.y = temp.y + 100; // light.Position= temp; physics.UpdatePhysics(0.01f); if (player.Stats.Lives.Value <= 0) { Console.WriteLine("GAME OVER"); gameEnd(evt); } base.UpdateScene(evt); }
/// <summary> /// This method update the scene after a frame has finished rendering /// </summary> /// <param name="evt"></param> protected override void UpdateScene(FrameEvent evt) { physics.UpdatePhysics(0.01f); base.UpdateScene(evt); //Levels if (gemCount == 5) { gemCount++; level++; gameHMD.leveltxt = "Level 2"; AddCollGun(); for (int i = 0; i < 10; i++) { AddGem(playerStats.Score); } for (int i = 0; i < 5; i++) { AddPowerUp(playerStats.Health, playerStats.Shield, playerStats.Lives); } } if (gemCount == 16) { gemCount++; level++; gameHMD.leveltxt = "Level 3"; AddCollGun(); for (int i = 0; i < 10; i++) { AddGem(playerStats.Score); } AddRobot(); } if (gemCount == 27) { gemCount++; level++; gameHMD.leveltxt = "Level 4"; AddCollGun(); AddCollGun(); for (int i = 0; i < 15; i++) { AddGem(playerStats.Score); } for (int i = 0; i < 3; i++) { AddRobot(); } } if (gemCount == 43) { win = true; } if (shoot) { if (player.PlayerArmoury.ActiveGun != null && player.PlayerArmoury.ActiveGun.Ammo.Value != 0) { player.Shoot(); projList.Add(player.PlayerArmoury.ActiveGun.Projectile); } } if (reload) { player.PlayerArmoury.ActiveGun.ReloadAmmo(); } foreach (Projectile p in projList) { p.Update(evt); if (p.RemoveMe) { projListToRemove.Add(p); } } foreach (Projectile p in projListToRemove) { projList.Remove(p); p.Dispose(); } projListToRemove.Clear(); if (mWalkList.First.Value != player.Position) { mWalkList.RemoveFirst(); mWalkList.AddLast(player.Position); } foreach (Enemies e in robots) { e.Update(evt); if (e.Model.RemoveMe) { robotsToRemove.Add(e); } } foreach (Enemies e in robotsToRemove) { robots.Remove(e); e.Model.Dispose(); } robotsToRemove.Clear(); foreach (Gem g in Gems) { g.Update(evt); if (g.RemoveMe) { gemsToRemove.Add(g); gemCount++; } } foreach (Gem g in gemsToRemove) { Gems.Remove(g); g.Dispose(); } gemsToRemove.Clear(); foreach (CollectableGun cg in collGuns) { cg.Update(evt); if (cg.RemoveMe) { collGunsToRemove.Add(cg); } } foreach (CollectableGun cg in collGunsToRemove) { collGuns.Remove(cg); cg.Dispose(); } collGunsToRemove.Clear(); foreach (PowerUp pu in PowerUps) { pu.Update(evt); if (pu.RemoveMe) { powerUpsToRemove.Add(pu); } } foreach (PowerUp pu in powerUpsToRemove) { PowerUps.Remove(pu); pu.Dispose(); } powerUpsToRemove.Clear(); if (player.Model.RemoveMe) { if (playerStats.Shield.Value > 0 && hitCount == 0) { playerStats.Shield.Decrease(5); } else if (playerStats.Health.Value == 0 && hitCount == 0) { playerStats.Lives.Decrease(1); playerStats.Shield.Increase(100); playerStats.Health.Increase(100); } else if (playerStats.Health.Value > 0 && hitCount == 0) { playerStats.Health.Decrease(5); } hitCount++; } player.Update(evt); gameHMD.Update(evt); if (hitCount == 50) { hitCount = 0; } mCamera.LookAt(player.Position); shoot = false; reload = false; }