public void AsteroidControl() { // If enough time has passed, a new asteroid is created if (tickCounter >= asteroidInterval) { // Randomizes where the asteroid spawns from asteroidDirection = rand.Next(1, 5); // Declares the direction that the asteroid will travel switch (asteroidDirection) { case 1: Asteroids newDownAsteroid = new Asteroids(asteroidSize, 245, 0, "Down"); asteroidList.Add(newDownAsteroid); break; case 2: Asteroids newLeftAsteroid = new Asteroids(asteroidSize, 0, 245, "Right"); asteroidList.Add(newLeftAsteroid); break; case 3: Asteroids newUpAsteroid = new Asteroids(asteroidSize, 245, 500, "Up"); asteroidList.Add(newUpAsteroid); break; case 4: Asteroids newRightAsteroid = new Asteroids(asteroidSize, 500, 245, "Left"); asteroidList.Add(newRightAsteroid); break; } tickCounter = 0; } // Controls how the Asteroid moves foreach (Asteroids a in asteroidList) { if (a.direction == "Up") { a.MoveUp(asteroidSpeed); } else if (a.direction == "Left") { a.MoveLeft(asteroidSpeed); } else if (a.direction == "Down") { a.MoveDown(asteroidSpeed); } else if (a.direction == "Right") { a.MoveRight(asteroidSpeed); } } // Checks for a collision between the Ship and an Asteroid foreach (Asteroids a in asteroidList) { if (shipHitBox.shipCollision(a)) { // Plays a sound effect if (OptionsScreen.setSoundOptions) { crashSound.Play(); } // Stops the game and switches to the GameOverScreen gameLoop.Stop(); Form f = this.FindForm(); f.Controls.Remove(this); GameOverScreen gs = new GameOverScreen(); f.Controls.Add(gs); return; } } // Checks for a collision between a Lazer and an Asteroid foreach (Lazers l in lazerList) { foreach (Asteroids a in asteroidList) { if (a.lazerCollision(l)) { // Removes the Lazer and Asteroid that collided from their respective lists playerScore++; asteroidList.Remove(a); lazerList.Remove(l); return; } } } // Controls the frequency of which Asteroids spawn if (speedController >= 500 && levelCounter < 8) { // Plays a sound effect if (OptionsScreen.setSoundOptions) { levelUpSound.Play(); } // The higher the level, the more frequently that Asteroids spawn levelCounter++; asteroidInterval -= 3; speedController = 0; } // Lets the user know that their level has increased levelUpLabel.Visible = false; if (speedController >= 0 && speedController <= 25 && levelCounter > 1 && totalFrameCounter > 200) { levelUpLabel.Visible = true; } }
/// <summary> /// Event handler for when the game over event /// </summary> void OnGameOver(object sender, PlayerIndexEventArgs e) { GameOverScreen gameOverScreen = new GameOverScreen(networkSession); ScreenManager.AddScreen(gameOverScreen, ControllingPlayer); }