private void UpdateEndOfGame(GameTime gameTime) { var mouseState = Mouse.GetState(); var mousePoint = new Point(mouseState.X, mouseState.Y); if (returnToMainMenuButton.location.Contains(mousePoint)) { returnToMainMenuButton.hover(); } else { returnToMainMenuButton.unhover(); } if (restartEndOfGameButton.location.Contains(mousePoint)) { restartEndOfGameButton.hover(); } else { restartEndOfGameButton.unhover(); } if (returnToMainMenuButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { returnToMainMenuButton.press(); } else if (restartEndOfGameButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { restartEndOfGameButton.press(); } if (returnToMainMenuButton.isPressed) { if (returnToMainMenuButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { MediaPlayer.Stop(); MediaPlayer.Play(menuSong); returnToMainMenuButton.unpress(); isPausePressed = false; _currentGameState = GameState.MainMenu; } } else if (restartEndOfGameButton.isPressed) { if (restartEndOfGameButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { restartEndOfGameButton.unpress(); isPausePressed = false; RestartGame(); _currentGameState = GameState.GamePlay; } } }
private void UpdateGameplay(GameTime gameTime) { if (scroll1.location.Y + scroll1.location.Height >= 8192) { scroll1.location.Y = scroll2.location.Y - scroll2.backgroundTexture.Height; } if (scroll2.location.Y + scroll2.backgroundTexture.Height >= 8192) { scroll2.location.Y = scroll1.location.Y - scroll1.backgroundTexture.Height; } scroll1.Update(); scroll2.Update(); player.UpdateMovement(); #region ButtonFunctionality if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { isPausePressed = true; this.IsMouseVisible = true; Pause(); //TODO napisać funkcje pauzująca grę } var mouseState = Mouse.GetState(); var mousePoint = new Point(mouseState.X, mouseState.Y); if (!showUpgradeWindow) { if (exitToMainMenuButton.location.Contains(mousePoint)) { exitToMainMenuButton.hover(); } else { exitToMainMenuButton.unhover(); } if (resumeButton.location.Contains(mousePoint)) { resumeButton.hover(); } else { resumeButton.unhover(); } if (restartButton.location.Contains(mousePoint)) { restartButton.hover(); } else { restartButton.unhover(); } if (upgradeButton.location.Contains(mousePoint)) { upgradeButton.hover(); } else { upgradeButton.unhover(); } if (exitToMainMenuButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { exitToMainMenuButton.press(); } else if (resumeButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { resumeButton.press(); } else if (restartButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { restartButton.press(); } else if (upgradeButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { upgradeButton.press(); } coinBackgroundButton.hideButton(); oneShotButton.hideButton(); piercingButton.hideButton(); movementSpeedButton.hideButton(); fireRateButton.hideButton(); } if (showUpgradeWindow) { if (oneShotButton.location.Contains(mousePoint)) { oneShotButton.hover(); } else { oneShotButton.unhover(); } if (piercingButton.location.Contains(mousePoint)) { piercingButton.hover(); } else { piercingButton.unhover(); } if (movementSpeedButton.location.Contains(mousePoint)) { movementSpeedButton.hover(); } else { movementSpeedButton.unhover(); } if (fireRateButton.location.Contains(mousePoint)) { fireRateButton.hover(); } else { fireRateButton.unhover(); } if (oneShotButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { oneShotButton.press(); } else if (piercingButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { piercingButton.press(); } else if (movementSpeedButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { movementSpeedButton.press(); } else if (fireRateButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { fireRateButton.press(); } coinBackgroundButton.showHiddenButton(); oneShotButton.showHiddenButton(); piercingButton.showHiddenButton(); movementSpeedButton.showHiddenButton(); fireRateButton.showHiddenButton(); if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { showUpgradeWindow = false; } } if (exitToMainMenuButton.isPressed) { if (exitToMainMenuButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { MediaPlayer.Stop(); MediaPlayer.Play(menuSong); exitToMainMenuButton.unpress(); isPausePressed = false; _currentGameState = GameState.MainMenu; } } else if (resumeButton.isPressed) { if (resumeButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { resumeButton.unpress(); isPausePressed = false; Resume(); } } else if (restartButton.isPressed) { if (restartButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { restartButton.unpress(); isPausePressed = false; RestartGame(); } } else if (upgradeButton.isPressed) { if (upgradeButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { upgradeButton.unpress(); showUpgradeWindow = true; } } else if (oneShotButton.isPressed) { if (oneShotButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { oneShotButton.unpress(); if (coinCount >= 5 && !isOneShotBought) { missileTexture = oneShotMissileTexture; coinCount -= 5; } } } else if (piercingButton.isPressed) { if (piercingButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { piercingButton.unpress(); if (coinCount >= 3 && !isPiercingBought) { missileTexture = piercingMissileTexture; coinCount -= 3; } } } else if (movementSpeedButton.isPressed) { if (movementSpeedButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { movementSpeedButton.unpress(); if (coinCount >= 1) { player.speed++; coinCount--; } } } else if (fireRateButton.isPressed) { if (fireRateButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { fireRateButton.unpress(); if (coinCount >= 1) { shootingSpeed++; coinCount--; } } } #endregion if (shooting) { //waves config if (actualScore > 100 && _currentEnemyWave == EnemyWave.First) { throwSomeCoins = true; _currentEnemyWave = EnemyWave.Second; enemySpeed = 2; } else if (actualScore > 200 && _currentEnemyWave == EnemyWave.Second) { throwSomeCoins = true; _currentEnemyWave = EnemyWave.Third; enemySpeed = 2; } else if (actualScore > 300 && _currentEnemyWave == EnemyWave.Third) { throwSomeCoins = true; _currentEnemyWave = EnemyWave.Fourth; enemySpeed = 2; } else if (actualScore > 400 && _currentEnemyWave == EnemyWave.Fourth) { throwSomeCoins = true; _currentEnemyWave = EnemyWave.Fifth; enemySpeed = 2; } //drawing missiles if (missiles.Count == 0) { missiles.Add(new Missile(missileTexture, new Rectangle(player.playerLocation.X + player.playerLocation.Width / 2 - 5, player.playerLocation.Y, 10, 32), shootingSpeed)); } else if (missiles[missiles.Count - 1].isNextReady(fireRate)) { missiles.Add(new Missile(missileTexture, new Rectangle(player.playerLocation.X + player.playerLocation.Width / 2 - 5, player.playerLocation.Y, 10, 32), shootingSpeed)); } foreach (Missile m in missiles) { //clearing destroyed missiles if (m.isDestroyed) { missiles.Remove(m); break; } else { m.Update(); } } //drawing enemies if (enemies.Count == 0) { enemies.Add(new Enemy(enemyTexture1, enemyTexture2, enemyTexture3, enemyTexture4, enemyTexture5, new Rectangle(rnd.Next(500), -100, 100, 100), enemySpeed, _currentEnemyWave)); } else if (enemies[enemies.Count - 1].isNextReady()) { enemies.Add(new Enemy(enemyTexture1, enemyTexture2, enemyTexture3, enemyTexture4, enemyTexture5, new Rectangle(rnd.Next(500), -100, 100, 100), enemySpeed, _currentEnemyWave)); } foreach (Enemy e in enemies) { //clearing destroyed enemies if (e.isDestroyed) { enemies.Remove(e); actualScore++; break; } else { e.Update(); } if (e.enemyLocation.Y > 800) { player.Hit(); e.isDestroyed = true; } if (player.health == 0) { Pause(); _currentGameState = GameState.EndOfGame; } } //missiles collision detection foreach (Missile m in missiles) { foreach (Enemy e in enemies) { if (e.enemyLocation.Contains(m.missileLocation)) { if (missileTexture == oneShotMissileTexture) { e.Hit(500); } else if (missileTexture == piercingMissileTexture) { e.Hit(50); } else { e.Hit(25); } m.isDestroyed = true; if (actualScore % 10 == 0 && enemySpeed != 5) { enemySpeed++; } } } foreach (TossACoin c in coins) { if (c.coinLocation.Contains(m.missileLocation)) { c.isDestroyed = true; coinCount++; } } } //update coins, check if out of screen foreach (TossACoin c in coins) { if (c.isDestroyed) { coins.Remove(c); break; } else { c.Update(); } } //drawing coins if (throwSomeCoins) { coins.Add(new TossACoin(coinTexture, new Rectangle(rnd.Next(500), -90, 45, 55))); coins.Add(new TossACoin(coinTexture, new Rectangle(rnd.Next(500), -150, 45, 55))); coins.Add(new TossACoin(coinTexture, new Rectangle(rnd.Next(500), -210, 45, 55))); throwSomeCoins = false; } } else if (isPausePressed == false) { shooting = true; } }
private void UpdateMainMenu(GameTime gameTime) { this.IsMouseVisible = true; var mouseState = Mouse.GetState(); var mousePoint = new Point(mouseState.X, mouseState.Y); #region ButtonsFunctionality if (!showSkinsWindow) { if (startButton.location.Contains(mousePoint)) { startButton.hover(); } else { startButton.unhover(); } if (exitButton.location.Contains(mousePoint)) { exitButton.hover(); } else { exitButton.unhover(); } if (skinsButton.location.Contains(mousePoint)) { skinsButton.hover(); } else { skinsButton.unhover(); } if (startButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { startButton.press(); } else if (exitButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { exitButton.press(); } else if (skinsButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { skinsButton.press(); } skin1Button.hideButton(); skin2Button.hideButton(); skin3Button.hideButton(); skin4Button.hideButton(); skin5Button.hideButton(); selectedSkinCoverButton.hideButton(); } if (showSkinsWindow) { if (skin1Button.location.Contains(mousePoint)) { skin1Button.hover(); } else { skin1Button.unhover(); } if (skin2Button.location.Contains(mousePoint)) { skin2Button.hover(); } else { skin2Button.unhover(); } if (skin3Button.location.Contains(mousePoint)) { skin3Button.hover(); } else { skin3Button.unhover(); } if (skin4Button.location.Contains(mousePoint)) { skin4Button.hover(); } else { skin4Button.unhover(); } if (skin5Button.location.Contains(mousePoint)) { skin5Button.hover(); } else { skin5Button.unhover(); } if (skin1Button.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { skin1Button.press(); } else if (skin2Button.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { skin2Button.press(); } else if (skin3Button.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { skin3Button.press(); } else if (skin4Button.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { skin4Button.press(); } else if (skin5Button.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Pressed) { skin5Button.press(); } skin1Button.showHiddenButton(); skin2Button.showHiddenButton(); skin3Button.showHiddenButton(); skin4Button.showHiddenButton(); skin5Button.showHiddenButton(); selectedSkinCoverButton.showHiddenButton(); if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { showSkinsWindow = false; } } if (exitButton.isPressed) { if (exitButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { exitButton.unpress(); Exit(); } } else if (startButton.isPressed) { if (startButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { startButton.unpress(); MediaPlayer.Stop(); MediaPlayer.Play(gameplaySong); MediaPlayer.IsRepeating = true; _currentGameState = GameState.GamePlay; RestartGame(); } } else if (skinsButton.isPressed) { if (skinsButton.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { skinsButton.unpress(); showSkinsWindow = true; } } else if (skin1Button.isPressed) { if (skin1Button.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { skin1Button.unpress(); player.playerTexture = playerTexture; missileTexture = bulletSkin1; currentBulletTexture = bulletSkin1; selectedSkinCoverButton.location.Y = 0; } } else if (skin2Button.isPressed) { if (skin2Button.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { skin2Button.unpress(); player.playerTexture = spaceShipSkin2; currentBulletTexture = bulletSkin2; missileTexture = bulletSkin2; selectedSkinCoverButton.location.Y = 160; } } else if (skin3Button.isPressed) { if (skin3Button.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { skin3Button.unpress(); player.playerTexture = spaceShipSkin3; currentBulletTexture = bulletSkin3; missileTexture = bulletSkin3; selectedSkinCoverButton.location.Y = 320; } } else if (skin4Button.isPressed) { if (skin4Button.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { skin4Button.unpress(); player.playerTexture = spaceShipSkin4; currentBulletTexture = bulletSkin4; missileTexture = bulletSkin4; selectedSkinCoverButton.location.Y = 480; } } else if (skin5Button.isPressed) { if (skin5Button.location.Contains(mousePoint) && mouseState.LeftButton == ButtonState.Released) { skin5Button.unpress(); player.playerTexture = spaceShipSkin5; missileTexture = bulletSkin5; currentBulletTexture = bulletSkin5; selectedSkinCoverButton.location.Y = 640; } } #endregion }