private void frmAsteroids_KeyDown(object sender, KeyEventArgs e) { // Check escape key if (e.KeyData == Keys.Escape) // Escape { // Escape during a title screen exits the game if (gameStatus == Modes.TITLE) { gameStatus = Modes.EXIT; Application.Exit(); } // Escape in game goes back to Title Screen if (gameStatus == Modes.GAME) { score.CancelGame(); currTitle = new TitleScreen(); gameStatus = Modes.TITLE; } } else // Not Escape { // If we are in tht Title Screen, Start a game if (gameStatus == Modes.TITLE) { score.ResetGame(); currGame = new Game(); gameStatus = Modes.GAME; bLeftPressed = false; bRightPressed = false; bUpPressed = false; bHyperspaceLastPressed = false; bShootingLastPressed = false; bPauseLastPressed = false; } else // In Game { // Keydown handled in game // Rotate Left if (e.KeyData == Keys.Left) { bLeftPressed = true; } // Rotate Right if (e.KeyData == Keys.Right) { bRightPressed = true; } // Thrust if (e.KeyData == Keys.Up) { bUpPressed = true; } // Hyperspace (can't be held down) if (!bHyperspaceLastPressed && (e.KeyData == Keys.Down)) { bHyperspaceLastPressed = true; currGame.Hyperspace(); } // Shooting (can't be held down) if (!bShootingLastPressed && (e.KeyData == Keys.Space)) { bShootingLastPressed = true; currGame.Shoot(); } // Pause can't be held down) if (!bPauseLastPressed && (e.KeyData == Keys.P)) { bPauseLastPressed = true; currGame.Pause(); } } } }