public void RestoreState(Form target) { keysDev.Dispose(); mouseDev.Dispose(); mouseDev = null; keysDev = null; try { //create our mouse device mouseDev = new Device(SystemGuid.Mouse); mouseDev.SetCooperativeLevel(target, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.Exclusive); mouseDev.Acquire(); //create our keyboard device keysDev = new Device(SystemGuid.Keyboard); keysDev.Properties.BufferSize = 0; keysDev.SetCooperativeLevel(target, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.NoWindowsKey); keysDev.Acquire(); } catch (Exception) { MessageBox.Show("DirectInput Faild to Start (userinterface.vb). Outerspace will exit"); target.Dispose(); Application.Exit(); } Cursor.Hide(); needrestore = false; }
internal void destroy() { keyboardDevice.Unacquire(); keyboardDevice.Dispose(); mouseDevice.Unacquire(); mouseDevice.Dispose(); }
/// <summary> /// Disposes of the mouse device. /// </summary> public void Dispose() { if (_device != null) { _device.Dispose(); _device = null; } }
protected void FreeDirectInput() { if (p_DInputDevice != null) { p_DInputDevice.Unacquire(); p_DInputDevice.Dispose(); p_DInputDevice = null; } }
static void FreeDirectInput() { if (null != mInputDevice) { mInputDevice.Unacquire(); mInputDevice.Dispose(); mInputDevice = null; } }
public void Release() { if (joystick != null) { joystick.Unacquire(); joystick.Dispose(); } joystick = null; isInitialized = false; // buttonMap.Clear(); }
private void FreeDirectInput() { if (this.mouse != null) { mouse.Unacquire(); mouse.Dispose(); mouse = null; } if (this.keyboard != null) { keyboard.Unacquire(); keyboard.Dispose(); keyboard = null; } }
} // 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(); } } }
public virtual void Dispose() { foreach (Picture picture in m_Pictures) { picture.Dispose(); } m_Pictures.Clear(); foreach (Font font in m_Fonts) { font.Dispose(); } m_Fonts.Clear(); foreach (Sound sound in m_Sounds) { sound.Dispose(); } m_Sounds.Clear(); foreach (Music music in m_Music) { music.Dispose(); } m_Music.Clear(); dIDevice.Dispose(); dIDevice = null; dsDevice.Dispose(); dsDevice = null; DXSprite.Dispose(); DXSprite = null; dGDevice.Dispose(); dGDevice = null; m_GameWindow.Dispose(); m_GameWindow = null; m_Disposed = true; }
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(); } }
} // inicializarMouse().fim // ---] // [--- void verificarMouse() { if (this.Focused == false) { return; } // 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.MouseState state; state = mouse.CurrentMouseState; byte[] btn = state.GetMouseButtons(); if (btn[0] > 0) { if (state.X < 0) { seta_esquerda = 1; } if (state.X > 0) { seta_direita = 1; } if (state.Y < 0) { seta_cima = 1; } if (state.Y > 0) { seta_abaixo = 1; } } // endif if (state.Z > 0) { seta_cima = 1; } if (state.Z < 0) { seta_abaixo = 1; } if (btn[1] > 0) { xcol = 320; ylin = 240; } // endif // Pressione os dois botões do mouse para sair if ((btn[1] > 0) && (btn[0] > 1)) { terminar = true; } // </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 = ":-)>"; } // Processa a tecla Escape if (terminar) { device.Dispose(); mouse.Dispose(); this.Close(); Application.Exit(); } // endif } // verificarMouse()
} // inicializarTeclado().fim // [--- void verificarTeclado() { string sInfo = "prj_Teclado02 - 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; // Verifica estado do teclado DirectInput.KeyboardState estadoTeclado; estadoTeclado = teclado.GetCurrentKeyboardState(); // Atualizado estados das variáveis de teclas if (estadoTeclado[DirectInput.Key.DownArrow]) { seta_abaixo = 1; } if (estadoTeclado[DirectInput.Key.UpArrow]) { seta_cima = 1; } if (estadoTeclado[DirectInput.Key.LeftArrow]) { seta_esquerda = 1; } if (estadoTeclado[DirectInput.Key.RightArrow]) { seta_direita = 1; } if (estadoTeclado[DirectInput.Key.RightShift]) { xcol = 320; } if (estadoTeclado[DirectInput.Key.RightShift]) { ylin = 240; } if (estadoTeclado[DirectInput.Key.Escape]) { terminar = true; } // 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 } // verificarTeclado()
} // onPaint().fim // [--- void verificarJoystick() { if (joystick == null) { return; } // 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.JoystickState state = joystick.CurrentJoystickState; byte[] btn = state.GetButtons(); if (state.X < -40) { seta_esquerda = 1; } if (state.X > 1) { seta_direita = 1; } if (state.Y < -40) { seta_cima = 1; } if (state.Y > 0) { seta_abaixo = 1; } if (state.Z < -40) { seta_cima = 1; } if (state.Z > 1) { seta_abaixo = 1; } // </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 = ":-)>"; } // Aplique um reset se botão 1 for pressionando if (btn[1] > 0) { xcol = 320; ylin = 240; } // endif // Pressione os dois botões [0] e [1] do joystick para sair if ((btn[1] > 0) && (btn[0] > 1)) { terminar = true; } // Processa a tecla Escape if (terminar) { device.Dispose(); joystick.Dispose(); this.Close(); Application.Exit(); } // endif } // Atualizarjoystick()
} // 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()