Exemple #1
0
        //Key Detection
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (lost == false)
            {
                if (pause == false)
                {
                    if (e.KeyCode == Keys.W)
                    {
                        MoveUpTimer.Start();

                        MoveDownTimer.Stop();
                        MoveLeftTimer.Stop();
                        MoveRightTimer.Stop();
                    }
                    if (e.KeyCode == Keys.A)
                    {
                        MoveLeftTimer.Start();

                        MoveUpTimer.Stop();
                        MoveDownTimer.Stop();
                        MoveRightTimer.Stop();
                    }
                    if (e.KeyCode == Keys.S)
                    {
                        MoveDownTimer.Start();

                        MoveUpTimer.Stop();
                        MoveLeftTimer.Stop();
                        MoveRightTimer.Stop();
                    }
                    if (e.KeyCode == Keys.D)
                    {
                        MoveRightTimer.Start();

                        MoveUpTimer.Stop();
                        MoveDownTimer.Stop();
                        MoveLeftTimer.Stop();
                    }
                }
            }
        }
Exemple #2
0
 //KeyDown Event Handler
 private void SpaceForm_KeyDown(object sender, KeyEventArgs e)
 {
     if (!pause)
     {
         if (e.KeyCode == Keys.Right)
         {
             MoveRigthTimer.Start();
         }
         if (e.KeyCode == Keys.Left)
         {
             MoveLeftTimer.Start();
         }
         if (e.KeyCode == Keys.Down)
         {
             MoveDownTimer.Start();
         }
         if (e.KeyCode == Keys.Up)
         {
             MoveTopTimer.Start();
         }
     }
 }