예제 #1
0
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     if (!pause)
     {
         if (e.KeyCode == Keys.Right)
         {
             RightMoveTimer.Start();
         }
         if (e.KeyCode == Keys.Left)
         {
             LeftMoveTimer.Start();
         }
         if (e.KeyCode == Keys.Up)
         {
             UpMoveTimer.Start();
         }
         if (e.KeyCode == Keys.Down)
         {
             DownMoveTimer.Start();
         }
         if (e.KeyCode == Keys.Space)
         {
             if (currentAmmo < limAmmo)
             {
                 currentAmmo++;
                 fire = true;
             }
         }
     }
 }
예제 #2
0
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right || e.KeyCode == Keys.Down || e.KeyCode == Keys.Up)
     {
         mainPlayer.Image = Properties.Resources.cowboy_run;
         if (e.KeyCode == Keys.Left)
         {
             LeftMoveTimer.Start();
         }
         if (e.KeyCode == Keys.Right)
         {
             RightMoveTimer.Start();
         }
         if (e.KeyCode == Keys.Up)
         {
             UpMoveTimer.Start();
         }
         if (e.KeyCode == Keys.Down)
         {
             DownMoveTimer.Start();
         }
     }
     if (e.KeyCode == Keys.Space)
     {
         ShootingTimer.Start();
     }
     if (e.KeyCode == Keys.Escape)
     {
         Process.GetCurrentProcess().Kill();
     }
 }
예제 #3
0
        // This is when key is pressed
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (!pause)
            {
                if (e.KeyCode == Keys.Right)
                {
                    RightMoveTimer.Start();
                }

                if (e.KeyCode == Keys.Left)
                {
                    LeftMoveTimer.Start();
                }

                if (e.KeyCode == Keys.Down)
                {
                    DownMoveTimer.Start();
                }

                if (e.KeyCode == Keys.Up)
                {
                    UpMoveTimer.Start();
                }
            }
        }
예제 #4
0
 private void StartTimers()
 {
     LeftMoveTimer.Start();
     RightMoveTimer.Start();
     LaserTimer.Start();
     EnemiesTimer.Start();
 }
예제 #5
0
        private void StartTimers()
        {
            int milliseconds = 2000;

            Thread.Sleep(milliseconds);

            LeftMoveTimer.Start();
            RightMoveTimer.Start();
            UpMoveTimer.Start();
            DownMoveTimer.Start();

            MoveBgTimer.Start();
            MoveEnemiesTimer.Start();
            MoveAmmunitionTimer.Start();
            EnemiesAmmunitionTimer.Start();
        }
예제 #6
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Left)
            {
                if (Spaceship.spaceshipX > 20)
                {
                    LeftMoveTimer.Start();
                }
                else
                {
                    LeftMoveTimer.Stop();
                    Spaceship.spaceshipV = 0;
                }
            }
            if (e.KeyCode == Keys.Right)
            {
                if (Spaceship.spaceshipX < 580)
                {
                    RightMoveTimer.Start();
                }
                else
                {
                    RightMoveTimer.Stop();
                    Spaceship.spaceshipV = 0;
                }
            }

            if (e.KeyCode == Keys.Space)
            {
                LaserTimer.Start();
            }

            if (e.KeyCode == Keys.R)
            {
                ResetGame();
            }
        }
예제 #7
0
        public void Form1_KeyDown(object sender, KeyEventArgs e) // Function that performs movements in 2D space for 3 models of spacecraft
        {
            e.SuppressKeyPress = true;
            if (!paused)
            {
                switch (e.KeyCode)
                {
                case Keys.D:         // Button D
                    if (firstPlane)
                    {
                        Player.Image = Properties.Resources.Plane_1_right;
                    }
                    else if (secondPlane)
                    {
                        Player.Image = Properties.Resources.Plane_2_right;
                    }
                    else if (thirdPlane)
                    {
                        Player.Image = Properties.Resources.Plane_3_right;
                    }
                    RihtMoveTimer.Start();
                    break;

                case Keys.A:         // Button A
                    if (firstPlane)
                    {
                        Player.Image = Properties.Resources.Plane_1_left;
                    }
                    else if (secondPlane)
                    {
                        Player.Image = Properties.Resources.Plane_2_left;
                    }
                    else if (thirdPlane)
                    {
                        Player.Image = Properties.Resources.Plane_3_left;
                    }
                    LeftMoveTimer.Start();
                    break;

                case Keys.S:         // Button S
                    if (firstPlane)
                    {
                        Player.Image = Properties.Resources.Plane_1_down;
                    }
                    else if (secondPlane)
                    {
                        Player.Image = Properties.Resources.Plane_2_place;
                    }
                    else if (thirdPlane)
                    {
                        Player.Image = Properties.Resources.Plane_3_down;
                    }
                    BackMoveTimer.Start();
                    break;

                case Keys.W:         // Button W
                    if (firstPlane)
                    {
                        Player.Image = Properties.Resources.Plane_1_up;
                    }
                    else if (secondPlane)
                    {
                        Player.Image = Properties.Resources.Plane_2_up;
                    }
                    else if (thirdPlane)
                    {
                        Player.Image = Properties.Resources.Plane_3_up;
                    }
                    ForwardMoveTimer.Start();
                    break;

                case Keys.Space:         //Button Space
                    if (!isDead)
                    {
                        if (paused)
                        {
                            StartTimers();
                        }
                        else
                        {
                            ShootSound.controls.play();
                            MoveBullets();
                        }
                    }

                    break;

                case Keys.P:
                    if (isstarted)
                    {
                        StopTimers();
                        Menu_On();
                    }
                    break;
                }
            }
            else
            {
                if (e.KeyCode == Keys.C)
                {
                    if (isstarted)
                    {
                        StartTimers();
                        Menu_Off();
                    }
                }
            }
        }