public override void Update(GameTime gameTime) { player.Update(gameTime); mouse = Mouse.GetState(); map.Update(); foreach (CollisionTiles tile in map.CollisionTiles) { player.Collisions(tile.Rectangle); if (tile.Rectangle.Contains(new Point(mouse.X, mouse.Y)) && (mouse.LeftButton == ButtonState.Pressed)) { tile.isEnabled = false; } } foreach (Rectangle rct in map.Rectangles) { if (rct.Contains(new Point(mouse.X, mouse.Y)) && mouse.RightButton == ButtonState.Pressed) { map.AddBlock(new Point(rct.X, rct.Y), 1); } } base.Update(gameTime); }
public override void UpdateObjects(ContentManager content) { this.mouse = Mouse.GetState(); this.keyboard = Keyboard.GetState(); this.UpdateCursor(); if (this.keyboard.IsKeyDown(Keys.Enter) && this.previousKeyboard.IsKeyUp(Keys.Enter) && this.controlScreenItems.Count != 0) { if (this.controlScreenItems[this.selectedEntry].ItemText == "Back") { Rpg.PActiveWindow=EnumActiveWindow.MainMenu; } } if (this.mouse.LeftButton == ButtonState.Pressed) { foreach (var item in this.controlScreenItems) { if (this.mouse.X > item.ItemPosition.X && this.mouse.X < item.ItemPosition.X + item.ItemTexture.Bounds.Width && this.mouse.Y > item.ItemPosition.Y && this.mouse.Y < item.ItemPosition.Y + item.ItemTexture.Bounds.Height) { if (item.ItemText == "Back") { Rpg.PActiveWindow=EnumActiveWindow.MainMenu; break; } } } } this.previousKeyboard = this.keyboard; }
/// <summary> /// Реакция на изменения мыши /// </summary> /// <param name="state">The state.</param> public override void ChangeState(Microsoft.Xna.Framework.Input.MouseState state) { if (state.LeftButton != ButtonState.Pressed && state.RightButton != ButtonState.Pressed) { if (Rect.Contains(state.X, state.Y)) { _Texture.CurrentFrame = 0; } else if (!Selected) { _Texture.CurrentFrame = 2; } } if (state.LeftButton == ButtonState.Pressed && _LastMouseState.LeftButton == ButtonState.Released && Rect.Contains(state.X, state.Y)) { Chosen = true; if (OnValueChanged != null) { OnValueChanged(); } _Texture.CurrentFrame = 1; Selected = true; } _LastMouseState = state; }
//Update. Checks where the mouse is, and returns a Vector2 for the camera to move when mouse is close to borders. public Vector2 Update(int Width, int Height) { ms = Mouse.GetState(); Position = new Point(ms.X, ms.Y); Vector2 mousePosition = new Vector2(ms.X, ms.Y); Vector2 targetVector = Vector2.Zero; if (ms.X < Width / 10) { targetVector.X = -4; } else if (ms.X > Width - Width / 10) { targetVector.X = 4; } if (ms.Y < Height / 10) { targetVector.Y = -4; } else if (ms.Y > Height - Height / 10) { targetVector.Y = 4; } return targetVector; }
public override void Update(GameTime gameTime) { _previousMouseState = _currentMouseState; _currentMouseState = Mouse.GetState(); _previousBugBox = _bugBox; if (drawEnemyBug) { Position = new Point(Position.X, Position.Y); _bugBox = new Rectangle(this.Position.X, this.Position.Y, Drawable.Art.Width, Drawable.Art.Height); } if (!drawEnemyBug) { _bugBox = new Rectangle(-500, -500, Drawable.Art.Width, Drawable.Art.Height); Point newPoint = randomBugPlacement(); Position = newPoint; } doCollisionDetection(); base.Update(gameTime); }
public Input(MouseState cms, MouseState pms, KeyboardState cks, KeyboardState pks) { Pms = pms; Pks = pks; Cms = cms; Cks = cks; }
public override void Update(GameTime gameTime, Rectangle clientBounds) { currentFrame.X = 1; // Move the sprite according to the direction property position += direction; // If the mouse moved, set the position of the sprite to the mouse position MouseState currMouseState = Mouse.GetState(); if (currMouseState.X != prevMouseState.X || currMouseState.Y != prevMouseState.Y) { if (currMouseState.X > prevMouseState.X) currentFrame.X = 2; else if (currMouseState.X < prevMouseState.X) currentFrame.X = 0; position = new Vector2(currMouseState.X, currMouseState.Y); } prevMouseState = currMouseState; //Plane Movement if (Keyboard.GetState().IsKeyDown(Keys.Left)) currentFrame.X = 0; if (Keyboard.GetState().IsKeyDown(Keys.Right)) currentFrame.X = 2; // If the sprite is off the screen, put it back in play if (position.X < 0) position.X = 0; if (position.Y < 0) position.Y = 0; if (position.X > clientBounds.Width - frameSize.X) position.X = clientBounds.Width - frameSize.X; if (position.Y > clientBounds.Height - frameSize.Y) position.Y = clientBounds.Height - frameSize.Y; base.Update(gameTime, clientBounds); }
public void Update(Player player, KeyboardState keyboard, MouseState mouse, Engine engine) { // Rortational Origin Rectangle originRect = new Rectangle((int)position.X, (int)position.Y, (int)texture.Width, (int)texture.Height); origin = new Vector2(originRect.Width / 2, originRect.Height / 2); int viewDistance = 200; double distance = Math.Sqrt(Math.Pow(player.position.X - position.X, 2) + Math.Pow(player.position.Y - position.Y, 2)); if (distance < viewDistance) { float deltaX = player.position.X - position.X; float deltaY = player.position.Y - position.Y; float radians = (float)Math.Atan2(deltaY, deltaX); setRotation(radians); float zombieSpeed = 1.5f; float dx = (float) Math.Cos(rotation) * zombieSpeed; float dy = (float) Math.Sin(rotation) * zombieSpeed; position.X += dx; position.Y += dy; } }
public void Update() { MouseState state = Mouse.GetState(); if ((this.previousState.LeftButton == ButtonState.Released) && (state.LeftButton == ButtonState.Pressed)) { this.gestures.OnNext(new Gesture(GestureType.LeftButtonDown, new Point((double)state.X, (double)state.Y))); } else if ((this.previousState.LeftButton == ButtonState.Pressed) && (state.LeftButton == ButtonState.Released)) { this.gestures.OnNext(new Gesture(GestureType.LeftButtonUp, new Point((double)state.X, (double)state.Y))); } if ((state.X != this.previousState.X) || (state.Y != this.previousState.Y)) { this.gestures.OnNext(new Gesture(GestureType.Move, new Point((double)state.X, (double)state.Y))); } if ((this.previousState.LeftButton == ButtonState.Pressed) && (state.LeftButton == ButtonState.Pressed)) { this.gestures.OnNext(new Gesture(GestureType.FreeDrag, new Point((double)state.X, (double)state.Y), new Vector(state.X - previousState.X, state.Y - previousState.Y))); } this.previousState = state; while (TouchPanel.IsGestureAvailable) { GestureSample sample = TouchPanel.ReadGesture(); if (sample.GestureType == XnaGestureType.FreeDrag) { this.gestures.OnNext(new Gesture(GestureType.FreeDrag, new Point((double)sample.Position.X, (double)sample.Position.Y), new Vector((double)sample.Delta.X, (double)sample.Delta.Y))); } } }
// this constructor doesn't really do much of anything, just calls the base // constructor, and saves the contentmanager so it can be used in // LoadContent. public Cursor(Game game, ContentManager content) : base(game) { this.content = content; currentMouseState = Mouse.GetState(); previousMouseState = Mouse.GetState(); }
public void Update(KeyboardState keyboard, MouseState mouse, Engine engine) { // Rortational Origin Rectangle originRect = new Rectangle((int) position.X, (int) position.Y, (int) texture.Width, (int) texture.Height); origin = new Vector2(originRect.Width / 2, originRect.Height / 2); int playerSpeed = 2; if (keyboard.IsKeyDown(Keys.A)) position.X -= playerSpeed; if (keyboard.IsKeyDown(Keys.D)) position.X += playerSpeed; if (keyboard.IsKeyDown(Keys.W)) position.Y -= playerSpeed; if (keyboard.IsKeyDown(Keys.S)) position.Y += playerSpeed; float deltaY = mouse.Y - position.Y; float deltaX = mouse.X - position.X; float radians = (float) Math.Atan2(deltaY, deltaX); setRotation(radians); }
public cMenuOptionsWindowButton(GraphicsDeviceManager gd, ContentManager cm) { _instance = this; _graphics = gd; _contentManager = cm; mouseState = new MouseState(); _tabFont = cFontManager.Instance.getFont("Treb8"); _optionsbuttons = new List<cMenuButton>(); cSpriteManager.Instance.addTexture("Resources/Menu/optionswindowtab", "controls_tab"); _tcontrolsTab = new cMenuButton("controls_tab"); _tcontrolsTab.setOnClickListener(this); _tcontrolsTab.Position = new Vector2(800 / 5 + 62, 600 / 2 - 157); _optionsbuttons.Add(_tcontrolsTab); cSpriteManager.Instance.addTexture("Resources/Menu/optionswindowtab", "sound_tab"); _tsoundTab = new cMenuButton("sound_tab"); _tsoundTab.setOnClickListener(this); _tsoundTab.Position = new Vector2(800 / 5 + 132, 600 / 2 - 157); _optionsbuttons.Add(_tsoundTab); cSpriteManager.Instance.addTexture("Resources/Menu/optionswindowtab", "display_tab"); _tdisplayTab = new cMenuButton("display_tab"); _tdisplayTab.setOnClickListener(this); _tdisplayTab.Position = new Vector2(800 / 5 + 202, 600 / 2 - 157); _optionsbuttons.Add(_tdisplayTab); cSpriteManager.Instance.addTexture("Resources/Menu/optionswindowtab", "cancel_button"); _tcancelButton = new cMenuButton("cancel_button"); _tcancelButton.setOnClickListener(this); _tcancelButton.Position = new Vector2(_screenWidth - 231, _screenHeight / 2 + 183); _optionsbuttons.Add(_tcancelButton); }
public void Update(MouseState mouse) { if (Enabled == true) { rectangle = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y); Rectangle mouseRectangle = new Rectangle(mouse.X, mouse.Y, 1, 1); if (mouseRectangle.Intersects(rectangle)) { if (mouse.LeftButton == ButtonState.Pressed) { isClicked = true; isSelected = true; } } else { isClicked = false; } if (isSelected==true & isClicked==true) { Count(); } } wasSelected = isSelected; count++; }
public override void Update() { keyboard = Keyboard.GetState(); mouse = Mouse.GetState(); if (keyboard.IsKeyDown(Keys.W)) { position.Y -= speed; } if (keyboard.IsKeyDown(Keys.A)) { position.X -= speed; } if (keyboard.IsKeyDown(Keys.D)) { position.X += speed; } if (keyboard.IsKeyDown(Keys.S)) { position.Y += speed; } rotation = point_direction(position.X, position.Y, mouse.X,mouse.Y); prevKeyBoard = keyboard; prevMouse = mouse; base.Update(); }
public static void Update(MouseState mouse, KeyboardState keyboard) { MouseMoving(mouse); MouseClicking(mouse); DevInput(mouse, keyboard); }
public static void Update() { prevMouseState = mouseState; mouseState = Mouse.GetState(); prevKeyboardState = keyboardState; keyboardState = Keyboard.GetState(); }
public void Update() { currentMouseState = Mouse.GetState(); for (int i = 0; i < MenuItems.Length; i++) { if (MenuRectangles[i].Intersects(new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1))) MenuHover[i] = true; else MenuHover[i] = false; } if (lastMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released) { for (int i = 0; i < MenuItems.Length; i++) { if (MenuRectangles[i].Intersects(new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1))) { switch (i) { case 0: ClickEvent(this, new GameStateEventArgs(GameState.Lobby)); break; case 1: ClickEvent(this, new GameStateEventArgs(GameState.Options)); break; case 2: ClickEvent(this, new GameStateEventArgs(GameState.Credits)); break; case 3: Process.GetCurrentProcess().Kill(); break; } } } } lastMouseState = currentMouseState; }
public void kill(KeyboardState kb, MouseState ms) { stateTimer = 0.0f; state = State.EXIT; this.update(kb, ms); this.init(); }
/// <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) { previousKeyState = currentKeyState; currentKeyState = Keyboard.GetState(); previousMouseState = currentMouseState; currentMouseState = Mouse.GetState(); // Exit if (gameState == GameState.Quit || currentKeyState.IsKeyDown(Keys.Escape)) { Exit(); } if (gameState == GameState.TitleScreen) { titleScreen.Update(currentMouseState, previousMouseState, currentKeyState, previousKeyState); gameState = titleScreen.gameState; } else if (gameState == GameState.Game) { character.Update(currentMouseState, previousMouseState, currentKeyState, previousKeyState, gameTime, map); } base.Update(gameTime); }
public override void Update(GameTime gameTime) { mouseState = Mouse.GetState(); m_BackButton.Update(mouseState); m_HomeButton.Update(mouseState); }
public void Update() { oldkey = key; om = m; key = Keyboard.GetState(); m = Mouse.GetState(); }
public static void ClearState() { previousMouseState = Mouse.GetState(); currentMouseState = Mouse.GetState(); previousKeyState = Keyboard.GetState(); currentKeyState = Keyboard.GetState(); }
public override void Mouse(MouseState state, MouseState oldState) { var pos = CCDrawManager.ScreenToWorld(state.X, state.Y); Vector2 position = new Vector2(pos.X, pos.Y); if (state.RightButton == ButtonState.Pressed) { DrawCircleOnMap(position, -1); _terrain.RegenerateTerrain(); DebugView.BeginCustomDraw(); DebugView.DrawSolidCircle(position, _circleRadius, Vector2.UnitY, Color.Blue * 0.5f); DebugView.EndCustomDraw(); } if (state.LeftButton == ButtonState.Pressed) { DrawCircleOnMap(position, 1); _terrain.RegenerateTerrain(); DebugView.BeginCustomDraw(); DebugView.DrawSolidCircle(position, _circleRadius, Vector2.UnitY, Color.Red * 0.5f); DebugView.EndCustomDraw(); } if (state.MiddleButton == ButtonState.Pressed) { Body circle = BodyFactory.CreateCircle(World, 1, 1); circle.BodyType = BodyType.Dynamic; circle.Position = position; } }
public InputController() { m_DragArgs = new DragArgs(); m_LastMouseState = Mouse.GetState(); m_LastKeyboardState = Keyboard.GetState(); }
public override void Update(MouseState mouse) { foreach (Button button in Buttons) { button.Update(mouse); } }
internal override void Update(GameTime gameTime) { _gameTime = gameTime; _currentState = Mouse.GetState(); CheckButtonPressed(s => s.LeftButton, MouseButton.Left); CheckButtonPressed(s => s.MiddleButton, MouseButton.Middle); CheckButtonPressed(s => s.RightButton, MouseButton.Right); CheckButtonPressed(s => s.XButton1, MouseButton.XButton1); CheckButtonPressed(s => s.XButton2, MouseButton.XButton2); CheckButtonReleased(s => s.LeftButton, MouseButton.Left); CheckButtonReleased(s => s.MiddleButton, MouseButton.Middle); CheckButtonReleased(s => s.RightButton, MouseButton.Right); CheckButtonReleased(s => s.XButton1, MouseButton.XButton1); CheckButtonReleased(s => s.XButton2, MouseButton.XButton2); // Check for any sort of mouse movement. if (_previousState.X != _currentState.X || _previousState.Y != _currentState.Y) RaiseEvent(MouseMoved, new MouseEventArgs(gameTime.TotalGameTime, _previousState, _currentState)); // Handle mouse wheel events. if (_previousState.ScrollWheelValue != _currentState.ScrollWheelValue) RaiseEvent(MouseWheelMoved, new MouseEventArgs(gameTime.TotalGameTime, _previousState, _currentState)); _previousState = _currentState; }
protected override void handleInput(KeyboardState keyboard, MouseState mouse) { base.handleInput(keyboard, mouse); if (DisplayGraph) { if (keyboard.IsKeyDown(Keys.D0)) clearPathDisplay(); bool leftAlt = keyboard.IsKeyDown(Keys.LeftAlt); bool rightAlt = keyboard.IsKeyDown(Keys.RightAlt); if (leftAlt || rightAlt) { bool leftMouseButton = mouse.LeftButton == ButtonState.Pressed; if (leftMouseButton) { Vector2 mouseVec = AStarGame.MousePositionInWorld(); checkForClickedNode(mouseVec, leftAlt, rightAlt); updatePathDisplay(); } } } }
public void Update(MouseState mouse) { rectangle = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y); Rectangle mouseRect = new Rectangle(mouse.X, mouse.Y, 1, 1); if (mouseRect.Intersects(rectangle)) { if (color.A == 255) { down = false; } if (color.A == 0) { down = true; } if (down == true) { color.A += 3; } else { color.A -= 3; } if (mouse.LeftButton == ButtonState.Pressed) { isClicked = true; } } else if(color.A <255) { color.A += 3; isClicked = false; } }
public override void ChangeState(Microsoft.Xna.Framework.Input.MouseState state) { if (state.LeftButton != ButtonState.Pressed && state.RightButton != ButtonState.Pressed) { if (_Sprite.Contains(state.X, state.Y)) { _Sprite.CurrentFrame = 1; } else { _Sprite.CurrentFrame = 0; } } if (state.LeftButton == ButtonState.Pressed && _Sprite.Contains(state.X, state.Y) && _LastMouseState.LeftButton == ButtonState.Released) { _Sprite.CurrentFrame = 2; if (OnValueChanged != null) { OnValueChanged(); } float snd = 12 - _Game.SoundVolume(); if (snd != 12) { _Sound.Play(1 / snd, 0, 0); } } _LastMouseState = state; }
public void Update(GameTime gameTime) { state = Mouse.GetState(); CurrentPos = new Vector2(state.X, state.Y); rect.X = (int)CurrentPos.X; rect.Y = (int)CurrentPos.Y; }
//Update methode public static void Update() { oks = ks; oms = ms; ks = Keyboard.GetState(); ms = Mouse.GetState(); }
}//InputManger public void InputHandler(MouseState mst, GameTime gameTime) { if (!cG.IsActive) return; mousestatus = mst; HandleMouseLeftButton(gameTime); if (mssButtonLeft == MsState.ButtonWasPressed) { if (mousestatus.X >= 0 && mousestatus.X <= 405) { if (mousestatus.Y >= 209 && mousestatus.Y <= 250) { cG.Toggle(); }//if }//if }//if if (mssButtonLeft == MsState.ButtonWasPressed) { if (mousestatus.X >= 0 && mousestatus.X <= 628) { if (mousestatus.Y >= 304 && mousestatus.Y <= 350) { cG.CenterWindow(); }//if }//if }//if }//InputHandler
/// <summary> /// Реагируем на изменения в игре /// </summary> /// <param name="state">The state.</param> public override void ChangeState(Microsoft.Xna.Framework.Input.MouseState state) { _StartGame.ChangeState(state); foreach (PanelItem item in Items) { item.ChangeState(state); } }
public void Update(GameTime gameTime) { previousMouseState = currentMouseState; previousKeyboardState = currentKeyboardState; previousGamePadState = (GamePadState[])currentGamePadState.Clone(); //previousJoyState = currentJoyState; currentMouseState = Mouse.GetState(); currentKeyboardState = Keyboard.GetState(); foreach (PlayerIndex index in Enum.GetValues(typeof(PlayerIndex))) { currentGamePadState[(int)index] = GamePad.GetState(index); } if (RumbleDuration > 0) { GamePadVibration(PlayerIndex.One, leftMotor, rightMotor); rumbleDuration -= (float)gameTime.ElapsedGameTime.TotalSeconds; } if (!currentGamePadState[0].IsConnected && enableControllers && joystick == null) { JoystickPing -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (JoystickPing < 0) { JoystickPing = JoystickPingDuration; var th = new Thread(GenericControllerConnection); th.Start(); #if DEBUG Console.WriteLine("A new thread has been created!"); #endif } } else if (joystick != null && enableControllers) { joystick.Poll(); #if DEBUG Console.WriteLine("Polling Joystick..."); #endif try { JoystickState state = joystick.GetCurrentState(); currentJoyState = joystick.GetCurrentState(); bool[] button = state.Buttons; int[] hats = state.PointOfViewControllers; Console.WriteLine("[{0}]", string.Join(", ", hats)); } catch (Exception) { #if DEBUG Console.WriteLine("Oops, the controller disconnected!"); #endif joystick = null; } } }
/// <summary> /// /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { float thumb = 0f; float newpos = this.mPosition.X; // Check Mouse Microsoft.Xna.Framework.Input.MouseState st = Mouse.GetState(); if (st.LeftButton == ButtonState.Pressed) { newpos = st.X; } // Check Input if ((thumb = Input.XInputHelper.GamePads[PlayerIndex.One].ThumbStickLeftX) != 0f) { newpos += this.mSpeed * thumb; } else if ((thumb = Input.XInputHelper.GamePads[PlayerIndex.One].ThumbStickRightX) != 0f) { newpos -= this.mSpeed * thumb; } else if (Input.XInputHelper.GamePads[PlayerIndex.One].LeftPressedContinous) { newpos -= this.mSpeed; } else if (Input.XInputHelper.GamePads[PlayerIndex.One].RightPressedContinous) { newpos += this.mSpeed; } // Apply frame limits if (newpos < mGame.mGameRectangle.X) { newpos = mGame.mGameRectangle.X; } int limMax = mGame.mGameRectangle.X + mGame.mGameRectangle.Width - (int)this.mWidth; if (newpos > limMax) { newpos = limMax; } mPosition.X = newpos; // Refresh drawingRect mDrawingRectangle = new Rectangle((int)mPosition.X, (int)mPosition.Y, (int)mWidth, (int)((float)cHeight * XNArkanoidGame.mScreenHeightMultiplier)); // Update Shots this.UpdateShots(gameTime); base.Update(gameTime); }
public MouseState(GameState state, Microsoft.Xna.Framework.Input.MouseState mouse) { this.state = state; this.mouse = mouse; this.leftPressed = new Lazy <bool>(() => this.state != null && this.state.Mouse.LeftButton == ButtonState.Released && this.mouse.LeftButton == ButtonState.Pressed); this.leftReleased = new Lazy <bool>(() => this.state != null && this.state.Mouse.LeftButton == ButtonState.Pressed && this.mouse.LeftButton == ButtonState.Released); this.middlePressed = new Lazy <bool>(() => this.state != null && this.state.Mouse.MiddleButton == ButtonState.Released && this.mouse.MiddleButton == ButtonState.Pressed); this.middleReleased = new Lazy <bool>(() => this.state != null && this.state.Mouse.MiddleButton == ButtonState.Pressed && this.mouse.MiddleButton == ButtonState.Released); this.rightPressed = new Lazy <bool>(() => this.state != null && this.state.Mouse.RightButton == ButtonState.Released && this.mouse.RightButton == ButtonState.Pressed); this.rightReleased = new Lazy <bool>(() => this.state != null && this.state.Mouse.RightButton == ButtonState.Pressed && this.mouse.RightButton == ButtonState.Released); }
public override void Update(GameTime gameTime) { if (this.EnableUpdate) { base.Update(gameTime); base.Game.IsMouseVisible = false; this.previousMouseState = this.mouseState; this.mouseState = Mouse.GetState(); this.keyState = Keyboard.GetState(); this.GenerateEarlyMouseEvent(); this.RefreshEnables(); } }
/// <summary> /// Реакция на изменения мыши /// </summary> /// <param name="state">The state.</param> public override void ChangeState(Microsoft.Xna.Framework.Input.MouseState state) { if (state.LeftButton != ButtonState.Pressed && state.RightButton != ButtonState.Pressed) { if (_Plus.Contains(state.X, state.Y)) { _Plus.CurrentFrame = 1; } else { _Plus.CurrentFrame = 0; } if (_Minus.Contains(state.X, state.Y)) { _Minus.CurrentFrame = 1; } else { _Minus.CurrentFrame = 0; } } if (state.LeftButton == ButtonState.Pressed && _LastMouseState.LeftButton == ButtonState.Released) { if (_Plus.Contains(state.X, state.Y) && (_Lent.CurrentFrame != 11)) { _Lent.Update(); PlaySound(); if (OnValueChanged != null) { OnValueChanged(); } } if (_Minus.Contains(state.X, state.Y) && (_Lent.CurrentFrame != 0)) { --_Lent.CurrentFrame; PlaySound(); if (OnValueChanged != null) { OnValueChanged(); } } } _LastMouseState = state; }
private void UpdateMouse() { if (previousMouseState == null) { previousMouseState = XnaInput.Mouse.GetState(); return; } XnaInput.MouseState mouseState = XnaInput.Mouse.GetState(); if (previousMouseState.X == mouseState.X && previousMouseState.Y == mouseState.Y) { return; } previousMouseState = mouseState; ViewPositionConsole.Position = new Point(mouseState.X, mouseState.Y); RealPositionConsole.Position = ViewPositionConsole.Position.PixelLocationToConsole(Font); }
public void Update(GameTime time) { renderer.Update(time); XI.MouseState mstate = XI.Mouse.GetState(); camera.ChaseDirection = new Vector3((float)Math.Cos(xang), -(float)Math.Sin(yang), (float)Math.Sin(xang)); camera.DesiredPositionOffset = new Vector3(0, 0, distance); distance -= 0.05f * (mstate.ScrollWheelValue - lastState.ScrollWheelValue); if (mstate.RightButton == XI.ButtonState.Pressed) { xang += MathEx.Degree2Radian(mstate.X - lastState.X) * 0.5f; yang += MathEx.Degree2Radian(mstate.Y - lastState.Y) * 0.5f; } else if (mstate.LeftButton == XI.ButtonState.Pressed) { //obj.Orientation *= Matrix.RotationY(MathEx.Degree2Radian(mstate.X - lastState.X) * 0.5f); } lastState = mstate; }
public override void Update(Microsoft.Xna.Framework.Input.MouseState ms) { MousePosition = new Location() { Screen = new Vector2() { X = ms.X, Y = ms.Y } }; Location Location = new Location() { Grid = new Vector2(MousePosition.Grid.X, MousePosition.Grid.Y) }; Bounds = new Area() { World = new Rectangle((int)Location.World.X, (int)Location.World.Y, (int)Location.World.X + Constants.TileSize, (int)Location.World.Y + Constants.TileSize) }; base.Update(ms); }
public void UpdateControls() { this.mouseState = Mouse.GetState(Program.MainView.Window); this.keyboardState = Keyboard.GetState(); if (this.mouseState.Position != this.oldMouseState.Position) { cancelUnselectedBone = true; } if (this.mouseState.LeftButton == ButtonState.Pressed) { if (this.oldMouseState.LeftButton == ButtonState.Released) { if (this.HighlightedBone) { if (selectedBone != this.HighlightedBoneParentID) { SelectBone(this.HighlightedBoneParentID); } } else { cancelUnselectedBone = false; } } } else if (!cancelUnselectedBone) { SelectBone(-1); } if (keyboardState.IsKeyDown(Keys.Left)) { if (leftKeyCount == 0) { leftKeyCount = 1; } } else { leftKeyCount = 0; } if (keyboardState.IsKeyDown(Keys.Right)) { if (rightKeyCount == 0) { rightKeyCount = 1; } } else { rightKeyCount = 0; } if (leftKeyCount == 1 || leftKeyCount > 20) { View.focusedObject.Skeleton.SelectBone(View.focusedObject.Skeleton.SelectedBone.ID - 1); } if (rightKeyCount == 1 || rightKeyCount > 20) { View.focusedObject.Skeleton.SelectBone(View.focusedObject.Skeleton.SelectedBone.ID + 1); } if (leftKeyCount > 0) { leftKeyCount++; } if (rightKeyCount > 0) { rightKeyCount++; } this.oldKeyboardState = keyboardState; this.oldMouseState = mouseState; }
void UpdateMouse() { this.mouseState = Mouse.GetState(Program.MainView.Window); this.keyboardState = Keyboard.GetState(); if (View.Controls.keyboardState.IsKeyDown(Keys.LeftShift)) { return; } if (View.Controls.MouseDragState == 0) { dragInstance = -1; } if (dragInstance > -1) { if (this.ID != dragInstance) { this.Highlight = false; return; } } Vector2 centre = Object3D.GetOrtho(this.position); double xDiff = mouseState.X - centre.X; double yDiff = mouseState.Y - centre.Y; Vector2 angle0 = Object3D.GetOrtho(this.position + Vector3.Transform(new Vector3(this.rayon, 0, 0), this.Matrice)); Vector2 anglePIsur2 = Object3D.GetOrtho(this.position + Vector3.Transform(new Vector3(0, this.rayon, 0), this.Matrice)); if (angle0.X < centre.X) { xDiff = -xDiff; } if (anglePIsur2.Y < centre.Y) { yDiff = -yDiff; } double hypo = Math.Pow(xDiff * xDiff + yDiff * yDiff, 0.5); float angleMouse = (float)Math.Atan2(yDiff / hypo, xDiff / hypo); Object3D.MesurePositive(ref angleMouse); double smallest = Single.MaxValue; double realAngleMouse = 0; int smallestI = 0; for (int i = 0; i < 100; i++) { double angle = (i / 100d) * Math.PI * 2; Vector2 posOrtho = Object3D.GetOrtho(this.position + Vector3.Transform(new Vector3((float)(this.rayon * Math.Cos(angle)), (float)(this.rayon * Math.Sin(angle)), 0), this.Matrice)); double xDiffSeek = posOrtho.X - centre.X; double yDiffSeek = posOrtho.Y - centre.Y; if (angle0.X < centre.X) { xDiffSeek = -xDiffSeek; } if (anglePIsur2.Y < centre.Y) { yDiffSeek = -yDiffSeek; } double hypoSeek = Math.Pow(xDiffSeek * xDiffSeek + yDiffSeek * yDiffSeek, 0.5); float angleOrtho = (float)Math.Atan2(yDiffSeek / hypoSeek, xDiffSeek / hypoSeek); Object3D.MesurePositive(ref angleOrtho); double diff = Math.Abs(angleOrtho - angleMouse); if (diff < smallest) { realAngleMouse = angle; smallest = diff; smallestI = i; } } Vector2 posRayonOrthoAtMouseAngle = Object3D.GetOrtho(this.position + Vector3.Transform(new Vector3((float)(this.rayon * Math.Cos(realAngleMouse)), (float)(this.rayon * Math.Sin(realAngleMouse)), 0), this.Matrice)); xDiff = posRayonOrthoAtMouseAngle.X - centre.X; yDiff = posRayonOrthoAtMouseAngle.Y - centre.Y; if (angle0.X < centre.X) { xDiff = -xDiff; } if (anglePIsur2.Y < centre.Y) { yDiff = -yDiff; } double hypo2 = Math.Pow(xDiff * xDiff + yDiff * yDiff, 0.5); bool highlight = View.Controls.keyboardState.IsKeyUp(Keys.LeftShift) && Math.Abs(hypo - hypo2) <= hypo2 * 0.1f; if (highlight) { dragInstance = this.ID; } this.Highlight = View.Controls.MouseDragState > 0; if (View.Controls.mouseState.LeftButton == ButtonState.Released && View.Controls.MouseDragState == 2) { this.Release?.Invoke(null, null); this.endAngle = 0; this.startAngle = 0; View.Controls.MouseDragState = 0; } if (highlight) { if (View.Controls.MouseDragState == 0 && View.Controls.mouseState.LeftButton == ButtonState.Released) { View.Controls.MouseDragState = 1; } if (View.Controls.mouseState.LeftButton == ButtonState.Pressed) { if (View.Controls.MouseDragState == 1) { this.endAngle = (float)realAngleMouse; this.startAngle = (float)realAngleMouse; View.Controls.MouseDragState = 2; } } else { View.Controls.MouseDragState = 1; } } else { if (View.Controls.MouseDragState == 1) { View.Controls.MouseDragState = 0; } } if (View.Controls.MouseDragState == 2) { this.endAngle = (float)realAngleMouse; float start = this.startAngle; float end = this.endAngle; float val = end - start; this.ValueChanged?.Invoke(val, null); } oldKeyboardState = keyboardState; oldMouseState = mouseState; }
private static void UpdateMouseEvents(GameTime gameTime) { MouseState current = Mouse.GetState(); // Check button press. if (current.LeftButton == ButtonState.Pressed && _previousMouseState.LeftButton == ButtonState.Released) { RaiseMouseDownEvent(MouseButton.Left, current.X, current.Y); } if (current.MiddleButton == ButtonState.Pressed && _previousMouseState.MiddleButton == ButtonState.Released) { RaiseMouseDownEvent(MouseButton.Middle, current.X, current.Y); } if (current.RightButton == ButtonState.Pressed && _previousMouseState.RightButton == ButtonState.Released) { RaiseMouseDownEvent(MouseButton.Right, current.X, current.Y); } if (current.XButton1 == ButtonState.Pressed && _previousMouseState.XButton1 == ButtonState.Released) { RaiseMouseDownEvent(MouseButton.X1, current.X, current.Y); } if (current.XButton2 == ButtonState.Pressed && _previousMouseState.XButton2 == ButtonState.Released) { RaiseMouseDownEvent(MouseButton.X2, current.X, current.Y); } // Check button releases. if (current.LeftButton == ButtonState.Released && _previousMouseState.LeftButton == ButtonState.Pressed) { RaiseMouseUpEvent(MouseButton.Left, current.X, current.Y); } if (current.MiddleButton == ButtonState.Released && _previousMouseState.MiddleButton == ButtonState.Pressed) { RaiseMouseUpEvent(MouseButton.Middle, current.X, current.Y); } if (current.RightButton == ButtonState.Released && _previousMouseState.RightButton == ButtonState.Pressed) { RaiseMouseUpEvent(MouseButton.Right, current.X, current.Y); } if (current.XButton1 == ButtonState.Released && _previousMouseState.XButton1 == ButtonState.Pressed) { RaiseMouseUpEvent(MouseButton.X1, current.X, current.Y); } if (current.XButton2 == ButtonState.Released && _previousMouseState.XButton2 == ButtonState.Pressed) { RaiseMouseUpEvent(MouseButton.X2, current.X, current.Y); } // Whether ANY button is pressed. bool buttonDown = current.LeftButton == ButtonState.Pressed || current.MiddleButton == ButtonState.Pressed || current.RightButton == ButtonState.Pressed || current.XButton1 == ButtonState.Pressed || current.XButton2 == ButtonState.Pressed; // Check for any sort of mouse movement. If a button is down, it's a drag, // otherwise it's a move. if (_previousMouseState.X != current.X || _previousMouseState.Y != current.Y) { RaiseMouseMoveEvent(current.X, current.Y); } // Handle mouse wheel events. if (_previousMouseState.ScrollWheelValue != current.ScrollWheelValue) { RaiseMouseScrollEvent(current.X, current.Y, current.ScrollWheelValue); } _previousMouseState = current; }
public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Microsoft.Xna.Framework.Input.KeyboardState keyboard, Microsoft.Xna.Framework.Input.MouseState mouse) { float dt = (float)gameTime.ElapsedGameTime.TotalSeconds; introTime += dt; pointerDimensions.Location = new Point(mouse.X, mouse.Y); shipRotation = Matrix.CreateRotationY(MathHelper.PiOver4 * introTime); Manager.Update(gameTime, mouse); }
public MouseSnapshot(Microsoft.Xna.Framework.Input.MouseState last) { _last = last; _current = Mouse.GetState(); }
public static void Update() { CurrentState = Mouse.GetState(); _mousePosition = Mouse.GetState().Position.ToVector2(); }
public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Microsoft.Xna.Framework.Input.KeyboardState keyboard, Microsoft.Xna.Framework.Input.MouseState mouse) { if (findingNetwork) { if (introTime > 8.1f) { introTime -= (float)gameTime.ElapsedGameTime.TotalSeconds * 4; } networkTime -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (networkTime < lastNetTime) { lastNetTime--; Network.FindServer(); if (Network.IsConnected) { Login(); } } if (networkTime <= 0) { findingNetwork = false; lastNetTime = 10; netFailString = "No Network Found."; } } else { introTime += (float)gameTime.ElapsedGameTime.TotalSeconds; if (networkTime < 10) { networkTime += (float)gameTime.ElapsedGameTime.TotalSeconds * 2; } } if (introTime < 0 && introTime > -1) { MobileFortressClient.Game.Exit(); } if (introTime > 8) { Manager.Update(gameTime, mouse); if (keyboard.IsKeyDown(Keys.Enter)) { if (!loginMenuScroll) { loginButton.DoClick(); } else { loginConfirmButton.DoClick(); } } } else { if (keyboard.IsKeyDown(Keys.Escape) || keyboard.IsKeyDown(Keys.Enter)) { introTime = 8; } } Viewport viewport = MobileFortressClient.Game.GraphicsDevice.Viewport; if (loginMenuScroll) { Color disabledColor = new Color(96, 64, 64); loginButton.canClick = false; loginButton.color = Color.Lerp(loginButton.color, disabledColor, 0.3f); optionsButton.canClick = false; optionsButton.color = Color.Lerp(optionsButton.color, disabledColor, 0.3f); exitButton.canClick = false; exitButton.color = Color.Lerp(exitButton.color, disabledColor, 0.3f); if (scrolledAmt < loginMenu.Height) { foreach (UIElement element in Manager.Elements) { element.dimensions.Y -= 4; } scrolledAmt += 4; } loginDimensions.Y = viewport.Height - scrolledAmt; } else { loginButton.canClick = true; loginButton.color = Color.Lerp(loginButton.color, Color.LightGray, 0.3f); optionsButton.canClick = true; optionsButton.color = Color.Lerp(optionsButton.color, Color.LightGray, 0.3f); exitButton.canClick = true; exitButton.color = Color.Lerp(exitButton.color, Color.LightGray, 0.3f); if (scrolledAmt > 0) { foreach (UIElement element in Manager.Elements) { element.dimensions.Y += 4; } scrolledAmt -= 4; } loginDimensions.Y = viewport.Height - scrolledAmt; } }
public void UpdateMouse() { mouseState = Mouse.GetState(Program.MainView.Window); keyboardState = Keyboard.GetState(); if (mouseState.LeftButton == ButtonState.Pressed) { } else if (oldMouseState.LeftButton == ButtonState.Pressed) { this.cmbX.Highlight = false; this.cmbY.Highlight = false; this.cmbZ.Highlight = false; } if (keyboardState.IsKeyDown(Keys.LeftShift)) { if (middleButtonPress > 0) { middleButtonPress++; } if (middleButtonPress < 0) { middleButtonPress--; } if (mouseState.MiddleButton == ButtonState.Pressed) { if (middleButtonPress < 0) { for (int i = 0; i < View.focusedObject.Skeleton.Bones.Length; i++) { View.focusedObject.Skeleton.Bones[i].RotateX_Addition = 0; View.focusedObject.Skeleton.Bones[i].RotateY_Addition = 0; View.focusedObject.Skeleton.Bones[i].RotateZ_Addition = 0; } middleButtonPress = 0; } if (middleButtonPress == 0) { middleButtonPress = 1; } } else { if (middleButtonPress > 0 && middleButtonPress < 8) { middleButtonPress = -1; } if (middleButtonPress > 0 || middleButtonPress < -8) { middleButtonPress = 0; } } if (middleButtonPress > 0) { View.focusedObject.Skeleton.SelectedBone.RotateX_Addition = 0; View.focusedObject.Skeleton.SelectedBone.RotateY_Addition = 0; View.focusedObject.Skeleton.SelectedBone.RotateZ_Addition = 0; } if (mouseState.LeftButton == ButtonState.Pressed) { int xDiff = (mouseState.Position.X - oldMouseState.X); int yDiff = (mouseState.Position.Y - oldMouseState.Y); this.cmbX.Highlight = xDiff != 0; this.cmbY.Highlight = yDiff != 0; View.focusedObject.Skeleton.SelectedBone.RotateX_Addition += xDiff / 100f; View.focusedObject.Skeleton.SelectedBone.RotateY_Addition += yDiff / 100f; } if (mouseState.RightButton == ButtonState.Pressed) { int zDiff = (mouseState.Position.Y - oldMouseState.Y); this.cmbZ.Highlight = zDiff != 0; View.focusedObject.Skeleton.SelectedBone.RotateZ_Addition += zDiff / 100f; } } else if (oldKeyboardState.IsKeyDown(Keys.LeftShift)) { this.cmbX.Highlight = false; this.cmbY.Highlight = false; this.cmbZ.Highlight = false; } oldKeyboardState = keyboardState; oldMouseState = mouseState; }
protected override void MouseExit(Microsoft.Xna.Framework.Input.MouseState mouse) { return; }
/// <summary> /// /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { // Check Mouse Microsoft.Xna.Framework.Input.MouseState st = Mouse.GetState(); foreach (UIControl ctrl in mControls) { int rectEndX = (int)ctrl.Pos.X + (int)ctrl.Size.X; int rectEndY = (int)ctrl.Pos.Y + (int)ctrl.Size.Y; if (st.X < ctrl.Pos.X || st.X > rectEndX || st.Y < ctrl.Pos.Y || st.Y > rectEndY) { continue; } if (st.LeftButton == ButtonState.Pressed) { int idx = mControls.IndexOf(ctrl); if (idx == FocusIdx) { Sound.Sound.Play(eSounds.menu_advance); ControlSelected(ctrl, this.mControls.IndexOf(ctrl)); } else { Sound.Sound.Play(eSounds.menu_select2); this.FocusIdx = this.mControls.IndexOf(ctrl); } } } // Check Gamepads if (Input.XInputHelper.GamePads[PlayerIndex.One].DownPressed || Input.XInputHelper.GamePads[PlayerIndex.One].LeftThumbStick_Down) { Sound.Sound.Play(eSounds.menu_select2); this.FocusIdx++; } else if (Input.XInputHelper.GamePads[PlayerIndex.One].UpPressed || Input.XInputHelper.GamePads[PlayerIndex.One].LeftThumbStick_Up) { Sound.Sound.Play(eSounds.menu_select2); this.FocusIdx--; } else if (Input.XInputHelper.GamePads[PlayerIndex.One].StartPressed || Input.XInputHelper.GamePads[PlayerIndex.One].APressed) { Sound.Sound.Play(eSounds.menu_advance); if (ControlSelected != null) { ControlSelected(this.mControls[this.mFocusIdx], this.mFocusIdx); } } foreach (UIControl ctrl in mControls) { ctrl.Update(gameTime); } base.Update(gameTime); }
private static void update_control_scheme( KeyboardState keyState, GamePadState controllerState) { // Force updating icons/etc if (GameActive && ShouldSwitchControlScheme) { ControlSchemeSwitched = true; ShouldSwitchControlScheme = false; } if (!GameActive) { LastMouseState = new Microsoft.Xna.Framework.Input.MouseState( LastMouseState.X, LastMouseState.Y, LastMouseState.ScrollWheelValue, ButtonState.Pressed, ButtonState.Pressed, ButtonState.Pressed, ButtonState.Pressed, ButtonState.Pressed); } // If the player pressed buttons, we want to disable mouse control // Otherwise, if the player moves the mouse, enable mouse control if (ControlScheme != ControlSchemes.Buttons) { bool buttons_pressed = controller_pressed(controllerState); if (buttons_pressed) { ControlScheme = ControlSchemes.Buttons; return; } } if (ControlScheme == ControlSchemes.Mouse) { if (other_pressed(new HashSet <Inputs> { Inputs.A, Inputs.B, Inputs.Y, Inputs.X, Inputs.L, Inputs.R, Inputs.Start, Inputs.Select })) { ControlScheme = ControlSchemes.Buttons; return; } } else { //else if (MouseState.X != LastMouseState.X || MouseState.Y != LastMouseState.Y) //Debug if (any_mouse_triggered && mouseOnscreen) { ControlScheme = ControlSchemes.Mouse; ControlSchemeSwitched = true; // Cancel clicks for this mouse state, since we just took control of the game LastMouseState = new Microsoft.Xna.Framework.Input.MouseState( LastMouseState.X, LastMouseState.Y, LastMouseState.ScrollWheelValue, ButtonState.Pressed, ButtonState.Pressed, ButtonState.Pressed, ButtonState.Pressed, ButtonState.Pressed); } } #if __MOBILE__ || TOUCH_EMULATION if (ControlScheme == ControlSchemes.Touch) { if (key_pressed(keyState)) { ControlScheme = ControlSchemes.Buttons; ControlSchemeSwitched = true; } } #if !CONTROL_MOUSE_WITH_TOUCH else { if ((_touchCollection.Count != 0 || Gestures.Count != 0) && !key_pressed(keyState)) { ControlScheme = ControlSchemes.Touch; ControlSchemeSwitched = true; } } #endif #endif }
public static void Update(GameTime time) { IsMouseUpLeft = false; IsMouseUpRight = false; IsMouseUpMiddle = false; IsMouseDownLeft = false; IsMouseDownRight = false; oldState = currentState; OldScrollWheelValue = ScrollWheelValue; currentState = XI.Mouse.GetState(); wheel.Add(currentState.ScrollWheelValue); ScrollWheelValue = wheel.Result; if (currentState.LeftButton == XI.ButtonState.Pressed && oldState.LeftButton == XI.ButtonState.Released) { if (MouseDown != null) { MouseDown(MouseButtonFlags.Left, currentState.X, currentState.Y); } IsMouseDownLeft = true; } if (currentState.MiddleButton == XI.ButtonState.Pressed && oldState.MiddleButton == XI.ButtonState.Released) { if (MouseDown != null) { MouseDown(MouseButtonFlags.Middle, currentState.X, currentState.Y); } } if (currentState.RightButton == XI.ButtonState.Pressed && oldState.RightButton == XI.ButtonState.Released) { if (MouseDown != null) { MouseDown(MouseButtonFlags.Right, currentState.X, currentState.Y); } IsMouseDownRight = true; } if (currentState.LeftButton == XI.ButtonState.Released && oldState.LeftButton == XI.ButtonState.Pressed) { if (MouseUp != null) { MouseUp(MouseButtonFlags.Left, currentState.X, currentState.Y); } IsMouseUpLeft = true; } if (currentState.MiddleButton == XI.ButtonState.Released && oldState.MiddleButton == XI.ButtonState.Pressed) { if (MouseUp != null) { MouseUp(MouseButtonFlags.Middle, currentState.X, currentState.Y); } IsMouseUpMiddle = true; } if (currentState.RightButton == XI.ButtonState.Released && oldState.RightButton == XI.ButtonState.Pressed) { if (MouseUp != null) { MouseUp(MouseButtonFlags.Right, currentState.X, currentState.Y); } IsMouseUpRight = true; } }
public void UpdateMouse(GameTime gameTime, bool isWindowActive) { this.totalGameTime = gameTime.TotalGameTime; if (this.ConsumedButtons.Count > 0) { this.ConsumedButtons.Clear(); } this.ConsumedDeltaWheel = 0; MouseState mouseState; if (isWindowActive) { mouseState = Microsoft.Xna.Framework.Input.Mouse.GetState(); } else { // don't read input if the game window is not focused mouseState = new MouseState( this.previousMouseState.X, this.previousMouseState.Y, this.previousMouseState.ScrollWheelValue, leftButton: ButtonState.Released, rightButton: ButtonState.Released, middleButton: ButtonState.Released, xButton1: ButtonState.Released, xButton2: ButtonState.Released); } var x = mouseState.X; var y = mouseState.Y; var scrollWheelValue = mouseState.ScrollWheelValue; if (this.lastX != x || this.lastY != y || this.isLastFrameWasScrolled) { this.view.MouseMove(x, y); this.lastX = x; this.lastY = y; this.isLastFrameWasScrolled = false; } if (this.lastScrollWheelValue != scrollWheelValue) { if (this.IsAnyControlUnderMouseCursor()) { var scrollDeltaValue = scrollWheelValue - this.lastScrollWheelValue; this.view.MouseWheel(x, y, scrollDeltaValue); this.ConsumedDeltaWheel = scrollDeltaValue; // on the next frame it's required to update NoesisGUI mouse position // (on the current frame it's doesn't give required affect) this.isLastFrameWasScrolled = true; } else { this.ConsumedDeltaWheel = 0; } this.lastScrollWheelValue = scrollWheelValue; } else { this.ConsumedDeltaWheel = 0; } this.ProcessMouseButtonDown(MouseButton.Left, mouseState.LeftButton, this.previousMouseState.LeftButton); this.ProcessMouseButtonDown(MouseButton.Right, mouseState.RightButton, this.previousMouseState.RightButton); this.ProcessMouseButtonDown( MouseButton.Middle, mouseState.MiddleButton, this.previousMouseState.MiddleButton); this.ProcessMouseButtonUp(MouseButton.Left, mouseState.LeftButton, this.previousMouseState.LeftButton); this.ProcessMouseButtonUp(MouseButton.Right, mouseState.RightButton, this.previousMouseState.RightButton); this.ProcessMouseButtonUp( MouseButton.Middle, mouseState.MiddleButton, this.previousMouseState.MiddleButton); this.previousMouseState = mouseState; }
public static void MouseControls(GameWindow win) { mouseState = Mouse.GetState(win); keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.S) && !oldKeyboardState.IsKeyDown(Keys.S)) { mainCamera.Animated = !mainCamera.Animated; if (mainCamera.Animated) { mainCamera.RotationX = 0; mainCamera.RotationY = 0; } } if (keyboardState.IsKeyDown(Keys.T) && !oldKeyboardState.IsKeyDown(Keys.T)) { View.AllowTextures = !View.AllowTextures; } if (keyboardState.IsKeyDown(Keys.I) && !oldKeyboardState.IsKeyDown(Keys.I)) { focusedObject.Skeleton.ShowIndices = !focusedObject.Skeleton.ShowIndices; } if (keyboardState.IsKeyDown(Keys.Enter) && !oldKeyboardState.IsKeyDown(Keys.Enter)) { if (focusedObject is MDLX) { MDLX mdl = focusedObject as MDLX; if (!Directory.Exists(View.GetCurrentDirectory() + @"\" + Path.GetFileNameWithoutExtension(mdl.FileName).ToUpper() + "-export")) { Directory.CreateDirectory(View.GetCurrentDirectory() + @"\" + Path.GetFileNameWithoutExtension(mdl.FileName).ToUpper() + "-export"); } mdl.ExportDAE(View.GetCurrentDirectory() + @"\" + Path.GetFileNameWithoutExtension(mdl.FileName).ToUpper() + @"-export\" + Path.GetFileNameWithoutExtension(mdl.FileName).ToUpper() + ".dae"); } } int wheelVal = mouseState.ScrollWheelValue; int oldWheelVal = oldMouseState.ScrollWheelValue; bool allowCameraRotation = MouseDragState == 0 && !View.focusedObject.Skeleton.HighlightedBone && keyboardState.IsKeyUp(Keys.LeftShift); bool allowCameraTranslation = MouseDragState == 0 && keyboardState.IsKeyUp(Keys.LeftShift); bool allowCameraZoom = MouseDragState == 0 && keyboardState.IsKeyUp(Keys.LeftShift); if (allowCameraZoom) { float step = focusedObject.Zoom / 10f; if (wheelVal < oldWheelVal) { mainCamera.ZoomTarget += step; } else if (wheelVal > oldWheelVal) { mainCamera.ZoomTarget -= step; } if (mouseState.MiddleButton == ButtonState.Pressed) { ResetCamToTarget(); } } ShowLookAt = false; float factor = mainCamera.Animated ? 0.3333f : 1; float diffY = oldMouseState.Position.Y - mouseState.Position.Y; float diffX = oldMouseState.Position.X - mouseState.Position.X; if (allowCameraTranslation) { if (mouseState.RightButton == ButtonState.Pressed) { ShowLookAt = true; float dist = (focusedObject.Perimetre) / 500f; if (keyboardState.IsKeyDown(Keys.LeftControl)) { if (diffY != 0) { mainCamera.TranslationZ += diffY * factor * dist; } //mainCamera.MoveCameraForward((oldMouseState.Position.Y - mouseState.Position.Y) * dist * mainCamera.RollStep); } else { if (diffY != 0) { mainCamera.TranslationY += -diffY * factor * dist; } if (diffX != 0) { mainCamera.TranslationX += diffX * factor * dist * mainCamera.RollStep; } //mainCamera.MoveCameraUp((mouseState.Position.Y - oldMouseState.Position.Y) * dist); //mainCamera.MoveCameraRight((oldMouseState.Position.X - mouseState.Position.X) * dist * mainCamera.RollStep); } } } if (mouseState.LeftButton == ButtonState.Pressed) { if (oldMouseState.LeftButton == ButtonState.Released) { cameraTurnPress = allowCameraRotation; } } else { cameraTurnPress = false; } if (cameraTurnPress) { ShowLookAt = true; /*mainCamera.Pitch += MathHelper.ToRadians(oldMouseState.Position.Y - mouseState.Position.Y); * mainCamera.Yaw += MathHelper.ToRadians(oldMouseState.Position.X - mouseState.Position.X) * mainCamera.RollStep;*/ if (diffY != 0) { mainCamera.RotationY += factor * MathHelper.ToRadians(diffY); } if (diffX != 0) { mainCamera.RotationX += factor * MathHelper.ToRadians(diffX) * mainCamera.RollStep; } } oldMouseState = mouseState; oldKeyboardState = keyboardState; }
/// <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) { if (isLoading) { if (!loadThread.IsAlive) { UI.InitUI(); isLoading = false; Logic.bye.Play(); Animation logoAnimation = new Animation(() => { Logic.images.Remove("LOGO"); UI.EnableGroup(Logic.menuNamespace); UI.DisableGroup(Logic.menuNamespace + "Z"); UI.GenerateFadeIn(1.0f); Logic.menuMusicInstance = Logic.menuMusic.CreateInstance(); Logic.menuMusicInstance.IsLooped = true; Logic.menuMusicInstance.Volume = Settings.volume; Logic.menuMusicInstance.Play(); }); logoAnimation.AddFadeInOut(2.0f, 5.0f, 2.0f, Logic.images["LOGO"]); Logic.animations.Add(logoAnimation); } return; } if (this.IsActive) { mouseState = Mouse.GetState(); keyboardState = Keyboard.GetState(); pressedKeys = keyboardState.GetPressedKeys(); Vector2 mousePos = new Vector2(mouseState.X / scale.X, mouseState.Y / scale.Y); for (int i = Logic.animations.Count - 1; i >= 0; i--) { if (Logic.animations[i].Update((float)gameTime.ElapsedGameTime.TotalSeconds)) { Logic.animations.RemoveAt(i); } } List <string> UIelements = new List <string>(); foreach (KeyValuePair <string, Button> pair in Logic.buttons) { if (pair.Value.enabled) { UIelements.Add(pair.Key); } } foreach (KeyValuePair <string, TextBox> pair in Logic.textBoxes) { if (pair.Value.enabled) { UIelements.Add(pair.Key); } } foreach (KeyValuePair <string, InputBox> pair in Logic.inputBoxes) { if (pair.Value.enabled) { UIelements.Add(pair.Key); } } foreach (KeyValuePair <string, Grid> pair in Logic.grids) { if (pair.Value.enabled) { UIelements.Add(pair.Key); } } UIelements.Sort(); //Left click if (mouseState.LeftButton == ButtonState.Pressed && mouseBeforeState.LeftButton == ButtonState.Released) { int i; for (i = UIelements.Count - 1; i >= 0; i--) { string name = UIelements[i]; //Klikanie buttonów if (Logic.buttons.ContainsKey(name)) { if (Geo.RectContains(Logic.buttons[name].location, mousePos) && Logic.buttons[name].enabled && Logic.buttons[name].registerClicks) { if (activeInputBox != null) { activeInputBox.active = false; } activeInputBox = null; if (Logic.buttons[name].clickEvent != null) { Logic.buttons[name].clickEvent(); } i = -1; } } if (Logic.textBoxes.ContainsKey(name)) { if (Geo.RectContains(Logic.textBoxes[name].location, mousePos) && Logic.textBoxes[name].enabled && Logic.textBoxes[name].registerClicks) { if (activeInputBox != null) { activeInputBox.active = false; } activeInputBox = null; i = -1; } } if (Logic.inputBoxes.ContainsKey(name)) { if (Geo.RectContains(Logic.inputBoxes[name].location, mousePos) && Logic.inputBoxes[name].enabled) { if (activeInputBox != null) { activeInputBox.active = false; } activeInputBox = Logic.inputBoxes[name]; activeInputBox.active = true; i = -2; } } if (Logic.grids.ContainsKey(name)) { Grid grid = Logic.grids[name]; if (Geo.RectContains(Geo.Shrink(grid.location, grid.margin), mousePos) && grid.enabled) { if (activeInputBox != null) { activeInputBox.active = false; } activeInputBox = null; int pressX = (int)((mousePos.X - grid.location.X - grid.margin - grid.location.Width / 2 + grid.margin) / grid.zoom + grid.offset.X); int pressY = (int)((mousePos.Y - grid.location.Y - grid.margin - grid.location.Height / 2 + grid.margin) / grid.zoom + grid.offset.Y); int tileX = pressX / (int)grid.fieldSize.X; int tileY = pressY / (int)grid.fieldSize.Y; if (grid.clickEvent != null && tileX >= 0 && tileX < grid.sizeX && tileY >= 0 && tileY < grid.sizeY) { grid.clickEvent(tileX, tileY); } i = -1; } } } if (i == -1) { if (activeInputBox != null) { activeInputBox.active = false; activeInputBox = null; } } } //Right click if (mouseState.RightButton == ButtonState.Pressed) { if (mouseBeforeState.RightButton == ButtonState.Released) { for (int i = Logic.grids.Count - 1; i >= 0; i--) { Grid grid = Logic.grids.ElementAt(i).Value; if (Geo.RectContains(Geo.Shrink(grid.location, grid.margin), mousePos) && grid.enabled && !grid.useScrollToScroll) { draggedGrid = grid; } } } else { if (draggedGrid != null) { draggedGrid.offset -= new Vector2(mouseState.X / scale.X - mouseBeforeState.X / scale.X, mouseState.Y / scale.Y - mouseBeforeState.Y / scale.Y) / draggedGrid.zoom; } } } else { draggedGrid = null; } //Konwersja klawiszy do inputBoxa if (activeInputBox != null) { if (keyboardState.IsKeyDown(Keys.LeftControl)) { if (keyboardState.IsKeyDown(Keys.V) && keyboardBeforeState.IsKeyUp(Keys.V)) { string sOut = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(GetClipboard())); activeInputBox.Append(sOut); } } else if (keyboardState.IsKeyDown(Keys.Delete)) { activeInputBox.Clear(); } else if (pressedKeys.Length > 0) { foreach (Keys key in pressedKeys) { char charkey; if (keyboardBeforeState.IsKeyUp(key) && TryConvertKeys(key, out charkey, keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift))) { activeInputBox.Append(charkey); } } } } //Backspace if (keyboardState.IsKeyDown(Keys.Back) && activeInputBox != null) { if (backspaceHeld == false) { if (activeInputBox.text.Length > 0) { activeInputBox.text = activeInputBox.text.Remove(activeInputBox.text.Length - 1); } backspaceStart = gameTime.TotalGameTime.TotalMilliseconds; } if (backspaceHeld && gameTime.TotalGameTime.TotalMilliseconds - backspaceStart > 500 && gameTime.TotalGameTime.TotalMilliseconds - backspaceTimer > 25) { backspaceTimer = gameTime.TotalGameTime.TotalMilliseconds; if (activeInputBox.text.Length > 0) { activeInputBox.text = activeInputBox.text.Remove(activeInputBox.text.Length - 1); } } backspaceHeld = true; } else { backspaceHeld = false; } //Scroll int scrollWheelDelta = mouseState.ScrollWheelValue - mouseBeforeState.ScrollWheelValue; if (scrollWheelDelta != 0) { int i; for (i = UIelements.Count - 1; i >= 0; i--) { string name = UIelements[i]; if (Logic.buttons.ContainsKey(name)) { Button button = Logic.buttons[name]; if (Geo.RectContains(button.location, mousePos) && button.enabled) { i = -2; } } if (Logic.inputBoxes.ContainsKey(name)) { InputBox inputBox = Logic.inputBoxes[name]; if (Geo.RectContains(inputBox.location, mousePos) && inputBox.enabled) { i = -2; } } if (Logic.textBoxes.ContainsKey(name)) { TextBox textBox = Logic.textBoxes[name]; if (Geo.RectContains(textBox.location, mousePos) && textBox.enabled) { if (textBox.canScroll) { if (scrollWheelDelta < 0) { textBox.scroll++; } else if (textBox.scroll > 0) { textBox.scroll--; } if (textBox.lines.Count - textBox.scroll < textBox.lineCount) { textBox.scroll = textBox.lines.Count - textBox.lineCount; } if (textBox.scroll < 0) { textBox.scroll = 0; } } i = -2; } } if (Logic.grids.ContainsKey(name)) { Grid grid = Logic.grids[name]; if (Geo.RectContains(grid.location, mousePos) && grid.enabled) { if (grid.useScrollToScroll) { if (scrollWheelDelta < 0) { grid.offset.Y += 25.0f; } else if (scrollWheelDelta > 0) { grid.offset.Y -= 25.0f; } } else { if (scrollWheelDelta < 0 && grid.zoom > 0.5f) { grid.zoom -= 0.1f; } else if (scrollWheelDelta > 0 && grid.zoom < 2.0f) { grid.zoom += 0.1f; } } i = -2; } } } } } //Wy³¹czanie nieaktywnych obiektów if (activeInputBox != null && !activeInputBox.enabled) { activeInputBox = null; } if (draggedGrid != null && !draggedGrid.enabled) { draggedGrid = null; } //Cofanie gdy przejedziesz grida za bardzo foreach (KeyValuePair <string, Grid> gridpair in Logic.grids) { Grid grid = gridpair.Value; int marginX = (int)((grid.location.Width / 2 - grid.margin) / grid.zoom); int marginY = (int)((grid.location.Height / 2 - grid.margin) / grid.zoom); if (grid.offset.X < marginX) { grid.offset.X = Math.Min(grid.offset.X + 25, marginX); } if (grid.offset.Y < marginY) { grid.offset.Y = Math.Min(grid.offset.Y + 25, marginY); } if (grid.offset.X > grid.sizeX * grid.fieldSize.X - marginX) { grid.offset.X = Math.Max(grid.offset.X - 25, grid.sizeX * grid.fieldSize.X - marginX); } if (grid.offset.Y > grid.sizeY * grid.fieldSize.Y - marginY) { grid.offset.Y = Math.Max(grid.offset.Y - 25, grid.sizeY * grid.fieldSize.Y - marginY); } } Logic.Update(); mouseBeforeState = mouseState; keyboardBeforeState = keyboardState; base.Update(gameTime); }
protected override void LoadContent() { defaultViewport = GraphicsDevice.Viewport; leftViewport = defaultViewport; centerViewport = defaultViewport; rightViewport = defaultViewport; leftViewport.Width = leftViewport.Width / 3; centerViewport.Width = rightViewport.Width / 3; rightViewport.Width = rightViewport.Width / 3; centerViewport.X = leftViewport.Width; rightViewport.X = leftViewport.Width * 2; spriteBatch = new SpriteBatch(GraphicsDevice); carpos = new Important_positions_struct[4]; models.Add(new CModel(Content.Load <Model>("Models/CAR2"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.7f), GraphicsDevice)); // models.Add(new CModel(Content.Load<Model>("Models/world"), Vector3.Zero, Vector3.Zero, new Vector3(1.00f), GraphicsDevice)); models.Add(new CModel(Content.Load <Model>("Models/world2"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(1.00f), GraphicsDevice)); models.Add(new CModel(Content.Load <Model>("Models/worldD"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(1.00f), GraphicsDevice)); models.Add(new CModel(Content.Load <Model>("Models/worldU"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(1.00f), GraphicsDevice)); models.Add(new CModel(Content.Load <Model>("Models/worldM"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(1.00f), GraphicsDevice)); Bus_models.Add(new BusModel(Content.Load <Model>("Models/BUS_FRONT"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice)); Bus_models.Add(new BusModel(Content.Load <Model>("Models/BUS_REAR"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice)); Bus_models.Add(new BusModel(Content.Load <Model>("Models/tire2"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice)); Bus_models.Add(new BusModel(Content.Load <Model>("Models/tire2"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice)); Bus_models.Add(new BusModel(Content.Load <Model>("Models/tire"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice)); Bus_models.Add(new BusModel(Content.Load <Model>("Models/tire"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice)); Bus_models.Add(new BusModel(Content.Load <Model>("Models/tire"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice)); Bus_models.Add(new BusModel(Content.Load <Model>("Models/tire"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice)); Bus_models.Add(new BusModel(Content.Load <Model>("Models/volante"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice)); TextureCube tc; tc = new TextureCube(GraphicsDevice, 1024, false, SurfaceFormat.Color); tc.SetData <byte>(CubeMapFace.PositiveX, RealSkyBox.getface("270", GraphicsDevice, 23)); tc.SetData <byte>(CubeMapFace.NegativeZ, RealSkyBox.getface("0", GraphicsDevice, 23)); tc.SetData <byte>(CubeMapFace.NegativeX, RealSkyBox.getface("90", GraphicsDevice, 23)); tc.SetData <byte>(CubeMapFace.PositiveZ, RealSkyBox.getface("180", GraphicsDevice, 23)); tc.SetData <byte>(CubeMapFace.PositiveY, RealSkyBox.getface("up", GraphicsDevice, 23)); skybox2 = new RealSkyBox(Content); skybox2.skyBoxTexture = tc; // models.Add(new CModel(Content.Load<Model>("Models/PRUEBA"), Vector3.Zero, Vector3.Zero, new Vector3(0.26f), GraphicsDevice)); CModel.skyboxTexture = Content.Load <TextureCube>("Skyboxes/Nice"); // CModel.skyboxTexture = Content.Load<TextureCube>("Skyboxes/Sunset"); CModel.effect = Content.Load <Microsoft.Xna.Framework.Graphics.Effect>("Effects/Reflection"); skybox = new Skybox("Skyboxes/Nice", Content); // skybox = new Skybox("Skyboxes/Sunset", Content); yalt = 1.100f; dis = 1.800f; angle = -0.0f; translation = new Microsoft.Xna.Framework.Vector3(((float)Math.Sin(angle)) * dis, yalt, ((float)Math.Cos(angle)) * dis); camera = new TargetCamera(translation, car_position, GraphicsDevice); yxalt = .600f; lastMouseState = Microsoft.Xna.Framework.Input.Mouse.GetState(); //carga el escenario resolve_collision.generate_last_index(100); compute_tiles(); Bus_models[0].position = car_position; Bus_models[0].Rotation = new Microsoft.Xna.Framework.Vector3(0, 0, 0); }
public static void MouseControls(GameWindow win) { mainCamera.Animate(); mouseState = Mouse.GetState(win); keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.S) && !oldKeyboardState.IsKeyDown(Keys.S)) { mainCamera.Animated = !mainCamera.Animated; if (mainCamera.Animated) { mainCamera.RotationX = 0; mainCamera.RotationY = 0; } } int wheelVal = mouseState.ScrollWheelValue; int oldWheelVal = oldMouseState.ScrollWheelValue; bool allowCameraRotation = keyboardState.IsKeyUp(Keys.LeftAlt) && keyboardState.IsKeyUp(Keys.LeftShift); bool allowCameraTranslation = true; bool allowCameraZoom = true; float step = 50f; if (keyboardState.IsKeyDown(Keys.LeftControl)) { if (wheelVal < oldWheelVal) { mainCamera.FieldOfView += step / 1000f; } else if (wheelVal > oldWheelVal) { mainCamera.FieldOfView -= step / 1000f; } } else { if (wheelVal < oldWheelVal) { mainCamera.ZoomTarget += step; } else if (wheelVal > oldWheelVal) { mainCamera.ZoomTarget -= step; } } if (mouseState.MiddleButton == ButtonState.Pressed) { if (keyboardState.IsKeyDown(Keys.LeftControl)) { mainCamera.FieldOfView = MathHelper.ToRadians((float)Camera.FieldsOfView.Default); } else { DefaultCamera(); } } float factor = mainCamera.Animated ? 0.3333f : 1; float diffY = oldMouseState.Position.Y - mouseState.Position.Y; float diffX = oldMouseState.Position.X - mouseState.Position.X; if (allowCameraTranslation) { if (mouseState.RightButton == ButtonState.Pressed) { if (keyboardState.IsKeyDown(Keys.LeftControl)) { if (diffY != 0) { mainCamera.TranslationZ += diffY * factor * step; } //mainCamera.MoveCameraForward((oldMouseState.Position.Y - mouseState.Position.Y) * dist * mainCamera.RollStep); } else { if (diffY != 0) { mainCamera.TranslationY += -diffY * factor * step; } if (diffX != 0) { mainCamera.TranslationX += diffX * factor * step * mainCamera.RollStep; } //mainCamera.MoveCameraUp((mouseState.Position.Y - oldMouseState.Position.Y) * dist); //mainCamera.MoveCameraRight((oldMouseState.Position.X - mouseState.Position.X) * dist * mainCamera.RollStep); } } } if (mouseState.LeftButton == ButtonState.Pressed) { if (oldMouseState.LeftButton == ButtonState.Released) { cameraTurnPress = allowCameraRotation; } } else { cameraTurnPress = false; } if (cameraTurnPress) { /*mainCamera.Pitch += MathHelper.ToRadians(oldMouseState.Position.Y - mouseState.Position.Y); * mainCamera.Yaw += MathHelper.ToRadians(oldMouseState.Position.X - mouseState.Position.X) * mainCamera.RollStep;*/ if (diffY != 0) { mainCamera.RotationY += factor * MathHelper.ToRadians(diffY); } if (diffX != 0) { mainCamera.RotationX += factor * MathHelper.ToRadians(diffX) * mainCamera.RollStep; } } oldMouseState = mouseState; oldKeyboardState = keyboardState; }
void updateCamera(GameTime gameTime) { colision_map.load_map(); JoystickState state = new JoystickState(); bool[] buttonData; int[] hats, uv; SlimDX.Result r; try { if ((r = joystick.Acquire()).IsFailure) { throw new DirectInputException(r); } if ((joystick.Capabilities.Flags & DeviceFlags.PolledDevice) != 0) { if ((r = joystick.Poll()).IsFailure) { throw new DirectInputException(r); } } state = joystick.GetCurrentState(); // state = joystick.GetCurrentState(); if (SlimDX.Result.Last.IsFailure) { throw new DirectInputException(SlimDX.Result.Last); } buttonData = state.GetButtons(); hats = state.GetPointOfViewControllers(); uv = state.GetForceSliders(); } catch (DirectInputException e) { int I = 0; } if (state.X != 0) { xval = state.X; } if (state.Y != 0) { yval = (-1 * (state.Y - 5000)); } if (state.RotationZ < 1) { bval = -1 * (state.RotationZ); } float iangle; iangle = (((float)xval)) * 1.4f / 5000.0f / 3.1415f; float iaccel; iaccel = yval / 100.0f + 1.0f; iaccel = (float)Math.Log10((double)iaccel) + 1.0f; iaccel = (float)Math.Pow(2, (double)iaccel) - 2; float daccel; daccel = bval / 100.0f + 1.0f; daccel = (float)Math.Log10((double)daccel) + 1.0f; daccel = (float)Math.Pow(3, (double)daccel) - 3; // Get the new keyboard and mouse state Microsoft.Xna.Framework.Input.MouseState mouseState = Microsoft.Xna.Framework.Input.Mouse.GetState(); Microsoft.Xna.Framework.Input.KeyboardState keyState = Microsoft.Xna.Framework.Input.Keyboard.GetState(); // Determine how much the camera should turn float deltaX = ((float)lastMouseState.X - (float)mouseState.X) * 0.02f; float deltaY = ((float)lastMouseState.Y - (float)mouseState.Y) * 0.02f; // Rotate the camera /// ((FreeCamera)camera).Rotate(deltaX * .01f, deltaY * .01f); double steer = 0; if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.I)) { driver_pos = 2.42f; mode = 1; dis = 1.36f; yalt = 1.45f; angle = -2.9115f; yxalt = 1.23f; rangle = -1.45f; // -2.34f; langle = 1.45f; //2.34f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape)) { Bus_models[0].position = new Microsoft.Xna.Framework.Vector3(1228.729f, 0.2f, -3246.247f); } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.O)) { mode = 0; dis = 13.5f; yalt = 6.0f; angle = 0; yxalt = 2.44f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.P)) { mode = 0; dis = 4.3f; yalt = 1.2f; angle = 4.77f; yxalt = 1.4f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D7)) { rangle += .010f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D8)) { rangle -= .010f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D9)) { langle += .0100f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D0)) { langle -= .0100f; //100 km/hr } if (mode == 0) { if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Y)) { driver_pos += .010f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.U)) { driver_pos -= .010f; } } else { if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Y)) { driver_pos += .0010f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.U)) { driver_pos -= .0010f; } } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D5)) { driver_posx += .0010f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D6)) { driver_posx -= .0010f; } // Determine in which direction to move the camera if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Z)) { dis += .010f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.X)) { dis -= .010f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.C)) { dis += .0200f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.V)) { dis -= .0200f; //100 km/hr } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Q)) { yalt += 5.0f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.W)) { yalt += .010f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S)) { yalt -= .010f; } if (mode == 0) { if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A)) { angle += .02f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D)) { angle -= .02f; } } else { if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D)) { angle += .01f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A)) { angle -= .01f; } } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.G)) { yxalt -= 0.010f; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.T)) { yxalt += 0.010f; } Bus_models[0].ProcessKeyboard(gameTime, iangle, iaccel, daccel); Bus_models[0].Update(gameTime); Bus_models[0].doit(); if (mode == 1) { tempbus_Position_I = new Microsoft.Xna.Framework.Vector3((float)(Bus_models[0].Position.X - driver_pos * Math.Sin(Bus_models[0].Rotation.Y) - driver_posx * Math.Cos(Bus_models[0].Rotation.Y)), yalt, (float)(Bus_models[0].Position.Z - driver_pos * Math.Cos(Bus_models[0].Rotation.Y) + driver_posx * Math.Sin(Bus_models[0].Rotation.Y))); tempbus_Position_C = new Microsoft.Xna.Framework.Vector3((float)(Bus_models[0].Position.X - driver_pos * Math.Sin(Bus_models[0].Rotation.Y) - driver_posx * Math.Cos(Bus_models[0].Rotation.Y)), yalt, (float)(Bus_models[0].Position.Z - driver_pos * Math.Cos(Bus_models[0].Rotation.Y) + driver_posx * Math.Sin(Bus_models[0].Rotation.Y))); tempbus_Position_D = new Microsoft.Xna.Framework.Vector3((float)(Bus_models[0].Position.X - driver_pos * Math.Sin(Bus_models[0].Rotation.Y) - driver_posx * Math.Cos(Bus_models[0].Rotation.Y)), yalt, (float)(Bus_models[0].Position.Z - driver_pos * Math.Cos(Bus_models[0].Rotation.Y) + driver_posx * Math.Sin(Bus_models[0].Rotation.Y))); // ((TargetCamera)camera).Position = target; // ((TargetCamera)camera).Target = new Vector3(car_position.X, yxalt, car_position.Z); tempbus_target_I = new Microsoft.Xna.Framework.Vector3((float)(tempbus_Position_I.X - dis * (Math.Sin(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle + langle))), yalt - (yalt - yxalt) * .6f, (float)(tempbus_Position_I.Z - dis * (Math.Cos(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle + langle)))); tempbus_target_C = new Microsoft.Xna.Framework.Vector3((float)(tempbus_Position_I.X - dis * (Math.Sin(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle))), yxalt, (float)(tempbus_Position_I.Z - dis * (Math.Cos(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle)))); tempbus_target_D = new Microsoft.Xna.Framework.Vector3((float)(tempbus_Position_I.X - dis * (Math.Sin(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle + rangle))), yalt - (yalt - yxalt) * .3f, (float)(tempbus_Position_I.Z - dis * (Math.Cos(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle + rangle)))); } if (mode == 0) { tempbus_target_I = new Microsoft.Xna.Framework.Vector3((float)(Bus_models[0].Position.X - driver_pos * Math.Sin(Bus_models[0].Rotation.Y) - 0.3 * Math.Cos(Bus_models[0].Rotation.Y)), yxalt, (float)(Bus_models[0].Position.Z - driver_pos * Math.Cos(Bus_models[0].Rotation.Y) + .3f * Math.Sin(Bus_models[0].Rotation.Y))); tempbus_target_C = new Microsoft.Xna.Framework.Vector3((float)(Bus_models[0].Position.X - driver_pos * Math.Sin(Bus_models[0].Rotation.Y) - 0.3 * Math.Cos(Bus_models[0].Rotation.Y)), yxalt, (float)(Bus_models[0].Position.Z - driver_pos * Math.Cos(Bus_models[0].Rotation.Y) + .3f * Math.Sin(Bus_models[0].Rotation.Y))); tempbus_target_D = new Microsoft.Xna.Framework.Vector3((float)(Bus_models[0].Position.X - driver_pos * Math.Sin(Bus_models[0].Rotation.Y) - 0.3 * Math.Cos(Bus_models[0].Rotation.Y)), yxalt, (float)(Bus_models[0].Position.Z - driver_pos * Math.Cos(Bus_models[0].Rotation.Y) + .3f * Math.Sin(Bus_models[0].Rotation.Y))); tempbus_Position_I = new Microsoft.Xna.Framework.Vector3((float)(tempbus_target_I.X - dis * (Math.Sin(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle - 1.57f))), yalt, (float)(tempbus_target_I.Z - dis * (Math.Cos(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle - 1.57f)))); tempbus_Position_C = new Microsoft.Xna.Framework.Vector3((float)(tempbus_target_C.X - dis * (Math.Sin(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle))), yalt, (float)(tempbus_target_C.Z - dis * (Math.Cos(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle)))); tempbus_Position_D = new Microsoft.Xna.Framework.Vector3((float)(tempbus_target_D.X - dis * (Math.Sin(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle + 1.57f))), yalt, (float)(tempbus_target_D.Z - dis * (Math.Cos(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle + 1.57f)))); } double fps = (1000 / gameTime.ElapsedGameTime.TotalMilliseconds); fps = Math.Round(fps, 0); this.Window.Title = " pos " + roadcode + " th " + BusModel.last_theta + " LF " + maps_loaded + " Distance " + dis + "," + fps.ToString() + " FPS"; // Update the mouse state lastMouseState = mouseState; }
/// <summary> /// This function is used to update the contents of the text box. /// </summary> /// <param name="CurrTime">Currend time information</param> /// <param name="CurrKeyboard">Current state of the keyboard.</param> /// <param name="CurrMouse">Current state of the mouse.</param> /// <param name="ProcessMouseEvent">Set true to allow this object to process mouse events, false to ignore them</param> protected override void UpdateContents(GameTime CurrTime, Microsoft.Xna.Framework.Input.KeyboardState CurrKeyboard, Microsoft.Xna.Framework.Input.MouseState CurrMouse, bool ProcessMouseEvent) { if ((ProcessMouseEvent == true) && ((CurrMouse.LeftButton == ButtonState.Pressed) || (CurrMouse.LeftButton == ButtonState.Pressed))) //Mouse button is pressed { if (ClientRegion.Contains(CurrMouse.Position) == false) //Mouse is outside of the control, it has lost focus { if (HasFocus != false) { HasChanged = true; } HasFocus = false; } } if (HasFocus != false) //Only update if the control has focus { string Input = MGInput.GetTypedChars(CurrKeyboard, cPriorKeys); if (CurrTime.TotalGameTime.Milliseconds <= 500) { if (cCursorOn == false) { HasChanged = true; } cCursorOn = true; } else { if (cCursorOn == true) { HasChanged = true; } cCursorOn = false; } if (Input.CompareTo("\b") == 0) { if (Text.Length > 0) { Text = Text.Substring(0, Text.Length - 1); HasChanged = true; } } else { Text += Input; HasChanged = true; } } }