private List <PictureBox> livesPics; // used for displaying extra lives #endregion #region Game Initialization /// <summary> /// this method initializes the game and plays the opening sequence. /// </summary> public Form1() { InitializeComponent(); Control.CheckForIllegalCrossThreadCalls = false; SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.SupportsTransparentBackColor, false); FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; Utilities.populateRandPool(); GameMedia.InitializeMedia(); Game.IntializeGame(this); GameSounds.initializeMusic(); GameSounds.backGroundLoop(); lbl_level.Hide(); lbl_score.Hide(); lvlSplashCycler = -1; //private WriteableBitmap bmp }
/// <summary> /// does all of the operating on the form, so that there isn't more than one thread operating on the form /// controls at once. Also calls all the objects' draw methods on form.refresh. /// </summary> private void graphicsEngine() { int currentTime = 0; int previousTime = Environment.TickCount; int deltaTime = 0; while (true) { currentTime = Environment.TickCount; deltaTime = currentTime - previousTime; if (deltaTime < Settings.graphicsInverseFPS) { Thread.Sleep(Settings.graphicsInverseFPS - deltaTime); } previousTime = currentTime; if (MainGame.isRunning) { this.Refresh(); } else if (MainGame.needsToExit) { return; } else { switch (MainGame.stateDescription) { case "LevelWon": showLevelSplash(); lbl_LvlScr.Text = "LEVEL: " + MainGame.level + "\nSCORE: " + MainGame.score; lbl_LvlScr.Show(); lbl_level.Hide(); lbl_score.Hide(); MessageBox.Show("Next Level!", "Good Job!", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000); hideLevelSplash(); lbl_LvlScr.Hide(); lbl_level.Show(); lbl_score.Show(); MainGame.score += MainGame.level * 100; MainGame.level++; Game.InitializeNextLevel(this); GameSounds.backGroundLoop(); break; case "LevelLost": MainGame.lives--; this.BeginInvoke((MethodInvoker) delegate() //() => { foreach (PictureBox p in livesPics) { this.Controls.Remove(p); } populateLivesPics(); }); MessageBox.Show("Switch to next miner?", "Died!", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000); Game.InitializeNextLevel(this); GameSounds.backGroundLoop(); break; case "GameLost": showHighScores(); MainGame.needsToExit = true; this.Refresh(); MessageBox.Show("Press ok to exit.", "Play again soon!", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000); Exit(); return; case "extraLife": MainGame.extraLifeAdded = false; this.BeginInvoke((MethodInvoker) delegate() { foreach (PictureBox p in livesPics) { this.Controls.Remove(p); } populateLivesPics(); }); break; case "Paused": MessageBox.Show("Game is Paused!!", "PAUSE", MessageBoxButtons.OK); break; case "Help": MessageBox.Show("Up Arrow: Accelerate \n\nLeft Arrow: Rotate Left \n\nRight Arrow: Rotate Right \n\nSpace Bar: Shoot\n\nCTRL: Warp\n\nLeft Click: Target" + "\n\n______________\n\nFOR MOUSE:\n______________\n\nShip points at mouse.\n\nLeft click to fire\n\nRight click to accelerate" + "\n\nMiddle or Side Click to target\n\nSpace Bar: Warp\n\n______________\n\nESC: QUIT", "Help", MessageBoxButtons.OK); break; } MainGame.isRunning = true; } } }