Пример #1
0
 public static void Update()
 {
     for (int i = 0; i < 256; i++)
     {
         m_KeyStates[i].IsPressed = false;
     }
     foreach (Key key in dIDevice.GetPressedKeys())
     {
         m_KeyStates[(int)key].IsPressed = true;
     }
     for (int i = 0; i < 256; i++)
     {
         if (m_KeyStates[i].IsPressed)
         {
             if (m_KeyStates[i].WasPressed)
             {
                 m_KeyStates[i].IsTriggered = false;
             }
             else
             {
                 m_KeyStates[i].WasPressed  = true;
                 m_KeyStates[i].IsTriggered = true;
             }
         }
         else
         {
             m_KeyStates[i].WasPressed  = false;
             m_KeyStates[i].IsTriggered = false;
         }
     }
 }
Пример #2
0
    } // inicializarTeclado().fim    


    void verificarTeclado()
    {

      // Variáveis para guardar o estado das teclas
      int seta_esquerda = 0;
      int seta_direita = 0;
      int seta_cima = 0;
      int seta_abaixo = 0;

      // <b>
      DirectInput.Key[] teclasPressionadas = teclado.GetPressedKeys();

      // Verifica teclado e atualiza teclas de estado
      foreach (DirectInput.Key tecla in teclasPressionadas)
      {
        if (tecla == DirectInput.Key.DownArrow) seta_abaixo = 1;
        if (tecla == DirectInput.Key.UpArrow) seta_cima = 1;
        if (tecla == DirectInput.Key.LeftArrow) seta_esquerda = 1;
        if (tecla == DirectInput.Key.RightArrow) seta_direita = 1;
        if (tecla == DirectInput.Key.RightShift) xcol = 320;
        if (tecla == DirectInput.Key.RightShift) ylin = 240;
        if (tecla == DirectInput.Key.Escape) terminar = true;
      } // endfor each
      // </b>

      // Atualiza posicionamento do 'jogador'
      if (seta_abaixo == 1) ylin += 5;
      if (seta_cima == 1) ylin -= 5;
      if (seta_esquerda == 1) xcol -= 5;
      if (seta_direita == 1) xcol += 5;

      // Processa a tecla Escape
      if (terminar)
      {
        device.Dispose();
        teclado.Dispose();
        this.Close();
        Application.Exit();
      } // endif

    } // AtualizarTeclado()  
 protected void ProcessInputState()
 {
     foreach (Key k in kbd.GetPressedKeys())
     {
         if (k == Key.Left)
         {
             //Turn counterclockwise
             angle -= spinRate;
         }
         if (k == Key.Right)
         {
             //turn clockwise
             angle += spinRate;
         }
         if (k == Key.Escape)
         {
             kbd.Unacquire();                     //release the keyboard device
             kbd.Dispose();
             Application.Exit();
         }
     }
 }
