public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); mouse.Update(); exitButton.Update(mouse.rectangle); if (exitButton.Intersects(mouse.rectangle) && mouse.newLeftClick) { exitButton.sound.Play(); ScreenManager.RemoveScreen(this); ScreenManager.AddScreen(new MainMenuScreen(), null); } }
/// <summary> /// Tells the screen to go away. Unlike ScreenManager.RemoveScreen, which /// instantly kills the screen, this method respects the transition timings /// and will give the screen a chance to gradually transition off. /// </summary> public void ExitScreen() { if (TransitionOffTime == TimeSpan.Zero) { // If the screen has a zero transition time, remove it immediately. ScreenManager.RemoveScreen(this); } else { // Otherwise flag that it should transition off and then exit. isExiting = true; } }
/// <summary> /// Allows the screen to run logic, such as updating the transition position. /// Unlike HandleInput, this method is called regardless of whether the screen /// is active, hidden, or in the middle of a transition. /// </summary> public virtual void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { this.otherScreenHasFocus = otherScreenHasFocus; if (isExiting) { // If the screen is going away to die, it should transition off. screenState = ScreenState.TransitionOff; if (!UpdateTransition(gameTime, transitionOffTime, 1)) { // When the transition finishes, remove the screen. ScreenManager.RemoveScreen(this); } } else if (coveredByOtherScreen) { // If the screen is covered by another, it should transition off. if (UpdateTransition(gameTime, transitionOffTime, 1)) { // Still busy transitioning. screenState = ScreenState.TransitionOff; } else { // Transition finished! screenState = ScreenState.Hidden; } } else { // Otherwise the screen should transition on and become active. if (UpdateTransition(gameTime, transitionOnTime, -1)) { // Still busy transitioning. screenState = ScreenState.TransitionOn; } else { // Transition finished! screenState = ScreenState.Active; } } }
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); mouse.Update(); easyButton.Update(mouse.rectangle); if (easyButton.Intersects(mouse.rectangle) && mouse.newLeftClick) { easyButton.sound.Play(); ScreenManager.RemoveScreen(this); ScreenManager.AddScreen(new NameEntryScreen(GameDifficulty.EASY_MODE), null); } hardButton.Update(mouse.rectangle); if (hardButton.Intersects(mouse.rectangle) && mouse.newLeftClick) { hardButton.sound.Play(); ScreenManager.RemoveScreen(this); ScreenManager.AddScreen(new NameEntryScreen(GameDifficulty.HARD_MODE), null); } }
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { if (levelstart && !otherScreenHasFocus) { ScreenManager.AddScreen(new MessageBoxScreen("", mouseTexture), null); levelstart = false; } base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); if (coveredByOtherScreen) { pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1); } else { pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0); } if (!otherScreenHasFocus) { Vector2 prevCamPos = cam.position; cam.Update(player, objList, backgroundLayer); if (!player.isAlive && player.pSprite.isFinished) { cam.position = new Vector2(0, 0); backgroundLayer = TileLayer.FromFile(content, "Content/Layers/LevelOneBackgroundLayer.txt"); player._playerPos = new Vector2(150, 150); } previousPlayerPos = player._playerPos; player.Update(gameTime, objList, cam); if (player._lives == 0) { ScreenManager.RemoveScreen(this); ScreenManager.AddScreen(new GameOverScreen(player, GameOverScreen.gameOverType.GAMEOVER), null); } // COLLISION List <TileObject> objRemoveList = new List <TileObject>(); List <TileObject> objCreateList = new List <TileObject>(); List <AnimatedSprite> animRemoveList = new List <AnimatedSprite>(); foreach (TileObject c in objList) { if (cam.position != prevCamPos) { c.objPos = c.objPos - (cam.position - prevCamPos); } c.Update(); if (player._playerRec.Intersects(c.objRec)) { if (c.objType == ObjectType.PICKUP) { if (player._health >= 50) { player._health = 100; } else { player._health += 50; } objRemoveList.Add(c); } } foreach (Bullet b in player.bulletList) { if (b.intersectsTarget(c.objRec)) { if (c.objType == ObjectType.DESTRUCTIBLE) { bulletDeleteList.Add(b); objRemoveList.Add(c); animList.Add(new AnimatedSprite(explosionTexture, AnimatedSprite.AnimType.PLAY_ONCE, 6, 6, 0.02f, new Vector2(c.objPos.X + c.objRec.Width / 2, c.objPos.Y + c.objRec.Width / 2), 1.5f)); sound.Play(); } if (c.objType == ObjectType.CRATE) { bulletDeleteList.Add(b); objRemoveList.Add(c); int test = 1; if (this.diff == GameDifficulty.HARD_MODE) { test = rand.Next(0, 7); } else { test = rand.Next(0, 5); } if (test == 0) { objCreateList.Add(new TileObject(heart, ObjectType.PICKUP, new Vector2(c.objRec.X, c.objRec.Y))); } } } } } foreach (AnimatedSprite a in animList) { if (cam.position != prevCamPos) { a.pos = a.pos - (cam.position - prevCamPos); } a.Update(gameTime); if (a.spriteRec.Intersects(player._playerRec) && !a.playerDamaged) { player._health -= 30; a.playerDamaged = true; } if (a.isFinished) { animRemoveList.Add(a); } } foreach (AnimatedSprite a in animRemoveList) { animList.Remove(a); } foreach (TileObject c in objCreateList) { objList.Add(c); } foreach (TileObject c in objRemoveList) { objList.Remove(c); } foreach (Enemy e in enemyList) { if (cam.position != prevCamPos) { e._enemyPos = e._enemyPos - (cam.position - prevCamPos); } e.Update(player._playerRec, gameTime); if (e.returnIntersect(player._playerRec)) { if (e.canDamage) { player._health -= 5; } } foreach (Bullet b in e.bulletList) { if (cam.position != prevCamPos) { b._bulletPos = b._bulletPos - (cam.position - prevCamPos); } if (b.intersectsTarget(player._playerRec)) { player._health -= 10; eBulletDeleteList.Add(b); } } foreach (Bullet b in eBulletDeleteList) { e.bulletList.Remove(b); } foreach (Bullet b in player.bulletList) { if (b.intersectsTarget(e.enemyRec)) { e.health -= 10; bulletDeleteList.Add(b); } } foreach (AnimatedSprite a in animList) { if (a.spriteRec.Intersects(e.enemyRec) && !a.damagedEnemies.Contains(e)) { e.health -= 100; a.damagedEnemies.Add(e); } } if (e.health <= 0) { enemyDeleteList.Add(e); if (e._type == EnemyType.normal) { player.score += 10; } if (e._type == EnemyType.fast) { player.score += 20; } if (e._type == EnemyType.hard) { player.score += 50; } if (e._type == EnemyType.projectile) { player.score += 70; } if (e._type == EnemyType.boss) { player.score += 100; } } } foreach (Bullet b in bulletDeleteList) { player.bulletList.Remove(b); } foreach (Enemy e in enemyDeleteList) { enemyList.Remove(e); } //LEVEL COMPLETE if (enemyList.Count == 0) { ScreenManager.Game.Components.Remove(particleComponent); isLevelComplete = true; } if (isLevelComplete) { ScreenManager.RemoveScreen(this); ScreenManager.AddScreen(new LevelCompleteScreen(player, this.diff, 50.0f), null); } } if (player.level == 3) { Emitter t2 = particleComponent.particleEmitterList[0]; t2.Position = new Vector2((float)random.NextDouble() * (ScreenManager.Game.GraphicsDevice.Viewport.Width), 0); if (t2.EmittedNewParticle) { float f = MathHelper.ToRadians(t2.LastEmittedParticle.Direction + 180); t2.LastEmittedParticle.Rotation = f; } } }