private void Restart() { // Initial egg spawn time eggSpawnTime = TimeSpan.FromSeconds(4); previousEggTime = TimeSpan.FromSeconds(-3); // Initial egg pace eggPace = TimeSpan.FromSeconds(1); score = 0; health.Clear(); eggs.Clear(); crushedEggs.Clear(); eggGameState = EggGameState.Game; }
private void CheckGameOver() { if (health.Value == 0) { Debug.Print("Game over!"); gameOverSound.Play(); eggGameState = EggGameState.GameOver; } }
private void Pause() { eggGameState = EggGameState.Pause; }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.N)) { Restart(); } if (Keyboard.GetState().IsKeyDown(Keys.Space) && eggGameState != EggGameState.GameOver) { Pause(); } if (Keyboard.GetState().IsKeyDown(Keys.P) && eggGameState != EggGameState.GameOver) { eggGameState = EggGameState.Game; } if ((kinectStartState == StartResult.ManyKinectsDetected || kinectStartState == StartResult.KinectError) && eggGameState != EggGameState.GameOver) Pause(); if (kinectStartState == StartResult.KinectStarted) { var kinectCurrentVoice = kinect.GetCurrentVoiceCommand(); switch (kinectCurrentVoice) { case VoiceCommand.NewGame: Restart(); break; case VoiceCommand.Exit: Exit(); break; case VoiceCommand.Pause: if(eggGameState != EggGameState.GameOver) Pause(); break; case VoiceCommand.Continue: if (eggGameState != EggGameState.GameOver) eggGameState = EggGameState.Game; break; } } if (eggGameState == EggGameState.Pause) { pauseButton.Visible = false; continueButton.Visible = true; } else if (eggGameState == EggGameState.GameOver) { continueButton.Visible = pauseButton.Visible = false; } else { pauseButton.Visible = true; continueButton.Visible = false; } if (eggGameState == EggGameState.Game) { UpdateCatcher(gameTime); UpdateEggs(gameTime); } UpdateCrushedEggs(gameTime); if (eggGameState == EggGameState.Game) { base.Update(gameTime); } }