Пример #4
0
 protected void ProcessInputState(float delta)
 {
     foreach (Key k in kbd.GetPressedKeys())
     {
         if (k == Key.Space && ship.Visible)
         {
             //Fire guns
             lastBullet += delta;
             if (lastBullet > bulletSpacing)
             {
                 BulletSprite bullet = new BulletSprite(bulletTileSet);
                 //Calculate bullet start position, outside ship boundaries
                 float radAngle = Geometry.DegreeToRadian(ship.Angle);
                 int   yOffset  = (int)(bulletFireRadius * Math.Sin((double)radAngle));
                 int   xOffset  = (int)(bulletFireRadius * Math.Cos((double)radAngle));
                 bullet.PositionY = (ship.PositionY) + shipTileSet.ExtentY + yOffset;
                 //the -4 below is a small nudge to center up the bullets
                 bullet.PositionX      = (ship.PositionX) + shipTileSet.ExtentX + xOffset - 4;
                 bullet.Angle          = ship.Angle;
                 bullet.Velocity       = 150f;
                 bullet.AnimationSpeed = 0f;
                 bullet.CanCollide     = true;
                 bullet.LimitLifespan(2f); //only 2 seconds to live
                 sm.AddSprite(bullet);
                 lastBullet = 0f;
                 if (totalScore > 0)
                 {
                     totalScore--;                 //lose a point for each bullet
                 }
                 shipSounds |= Sounds.ShipFire;
             }
         }
         if (k == Key.Left)
         {
             ship.PrevFrame();
         }
         if (k == Key.Right)
         {
             ship.NextFrame();
         }
         if (k == Key.Up)
         {
             ship.Thrust();
             shipSounds |= Sounds.ShipThrust;
         }
         if (k == Key.Down)
         {
             //Put on the brakes!
             ship.VelocityX = 0f;
             ship.VelocityY = 0f;
             shipSounds    |= Sounds.ShipBrake;
         }
         if (k == Key.Escape)
         {
             kbd.Unacquire(); //release the keyboard device
             kbd.Dispose();
             Application.Exit();
         }
         if (k == Key.Home)
         {
             //resets ship to starting position
             ship.PositionY = (float)this.Height / 2;
             ship.PositionX = (float)this.Width / 2;
             ship.VelocityX = 0f;
             ship.VelocityY = 0f;
             ship.Angle     = 0.0f;
             ship.Frame     = 10;
         }
         //if (k == Key.D) sm.ShowList();
     }
 }
Пример #5
0
        public void Move()
        {
            try
            {
                Device.Acquire();
            }
            catch
            {
                return;
            }

            foreach (Key kk in Device.GetPressedKeys())
            {
                switch (kk.ToString())
                {
                case "W":
                    Position.X += (Target.X - Position.X) * Speed;
                    Position.Y += (Target.Y - Position.Y) * Speed;
                    Position.Z += (Target.Z - Position.Z) * Speed;
                    break;

                case "S":
                    Position.X -= (Target.X - Position.X) * Speed;
                    Position.Y -= (Target.Y - Position.Y) * Speed;
                    Position.Z -= (Target.Z - Position.Z) * Speed;
                    break;

                case "A":
                    Strafe(false);
                    break;

                case "D":
                    Strafe(true);
                    break;

                case "Z":
                    Position.Z -= Speed;
                    break;

                case "X":
                    Position.Z += Speed;
                    break;

                case "Equals":
                case "Add":
                    Speed += 0.01f;
                    break;

                case "Minus":
                case "NumPadMinus":
                    Speed -= 0.01f;
                    if (Speed <= 0.01f)
                    {
                        Speed = 0.01f;
                    }
                    break;
                }

                ComputePosition();
            }
        }
Пример #6
0
        public void Render()
        {
            mousePos = this.PointToClient(System.Windows.Forms.Cursor.Position);
            //Clear the backbuffer and begin the scene.
            device.Clear(ClearFlags.Target, BGcolor, 1.0f, 0);
            device.BeginScene();
            foreach (Input.Key key in keyboard.GetPressedKeys())
            {
                switch (key)
                {
                case Input.Key.Space:
                    frames[frameIndex].createVertex();
                    break;

                case Input.Key.W:
                    createFrame(frames[frameIndex]);
                    break;

                case Input.Key.A:
                    prevFrame();
                    break;

                case Input.Key.D:
                    nextFrame();
                    break;

                case Input.Key.X:
                    removeFrame();
                    break;

                case Input.Key.S:
                    createFrame();
                    break;

                case Input.Key.Q:
                    SaveFrames();
                    break;

                case Input.Key.E:
                    LoadFrames();
                    break;

                case Input.Key.F1:
                    if (!managingInput)
                    {
                        managingInput = true;
                        if (showHelp)
                        {
                            showHelp = false;
                        }
                        else
                        {
                            showHelp = true;
                        }
                    }
                    break;
                }
            }
            if (keyboard.GetPressedKeys().Length == 0)
            {
                if (managingInput)
                {
                    managingInput = false;
                }
                if (frames[frameIndex].creating)
                {
                    frames[frameIndex].creating = false;
                }
            }
            frames[frameIndex].DrawFrame();
            font.DrawText(null, "Frame " + (frameIndex + 1) + " of " + frames.Count, Width - 125, 15, Color.LightGoldenrodYellow);
            if (showHelp)
            {
                font.DrawText(null, helpMessage, Width - 325, Height - 300, Color.LightGoldenrodYellow);
            }

            //End the scene.
            device.EndScene();
            device.Present();
        }
