public override void CheckState(ref Microsoft.DirectX.DirectInput.JoystickState controllerState) { bool s = (controllerState.GetButtons()[Index] & 0x80) == 0x80; if (s) { if (!_repeating) { _state = s; _repeatingState = _state; OnChangeValue(_state); _repeating = true; _timer.Change(RepeatAfter, System.Threading.Timeout.Infinite); } } else { if (_repeating || _state) { _repeating = false; _timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); _state = s; OnChangeValue(_state); } } }
public override void FirstCheckState(ref Microsoft.DirectX.DirectInput.JoystickState controllerState) { bool s = (controllerState.GetButtons()[Index] & 0x80) == 0x80; _state = !s; CheckState(ref controllerState); }
public override void FirstCheckState(ref Microsoft.DirectX.DirectInput.JoystickState controllerState) { int s = controllerState.GetPointOfView()[Index]; _state = -s; CheckState(ref controllerState); }
public override void CheckState(ref Microsoft.DirectX.DirectInput.JoystickState controllerState) { bool s = (controllerState.GetButtons()[Index] & 0x80) == 0x80; if (_state != s) { _state = s; OnChangeValue(_state); } }
public override void CheckState(ref Microsoft.DirectX.DirectInput.JoystickState controllerState) { int s = controllerState.GetPointOfView()[Index]; if (_state != s) { _state = s; OnChangeValue(_state); } }
public override void CheckState(ref Microsoft.DirectX.DirectInput.JoystickState controllerState) { int pos = 0; switch (SliderType) { case AxisType.X: pos = controllerState.X; break; case AxisType.Y: pos = controllerState.Y; break; case AxisType.Z: pos = controllerState.Z; break; case AxisType.RX: pos = controllerState.Rx; break; case AxisType.RY: pos = controllerState.Ry; break; case AxisType.RZ: pos = controllerState.Rz; break; case AxisType.EXT1: pos = controllerState.GetSlider()[0]; break; case AxisType.EXT2: pos = controllerState.GetSlider()[1]; break; default: throw new ApplicationException("Nieobsługiwana oś kontrolera."); } if (_position != pos) { _position = pos; if (Reverse) { OnChangeValue(Max - (_position - Min)); } else { OnChangeValue(_position); } } }
public void update(Microsoft.DirectX.DirectInput.JoystickState stick) { int absoluteMovement = stick.Z; int range = maximalValue - minimalValue; if (absoluteMovement < range / 2) { movement[(int)Side.LEFT] = range / 2 - absoluteMovement; movement[(int)Side.RIGHT] = 0; } else { movement[(int)Side.LEFT] = 0; movement[(int)Side.RIGHT] = absoluteMovement - range / 2; } }
public override void FirstCheckState(ref Microsoft.DirectX.DirectInput.JoystickState controllerState) { int pos = 0; switch (SliderType) { case AxisType.X: pos = controllerState.X; break; case AxisType.Y: pos = controllerState.Y; break; case AxisType.Z: pos = controllerState.Z; break; case AxisType.RX: pos = controllerState.Rx; break; case AxisType.RY: pos = controllerState.Ry; break; case AxisType.RZ: pos = controllerState.Rz; break; case AxisType.EXT1: pos = controllerState.GetSlider()[0]; break; case AxisType.EXT2: pos = controllerState.GetSlider()[1]; break; default: throw new ApplicationException("Nieobsługiwana oś kontrolera."); } _position = -pos; CheckState(ref controllerState); }
public override void CheckState(ref Microsoft.DirectX.DirectInput.JoystickState controllerState) { int s = controllerState.GetPointOfView()[Index]; if (s == _state && _state == -1) { return; } if (s == _state || s != -1) { if (s != _state) { _state = s; _repeatingState = false; OnChangeValue(_state); _repeating = true; _timer.Change(RepeatAfter, System.Threading.Timeout.Infinite); return; } if (!_repeating) { _state = s; _repeatingState = false; OnChangeValue(_state); _timer.Change(RepeatAfter, System.Threading.Timeout.Infinite); _repeating = true; return; } } else { if (_repeating || _state != -1) { _repeating = false; _timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); _state = s; OnChangeValue(_state); return; } } }
//* -----------------------------------------------------------------------* /// <summary>入力状態更新のスレッドです。</summary> /// /// <returns>スレッドが実行される間、<c>true</c></returns> private IEnumerator <object> threadStateReflesh() { while (true) { yield return(null); bool[] bState = new bool[BUTTON_STATE.Length]; #if WINDOWS KeyboardState stateKey = Keyboard.GetState(); for (int i = 0; i < bState.Length; i++) { bState[i] = stateKey.IsKeyDown(assignKeyboard[i]); } if (legacy != null) { Microsoft.DirectX.DirectInput.JoystickState legacystate = legacy.state; byte[] buttons = legacystate.GetButtons(); bState[(int)EDirection.up] = bState[(int)EDirection.up] || (legacystate.Y < -600); bState[(int)EDirection.down] = bState[(int)EDirection.down] || (legacystate.Y > 600); bState[(int)EDirection.left] = bState[(int)EDirection.left] || (legacystate.X < -600); bState[(int)EDirection.right] = bState[(int)EDirection.right] || (legacystate.X > 600); for (int i = (int)EDirection.__reserved; i < bState.Length; i++) { int nButtonID = assignLegacy[i - (int)EDirection.__reserved]; bState[i] = bState[i] || (buttons.Length > nButtonID && buttons[nButtonID] != 0); } } #else for (int i = 0; i < bState.Length; bState[i++] = false) { ; } #endif if (isUseXBOX360GamePad) { GamePadState stateButton = GamePad.GetState(PlayerIndex.One); Vector2 leftStick = stateButton.ThumbSticks.Left; if (leftStick.Length() > 0.7f) { double dAngle = Math.Atan2(leftStick.Y, leftStick.X); bState[(int)EDirection.up] = bState[(int)EDirection.up] || (dAngle <= MathHelper.PiOver4 * 3.5 && dAngle >= MathHelper.PiOver4 * 0.5); bState[(int)EDirection.down] = bState[(int)EDirection.down] || (dAngle >= MathHelper.PiOver4 * -3.5 && dAngle <= MathHelper.PiOver4 * -0.5); bState[(int)EDirection.left] = bState[(int)EDirection.left] || Math.Abs(dAngle) >= MathHelper.PiOver4 * 2.5; bState[(int)EDirection.right] = bState[(int)EDirection.right] || Math.Abs(dAngle) <= MathHelper.PiOver4 * 1.5; } else { bState[(int)EDirection.up] = bState[(int)EDirection.up] || stateButton.IsButtonDown(Buttons.DPadUp); bState[(int)EDirection.down] = bState[(int)EDirection.down] || stateButton.IsButtonDown(Buttons.DPadDown); bState[(int)EDirection.left] = bState[(int)EDirection.left] || stateButton.IsButtonDown(Buttons.DPadLeft); bState[(int)EDirection.right] = bState[(int)EDirection.right] || stateButton.IsButtonDown(Buttons.DPadRight); } for (int i = (int)EDirection.__reserved; i < bState.Length; i++) { bState[i] = bState[i] || stateButton.IsButtonDown(assignXBOX360[i - (int)EDirection.__reserved]); } } for (int i = 0; i < bState.Length; i++) { BUTTON_STATE[i].refresh(bState[i]); } } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Q)) { this.Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.M)) { warsContent.AddExplosion(1); warsContent.PlayExplosionSound(); } /* * Keys[] keys = Keyboard.GetState().GetPressedKeys(); * foreach(Keys key in keys) * { * Console.WriteLine("Key pressed: {0}", key); * } */ // The time since Update was called last. float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; addShipCounter -= elapsed; if (Keyboard.GetState().IsKeyDown(Keys.Y) && addShipCounter <= 0) { addShipCounter = 0.3f; warsContent.AddShip(random.Next(4)); } counter -= elapsed; if (counter <= 0) { counter = 3f; //Console.WriteLine("elapsed game time: {0}, elapsed real time: {1}", elapsed, (float)gameTime.ElapsedRealTime.TotalSeconds); if (warsContent.ships.Count == 1) { warsContent.AddShip(random.Next(4)); /* * for (int i = 0; i < 50; i++) * { * warsContent.AddShip(random.Next(4)); * } */ } //warsContent.AddShip(); //Console.WriteLine("Angle: {0}", MathHelper.ToDegrees(((Ship)warsContent.ships[0]).RotationAngle)); } // Joystick #if HAVE_LEGACY_DIRECTX try { // poll the joystick joystickDevice.Poll(); // update the joystick state field joystickState = joystickDevice.CurrentJoystickState; } catch (Exception err) { // we probably lost connection to the joystick // was it unplugged or locked by another application? Console.WriteLine(err.Message); } #endif // TODO: Add your update logic here foreach (Cat cat in warsContent.cats) { cat.RedShotSpacingCounter -= elapsed; } bool playerAbove1throttle = false; for (int player = 1; player <= warsContent.ships.Count; player++) { //Ship ship = (Ship)warsContent.ships[player]; Ship ship = warsContent.getPlayersShip(player); Commands com = warsControl.GetPlayerCommands(player, ref warsContent #if HAVE_LEGACY_DIRECTX , ref joystickState #endif ); if (com.left) { ship.RotationAngle += 4 * elapsed; //Console.WriteLine("RotationAngle: {0}", MathHelper.ToDegrees(ship.RotationAngle)); } if (com.right) { ship.RotationAngle -= 4 * elapsed; //Console.WriteLine("RotationAngle: {0}", MathHelper.ToDegrees(ship.RotationAngle)); } if (com.throttle) { // Sound if (player == 1) { warsContent.PlayEngineSound(player); } ship.Throttle = elapsed * ship.ThrottlePower; // NOTE NOTE NOTE TODO: Make dependent on time (elapsed) //Console.WriteLine("Ship speed: {0}", ship.Speed.ToString()); warsContent.AddFume(player); if (player > 1) { playerAbove1throttle = true; } } else { if (player == 1) { warsContent.PauseEngineSound(player); } ship.Throttle = 0; } ship.RedShotSpacingCounter -= elapsed; if (com.fire == 1) { if (ship.RedShotSpacingCounter <= 0) { ship.RedShotSpacingCounter = ship.RedShotSpacing; //Console.WriteLine("Shot!"); warsContent.AddShot(player); } if (player == 1) { foreach (Cat cat in warsContent.cats) { if (cat.RedShotSpacingCounter <= 0) { cat.RedShotSpacingCounter = cat.RedShotSpacing; warsContent.AddCatShot(player, cat); } } } } } if (playerAbove1throttle) { warsContent.PlayEngineSound(2); } else { warsContent.PauseEngineSound(2); } // if(Keyboard.GetState().IsKeyDown(Keys.S)) { // ship.Throttle -= 4 * elapsed; // } foreach (Cat cat in warsContent.cats) { cat.RotationAngle += 4 * elapsed; cat.PosRotationAngle -= 4 * elapsed; cat.Pos = warsContent.getPlayersShip(cat.Owner).Pos; //Vector2 goal = warsContent.getPlayersShip(cat.Owner).Pos + cat.PosRotationVector * cat.ShipDistance; cat.Pos += cat.PosRotationVector * cat.ShipDistance; //cat.Speed = goal; //cat.move(); } foreach (Ship ship in warsContent.ships) { ship.updateSpeed(); } for (int playerMinus1 = 0; playerMinus1 < warsContent.ships.Count; playerMinus1++) { if (playerMinus1 != 0) { warsContent.getPlayersShip(playerMinus1 + 1).move(); warsContent.getPlayersShip(playerMinus1 + 1).Pos -= warsContent.getPlayersShip(1).Speed; } } foreach (WarsObject obj in warsContent.planetObjects) { obj.Speed = -warsContent.getPlayersShip(1).Speed; obj.move(); } foreach (WarsObject obj in warsContent.bgObjects) { //obj.Speed = new Vector2(-ship.Speed.X, ship.Speed.Y); //obj.Speed = -((Ship)warsContent.ships[1]).Speed; obj.Speed = -warsContent.getPlayersShip(1).Speed; obj.move(); Vector2 newPos = obj.Pos; newPos.X = newPos.X % Constants.RESOLUTION_WIDTH; newPos.Y = newPos.Y % Constants.RESOLUTION_HEIGHT; if (newPos.X < 0) { newPos.X += Constants.RESOLUTION_WIDTH; } if (newPos.Y < 0) { newPos.Y += Constants.RESOLUTION_HEIGHT; } obj.Pos = newPos; } foreach (WarsObject obj in warsContent.fumeObjects) { obj.move(); //obj.Pos += new Vector2(-ship.Speed.X / Constants.FUME_SPEED_AFFECT_FACTOR, ship.Speed.Y / Constants.FUME_SPEED_AFFECT_FACTOR); //obj.Pos += new Vector2(-ship.Speed.X, ship.Speed.Y); //obj.Pos -= ((Ship)warsContent.ships[1]).Speed; obj.Pos -= warsContent.getPlayersShip(1).Speed; } for (int i = 0; i < warsContent.fumeObjects.Count; i++) { WarsObject obj = (WarsObject)warsContent.fumeObjects[i]; //newPos.X = newPos.X % Constants.RESOLUTION_WIDTH; //newPos.Y = newPos.Y % Constants.RESOLUTION_HEIGHT; if (obj.updateTTL(elapsed)) { warsContent.fumeObjects.RemoveAt(i); } else { if (obj.Pos.X < 0) { warsContent.fumeObjects.RemoveAt(i); } else if (obj.Pos.Y < 0) { warsContent.fumeObjects.RemoveAt(i); } } } // Shots foreach (WarsObject obj in warsContent.shotObjects) { obj.move(); //obj.Pos += new Vector2(-ship.Speed.X, ship.Speed.Y); //obj.Pos -= ((Ship)warsContent.ships[1]).Speed; obj.Pos -= warsContent.getPlayersShip(1).Speed; } for (int i = 0; i < warsContent.shotObjects.Count; i++) { WarsObject obj = (WarsObject)warsContent.shotObjects[i]; if (obj.updateTTL(elapsed)) { warsContent.shotObjects.RemoveAt(i); } } // Collision detection (player 1 shoots others) for (int playerIndexMinus1 = 1; playerIndexMinus1 < warsContent.ships.Count; playerIndexMinus1++) { Ship ship = warsContent.getPlayersShip(playerIndexMinus1 + 1); BoundingSphere shipSphere = new BoundingSphere(new Vector3(ship.Pos, 0), (float)ship.Texture.Width / 2f); for (int i = 0; i < warsContent.shotObjects.Count; i++) { WarsObject obj = (WarsObject)warsContent.shotObjects[i]; BoundingSphere shotSphere = new BoundingSphere(new Vector3(obj.Pos, 0), (float)warsContent.redShot.Height / 2f); if (shotSphere.Intersects(shipSphere)) { if (obj.Owner != playerIndexMinus1 + 1) { warsContent.AddExplosion(playerIndexMinus1 + 1); warsContent.PlayExplosionSound(); warsContent.shotObjects.RemoveAt(i); warsContent.ships.RemoveAt(playerIndexMinus1); whiteFlash = true; break; } } } } // Collision detection (player 1 gets shot) Ship ship1 = warsContent.getPlayersShip(1); BoundingSphere ship1Sphere = new BoundingSphere(new Vector3(ship1.Pos, 0), (float)ship1.Texture.Width / 2f); for (int i = 0; i < warsContent.shotObjects.Count; i++) { WarsObject obj = (WarsObject)warsContent.shotObjects[i]; BoundingSphere shotSphere = new BoundingSphere(new Vector3(obj.Pos, 0), (float)warsContent.redShot.Height / 2f); if (shotSphere.Intersects(ship1Sphere)) { if (obj.Owner != 1) { // warsContent.AddExplosion(1); // warsContent.PlayExplosionSound(); warsContent.shotObjects.RemoveAt(i); // warsContent.ships.RemoveAt(playerIndexMinus1); warsContent.PlayImHit(); break; } } } base.Update(gameTime); }
public abstract void FirstCheckState(ref Microsoft.DirectX.DirectInput.JoystickState controllerState);