public override void Update(GameTime gameTime) { if (isDying == true) { m_animation.Update(gameTime); deathTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (deathTimer <= 0) { Destroyed = true; } } else { base.Update(gameTime); } redEnemyLivesCounter.SetCount(redEnemyLives); redEnemyLivesCounter.Position = m_position + new Vector2(-10, -25); }
public override void Update(GameTime gameTime) { elapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; cursor.SetCursor(Cursors.normal); continueButton.isEnabled = (repairs >= 15); isPaused = continueButton.isEnabled; if (moveableSprites.OfType <Player>().Count() > 0) { Player player = moveableSprites.OfType <Player>().First(); livesCounter.SetCount(player.lives); woodPileCounter.SetCount(player.woodPiles); nailCounter.SetCount(player.nails); } //The current level can be reset using the R key (for testing only) if (Input.beenPressed(Keys.R)) { LoadLevel(Game.Content, currentLevel); } //Levels can be skipped through using the Num Pad 0 key (for testing only) if (Input.beenPressed(Keys.NumPad0)) { LoadLevel(Game.Content, currentLevel + 1); } //The game can be paused using the P key bool pPressed = Input.beenPressed(Keys.P); //If P is pressed the game will switch to the pause screen and freeze the game in the background if (pPressed) { Game.ScreenMgr.Switch(new PauseScreen(Game)); } //Checking if big windows are destroyed and drawing an enemy at a 1 in 750 chance (60 x per second) if they are foreach (var bigWindow in collideableSprites.OfType <BigWindow>()) { if (bigWindow.IsDestroyed() && random.Next(750) == 1) { addMoveable(m_content, bigWindow.Hitbox.Location.ToVector2(), new NormalEnemy(true, moveableSprites.OfType <Player>().First(), collideableSprites, moveableSprites, new Vector2(0, 1))); } //Checking if big windows are destroyed and drawing a stronger enemy at a 1 in 3000 chance (60 x per second) if they are if (bigWindow.IsDestroyed() && random.Next(3000) == 1) { addMoveable(m_content, bigWindow.Hitbox.Location.ToVector2(), new RedEnemy(true, moveableSprites.OfType <Player>().First(), collideableSprites, moveableSprites, new Vector2(0, 1))); } //Changing the cursor to the hammer if it is contained by a big window if (bigWindow.Hitbox.Contains((Input.WorldMousePosition))) { cursor.SetCursor(Cursors.hammer); } } //See above comments foreach (var smallWindow in collideableSprites.OfType <SmallWindow>()) { if (smallWindow.IsDestroyed() && random.Next(1300) == 1) { addMoveable(m_content, smallWindow.Hitbox.Location.ToVector2(), new NormalEnemy(true, moveableSprites.OfType <Player>().First(), collideableSprites, moveableSprites, new Vector2(0, 1))); } if (smallWindow.IsDestroyed() && random.Next(3000) == 1) { addMoveable(m_content, smallWindow.Hitbox.Location.ToVector2(), new RedEnemy(true, moveableSprites.OfType <Player>().First(), collideableSprites, moveableSprites, new Vector2(0, 1))); } if (smallWindow.Hitbox.Contains((Input.WorldMousePosition))) { cursor.SetCursor(Cursors.hammer); } } //See above comments foreach (var door in collideableSprites.OfType <Door>()) { if (door.IsDestroyed() && random.Next(900) == 1) { addMoveable(m_content, door.Hitbox.Location.ToVector2(), new NormalEnemy(true, moveableSprites.OfType <Player>().First(), collideableSprites, moveableSprites, new Vector2(0, 1))); } if (door.IsDestroyed() && random.Next(3000) == 1) { addMoveable(m_content, door.Hitbox.Location.ToVector2(), new RedEnemy(true, moveableSprites.OfType <Player>().First(), collideableSprites, moveableSprites, new Vector2(0, 1))); } if (door.Hitbox.Contains((Input.WorldMousePosition))) { cursor.SetCursor(Cursors.hammer); } } //Setiing the cursor to the sword if it is hovering over an enemy foreach (var enemy in moveableSprites.OfType <Enemy>()) { if (enemy.Hitbox.Contains((Input.WorldMousePosition))) { cursor.SetCursor(Cursors.sword); } } foreach (var redEnemy in moveableSprites.OfType <RedEnemy>()) { if (redEnemy.Hitbox.Contains((Input.WorldMousePosition))) { cursor.SetCursor(Cursors.sword); } } //If the player clicks on a nail within the world and the nail counter is not full it is collected and added to the counter foreach (var nail in collideableSprites.OfType <Nail>()) { if (nail.Hitbox.Contains(Input.WorldMousePosition) && Input.isMouseJustClicked() && m_player.nails < 5) { nail.Destroyed = true; m_player.nails++; PickupSound.Play(); } } foreach (var woodPile in collideableSprites.OfType <WoodPile>()) { if (woodPile.Hitbox.Contains(Input.WorldMousePosition) && Input.isMouseJustClicked() && m_player.woodPiles < 10) { woodPile.Destroyed = true; m_player.woodPiles++; PickupSound.Play(); } } //Game runs if it is not paused (WHODDA THUNK IT?) if (isPaused == false) { foreach (var moveable in moveableSprites) { moveable.Update(gameTime); } foreach (var collidable in collideableSprites) { collidable.Update(gameTime); } } //The continue button can be clicked at the end of levels. If the player is not on level 5, the next level is loaded, else, the highscore entry screen is loaded if (continueButton.IsClicked()) { if (currentLevel < 5) { LoadLevel(Game.Content, currentLevel + 1); repairs = 0; } else if (currentLevel > 4 && continueButton.IsClicked()) { Game.ScreenMgr.Switch(new PlayerEntry(Game, (int)elapsedTime)); } } collideableSprites.RemoveAll(sprite => sprite.Destroyed); moveableSprites.RemoveAll(sprite => sprite.Destroyed); camera.Update(m_player.Hitbox.Location.ToVector2()); }