Пример #7
0
        private void UpdateKeyboard()
        {
            //Capture pressed keys.
            Key[] keys = null;
            try
            {
                keyboard.Poll();
                keys = keyboard.GetPressedKeys();
            }
            catch (InputLostException)
            {
                try
                {
                    FreeDirectInput();
                    InitInputDevices();
                    keys = keyboard.GetPressedKeys();
                }
                catch (InputException ex)
                {
                    Logging.Logger.AddError("CHYBA - V INPUTU " + ex.ToString());
                    return;
                }
            }
            foreach (Key k in keys)
            {
                switch (k)
                {
                case Key.W:
                    actions.Add(Action.MoveForwardStart);
                    break;

                case Key.S:
                    actions.Add(Action.MoveBackwardStart);
                    break;

                case Key.A:
                    actions.Add(Action.MoveLeftStart);
                    break;

                case Key.D:
                    actions.Add(Action.MoveRightStart);
                    break;

                case Key.Escape:
                    actions.Add(Action.Exit);
                    break;

                case Key.U:
                    actions.Add(Action.InvertMouse);
                    break;

                case Key.F:
                    actions.Add(Action.Action3);
                    break;

                case Key.Return:
                    actions.Add(Action.ChangeFillMode);
                    break;
                }
            }
        }
Пример #8
0
        } // inicializarTeclado().fim

        // ---]


        // [---
        void verificarTeclado()
        {
            string sInfo = "prj_Teclado01 - Teclas pressionadas: ";

            // Variáveis para guardar o estado das teclas
            int seta_esquerda = 0;
            int seta_direita  = 0;
            int seta_cima     = 0;
            int seta_abaixo   = 0;

            // <b>
            DirectInput.Key[] teclasPressionadas = teclado.GetPressedKeys();

            // Verifica teclado e atualiza teclas de estado
            foreach (DirectInput.Key tecla in teclasPressionadas)
            {
                sInfo += tecla.ToString() + " ";

                if (tecla == DirectInput.Key.DownArrow)
                {
                    seta_abaixo = 1;
                }
                if (tecla == DirectInput.Key.UpArrow)
                {
                    seta_cima = 1;
                }
                if (tecla == DirectInput.Key.LeftArrow)
                {
                    seta_esquerda = 1;
                }
                if (tecla == DirectInput.Key.RightArrow)
                {
                    seta_direita = 1;
                }
                if (tecla == DirectInput.Key.RightShift)
                {
                    xcol = 320;
                }
                if (tecla == DirectInput.Key.RightShift)
                {
                    ylin = 240;
                }
                if (tecla == DirectInput.Key.Escape)
                {
                    terminar = true;
                }
            } // endfor each
              // </b>

            // Atualiza posicionamento do 'jogador'
            if (seta_abaixo == 1)
            {
                ylin += 5;
            }
            if (seta_cima == 1)
            {
                ylin -= 5;
            }
            if (seta_esquerda == 1)
            {
                xcol -= 5;
            }
            if (seta_direita == 1)
            {
                xcol += 5;
            }

            // Muda 'jogador' conforme seta pressionada
            if (seta_esquerda == 1)
            {
                jogador = "<(-:";
            }
            if (seta_direita == 1)
            {
                jogador = ":-)>";
            }

            this.Text = sInfo;

            // Processa a tecla Escape
            if (terminar)
            {
                device.Dispose();
                teclado.Dispose();
                this.Close();
                Application.Exit();
            } // endif
        }     // AtualizarTeclado()
Пример #9
0
 public CustomKeyboardState(Microsoft.DirectX.DirectInput.Device keyboard)
 {
     keys = keyboard.GetPressedKeys();
 }