public void GameLoop() { gameEngine = new GameEngine(); GameEngine.BackgroundColor = Color.Black; gameEngine.CreateGameField(); //LOOP timer.Start(); while (this.Created) { startTime = timer.ElapsedMilliseconds; RenderAll(); Application.DoEvents(); while (timer.ElapsedMilliseconds - startTime < interval) { ; } } }
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.W) { keyData = Keys.Up; } if (keyData == Keys.S) { keyData = Keys.Down; } if (keyData == Keys.A) { keyData = Keys.Left; } if (keyData == Keys.D) { keyData = Keys.Right; } switch (keyData) { case Keys.Right: if (gameEngine.isRunning == true && gameEngine.isPaused == false) { gameEngine.pacMan.NextDirection = PacMan.PacManDirection.Right; } break; case Keys.Left: if (gameEngine.isRunning == true && gameEngine.isPaused == false) { gameEngine.pacMan.NextDirection = PacMan.PacManDirection.Left; } break; case Keys.Down: if (gameEngine.isRunning == true && gameEngine.isPaused == false) { gameEngine.pacMan.NextDirection = PacMan.PacManDirection.Down; } break; case Keys.Up: if (gameEngine.isRunning == true && gameEngine.isPaused == false) { gameEngine.pacMan.NextDirection = PacMan.PacManDirection.Up; } break; case Keys.Escape: if (gameEngine.isRunning == true) { gameEngine.isPaused = !gameEngine.isPaused; if (gameEngine.isPaused) { this.Text = "Main - PAUSED"; } else { this.Text = "Main"; } } break; case Keys.Enter: if (gameEngine.isRunning == false && gameEngine.isGameOver == true) { gameEngine.CreateGameField(); } break; } return(base.ProcessCmdKey(ref msg, keyData)); }