Esempio n. 1
0
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     GameInput.ChangeState(e.KeyCode, true);
     if (GameInput.PressedKey(Keys.U))
     {
         canvas.BackgroundImage = background;
     }
 }
Esempio n. 2
0
        private void UpdateScreen(object sender, EventArgs e)
        {
            highscoreLBL.Text = Highscore.GetHighScore(Settings.player1Name).ToString();

            //Check for Game Over
            if (Settings.IsGameOver)
            {
                //Check if Enter is pressed
                if (GameInput.PressedKey(Keys.Enter))
                {
                    StartGame();
                }
            }
            else
            {
                //(()or())and()
                if (GameInput.PressedKey(Keys.Space))
                {
                    Settings.IsGamePaused = !Settings.IsGamePaused;
                    pausedLBL.Visible     = !pausedLBL.Visible;
                }
                if (GameInput.PressedKey(Keys.K))
                {
                    createPowerup();
                }

                //move when unpaused
                if (!Settings.IsGamePaused)
                {
                    if ((GameInput.PressedKey(Keys.Right) || (GameInput.PressedKey(Keys.D))) && Settings.InGameDirection != Direction.Left)
                    {
                        Settings.InGameDirection = Direction.Right;
                    }
                    else if ((GameInput.PressedKey(Keys.Left) || (GameInput.PressedKey(Keys.A))) && Settings.InGameDirection != Direction.Right)
                    {
                        Settings.InGameDirection = Direction.Left;
                    }
                    else if ((GameInput.PressedKey(Keys.Up) || (GameInput.PressedKey(Keys.W))) && Settings.InGameDirection != Direction.Down)
                    {
                        Settings.InGameDirection = Direction.Up;
                    }
                    else if ((GameInput.PressedKey(Keys.Down) || (GameInput.PressedKey(Keys.S))) && Settings.InGameDirection != Direction.Up)
                    {
                        Settings.InGameDirection = Direction.Down;
                    }
                    MoveSnake(Snake);
                }
            }


            canvas.Invalidate();
        }