//Should be called at beginning of Update in Game public static void Update() { oldKeyState = keyState; keyState = Keyboard.GetState(); oldMouseState = mouseState; mouseState = Mouse.GetState(); }
/// <summary> /// Initializes a new instance of the <see cref="EVEMon.TrayIcon"/> class with the specfied container. /// </summary> /// <param name="container">An <see cref="System.ComponentModel.IContainer"/> that represents the container for the <see cref="EVEMon.TrayIcon"/> control.</param> public TrayIcon(IContainer container) { if (container != null) container.Add(this); InitializeComponent(); this.mouseState = new MouseStateOut(this); }
/// <summary> /// Initializes the input states /// </summary> public static void Initialize() { PreviousKeyboardState = CurrentKeyboardState = Keyboard.GetState(); PreviousMouseState = CurrentMouseState = Mouse.GetState(); }
// Method that check if our mouse input is over our button position. // if it is we change the color and the text. // when click we see the state to clicked. // finally check if any new events should be fired. internal void HandleInput(MouseState mouseState) { Sprite.Color = DefeaultSpriteColor; Text.Color = DefaultTextColor; if (ContainsPosition(new Vector2(mouseState.X, mouseState.Y))) { Sprite.Color = HoverSpriteColor; Text.Color = HoverTextColor; m_currentButtonState = ButtonState.Hovered; if(mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { m_currentButtonState = ButtonState.Clicked; } } else { m_currentButtonState = ButtonState.None; } FireEvents(); m_previousButtonState = m_currentButtonState; }
public static void ProcessMouse(int oriX,int oriY){ EventArgs evnt=null; var pressed = false; prevMouseState =curMouseState; curMouseState = Mouse.GetCursorState (); Gwen.Input.InputHandler.HoveredControl =input.m_Canvas.GetControlAt(curMouseState.X - oriX, curMouseState.Y - oriY); foreach (var mouseCode in mouseCodes) if (curMouseState[mouseCode]!=prevMouseState[mouseCode]){ evnt = new MouseButtonEventArgs(curMouseState.X - oriX, curMouseState.Y - oriY, mouseCode, true);//last param bugged //evnt = new MouseButtonEventArgs (curMouseState.X, curMouseState.Y, mouseCode,true);//last param bugged if (curMouseState [mouseCode]) { pressed = true; Gwen.Input.InputHandler.MouseFocus = Gwen.Input.InputHandler.HoveredControl; OnMouseDown?.Invoke ((MouseButtonEventArgs)evnt); } else { OnMouseUp?.Invoke ((MouseButtonEventArgs)evnt); } } Vector2 delta =MainWindow.lastPos - new Vector2(curMouseState.X, curMouseState.Y); if (Math.Abs (delta.X) > 0 || Math.Abs (delta.Y) > 0) { evnt = new MouseMoveEventArgs (curMouseState.X-oriX, curMouseState.Y-oriY,(int)delta.X,(int)delta.Y); OnMouseMove?.Invoke (evnt as MouseMoveEventArgs); } input.ProcessMouseMessage (evnt,pressed); MainWindow.lastPos = new Vector2 (curMouseState.X, curMouseState.Y); }
public void Update(MouseState mouseState) { _previousFrameMouseState = _currentFrameMouseState; _currentFrameMouseState = mouseState; CalculateRelativeMousePosition(); }
public void ClickOutput(AC.Menu _menu, MouseState _mouseState) { if (items.Count > 0) { if (_mouseState == MouseState.SingleClick) { if (KickStarter.runtimeInventory.selectedItem == null) { // Pick up created item if (activeRecipe.onCreateRecipe == OnCreateRecipe.SelectItem) { KickStarter.runtimeInventory.PerformCrafting (activeRecipe, true); } else if (activeRecipe.onCreateRecipe == OnCreateRecipe.RunActionList) { KickStarter.runtimeInventory.PerformCrafting (activeRecipe, false); if (activeRecipe.invActionList != null) { AdvGame.RunActionListAsset (activeRecipe.invActionList); } } else { KickStarter.runtimeInventory.PerformCrafting (activeRecipe, false); } } } PlayerMenus.ResetInventoryBoxes (); } }
/// <summary> /// Update input, including getting mouse deltas/etc. /// </summary> public static void Think(GameWindow window, FrameEventArgs e) { current = Mouse.GetState(); window.CursorVisible = !LockMouse; if (current != previous && window.Focused) { // Mouse state has changed deltaX = current.X - previous.X; deltaY = current.Y - previous.Y; deltaZ = current.Wheel - previous.Wheel; if (LockMouse) { Mouse.SetPosition(window.X + window.Width / 2, window.Y + window.Height / 2); } } else { deltaX = 0; deltaY = 0; deltaZ = 0; } previous = current; }
public void ClickContainer(MouseState _mouseState, int _slot, Container container) { if (container == null || KickStarter.runtimeInventory == null) return; KickStarter.runtimeInventory.SetFont (font, GetFontSize (), fontColor, textEffects); if (_mouseState == MouseState.SingleClick) { if (KickStarter.runtimeInventory.selectedItem == null) { if (container.items.Count > (_slot+offset) && container.items [_slot+offset] != null) { ContainerItem containerItem = container.items [_slot + offset]; KickStarter.runtimeInventory.Add (containerItem.linkedID, containerItem.count, selectItemsAfterTaking, -1); container.items.Remove (containerItem); } } else { // Placing an item inside the container container.InsertAt (KickStarter.runtimeInventory.selectedItem, _slot+offset); KickStarter.runtimeInventory.Remove (KickStarter.runtimeInventory.selectedItem); } } else if (_mouseState == MouseState.RightClick) { if (KickStarter.runtimeInventory.selectedItem != null) { KickStarter.runtimeInventory.SetNull (); } } }
public void HandleInput(MouseState mouseState, KeyboardState keyboardState) { KeyboardState = keyboardState; if (MouseOverRenderArea && mouseState.LeftButton == ButtonState.Pressed) { if (!MouseDragging) { MouseDragging = true; MousePreviousPosition = new Vector2(mouseState.X, mouseState.Y); } var mouseNewCoords = new Vector2(mouseState.X, mouseState.Y); MouseDelta.X = mouseNewCoords.X - MousePreviousPosition.X; MouseDelta.Y = mouseNewCoords.Y - MousePreviousPosition.Y; MousePreviousPosition = mouseNewCoords; } if (!MouseOverRenderArea || mouseState.LeftButton == ButtonState.Released) { MouseDragging = false; } }
public void Update() { previousMouseState = currentMouseState; previousKeyboardState = currentKeyboardState; currentMouseState = Mouse.GetState(); currentKeyboardState = Keyboard.GetState(); }
public override void DoMouseInteraction(MouseState mouseState, System.Windows.Forms.MouseButtons mouseButtons, Vector2 mousePos, out bool shouldUpdate) { shouldUpdate = false; switch (mouseState) { case MouseState.ClickStart: if (Click == null) { Open(); } shouldUpdate = true; break; case MouseState.ClickEnd: if (Bounds.Contains(mousePos.X, mousePos.Y)) { if (DoClick() == true) { Close(); } } shouldUpdate = true; break; default: base.DoMouseInteraction(mouseState, mouseButtons, mousePos, out shouldUpdate); break; } }
/// <summary> /// Initializes a new instance of the <see cref="TrayIcon"/> class with the specfied container. /// </summary> /// <param name="container">An <see cref="System.ComponentModel.IContainer"/> that represents the container for the <see cref="TrayIcon"/> control.</param> public TrayIcon(IContainer container) { container?.Add(this); InitializeComponent(); m_mouseState = new MouseStateOut(this); }
public void Update(GameTime t) { this.PreviousKeyboardState = this.KeyboardState; this.PreviousMouseState = this.MouseState; this.KeyboardState = Keyboard.GetState(); this.MouseState = Mouse.GetState(); }
/// <summary> /// Initializes a new instance of the Presenter class. /// </summary> /// <param name="view">View interface</param> /// <param name="factory">Path finder factory service</param> public Presenter(IView view, IPathFinderFactory factory) { this.View = view; this.View.Presenter = this; this.View.SetDrawing(this.Surface); this.CurrentMouseState = MouseState.Default; this.Factory = factory; }
public void OnMouseDown(IInputElement relativeTo, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left && _selectionState == MouseState.WaitingForDown) { _selectionState = MouseState.WaitingForUp; _selectDown = e.GetPosition(relativeTo); } }
/// <summary> /// Check input device without check Floor Height /// </summary> public void Poll() { KeyState = KeyBoardDevice.GetCurrentKeyboardState(); KeyBoardJOBs(); MState = MouseDevice.CurrentMouseState; MouseJOBs(); }
public static void Update() { previousMouseState = currentMouseState; previousKeyboardState = currentKeyboardState; currentMouseState = Mouse.GetState(); currentKeyboardState = Keyboard.GetState(); DetermineScale(); }
public InputSystem() { CurrentKeyboardState = new KeyboardState(); PreviousKeyboardState = new KeyboardState(); CurrentGamepadState = new GamePadState(); PreviousGamepadState = new GamePadState(); CurrentMouseState = new MouseState(); PreviousMouseState = new MouseState(); }
/// <summary>Update player inputs.</summary> public void Update() { previousMouseState = currentMouseState; previousKeyboardState = currentKeyboardState; previousControlerState = currentControlerState; currentMouseState = Mouse.GetState(); currentKeyboardState = Keyboard.GetState(); currentControlerState = GamePad.GetState(PlayerIndex.One); }
public MeasureTool(ImageCanvas canvas) { _lineOverlay = null; _mouseDownText = null; _mouseFollowText = null; _canvas = canvas; _mouseState = MouseState.WaitingForDown; }
public static MouseState GetState () { MouseState ms = new MouseState(_x,_y); ms.LeftButton = _leftButton; ms.RightButton = _rightButton; ms.MiddleButton = _middleButton; return ms; }
public static bool Collides(MouseState mouseState, MenuItem item) { if (mouseState.X < item.Dst.Left || mouseState.X > item.Dst.Right || mouseState.Y < item.Dst.Top || mouseState.Y > item.Dst.Bottom) return false; return true; }
public static MouseState GetState () { MouseState ms = new MouseState(_x,_y); ms.LeftButton = _leftButton; ms.RightButton = _rightButton; ms.MiddleButton = _middleButton; ms.ScrollWheelValue = (int)_scrollWheelValue; return ms; }
/// <summary> /// 构造函数。 /// </summary> public SplitContainerEx() { this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); this.mCollpasePanel = SplitterPanelEnum.Panel2; this.mMouseState = MouseState.Normal; this.SplitterWidth = 9; this.Panel1MinSize = this.Panel2MinSize = 0; }
public void OnMouseUp(IInputElement relativeTo, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left && _selectionState == MouseState.WaitingForUp) { _selectionState = MouseState.Completed; _selectUp = e.GetPosition(relativeTo); _DragCompleted(); } }
public MouseState GetState() { lock (this.UpdateLock) { MouseState local_0 = new MouseState(); foreach (MouseState item_0 in this.mice) local_0.MergeBits(item_0); return local_0; } }
public PCInput(Tortoise2d game) { now = new MouseState(); prev = new MouseState(); deltamouse = new float[3] { 0, 0, 0 }; this.game = game; keysDown = new bool[71]; keysPrev = new bool[71]; deltaMouse = new float[3]; }
//Should be called at beginning of Update in Game public static void Update() { oldKeyState = keyState; keyState = Keyboard.GetState(); oldMouseState = mouseState; mouseState = Mouse.GetState(); if (LeftButtonPressed()) leftMouseDownPosition = mouseState.Position; if (RightButtonPressed()) rightMouseDownPosition = mouseState.Position; }
public MouseInputProcessor(GameWindow gameWindow, IGuiToRelativeCoordinateTransformer guiToRelativeCoordinateTransformer) { _gameWindow = gameWindow; _guiToRelativeCoordinateTransformer = guiToRelativeCoordinateTransformer; var gameWindowInterfaceSizeAdapter = new GameWindowInterfaceSizeAdapter { GameWindow = gameWindow }; _guiToRelativeCoordinateTransformer.Interface = gameWindowInterfaceSizeAdapter; _previousFrameMouseState = new MouseState(); _currentFrameMouseState = new MouseState(); }
public void Update(GameTime gameTime) { UpdateDragAndDrop(); KeyboardState newState = Keyboard.GetState(); if (newState.IsKeyDown(Keys.D) && !oldState.IsKeyDown(Keys.D)) { DeleteEntity(Mouse.GetState()); } if (newState.IsKeyDown(Keys.M) && !oldState.IsKeyDown(Keys.M)) { isListening = !isListening; } if (isListening) { MouseState mouseState = Mouse.GetState(); if (newState.IsKeyDown(Keys.P) && !oldState.IsKeyDown(Keys.P)) { npcController.CreateNPC(Entities.NPCType.PoliceA, new Vector2(mouseState.X + HideOutGame.SCREEN_OFFSET_X, mouseState.Y + HideOutGame.SCREEN_OFFSET_Y)); isListening = false; } if (newState.IsKeyDown(Keys.L) && !oldState.IsKeyDown(Keys.L)) { npcController.CreateNPC(Entities.NPCType.PoliceB, new Vector2(mouseState.X + HideOutGame.SCREEN_OFFSET_X, mouseState.Y + HideOutGame.SCREEN_OFFSET_Y)); isListening = false; } else if (newState.IsKeyDown(Keys.A) && !oldState.IsKeyDown(Keys.A)) { itemController.CreateItem(Entities.ItemType.Apple, new Vector2(mouseState.X + HideOutGame.SCREEN_OFFSET_X, mouseState.Y + HideOutGame.SCREEN_OFFSET_Y)); isListening = false; } else if (newState.IsKeyDown(Keys.C) && !oldState.IsKeyDown(Keys.C)) { itemController.CreateItem(Entities.ItemType.CandyBar, new Vector2(mouseState.X + HideOutGame.SCREEN_OFFSET_X, mouseState.Y + HideOutGame.SCREEN_OFFSET_Y)); isListening = false; } else if (newState.IsKeyDown(Keys.O) && !oldState.IsKeyDown(Keys.O)) { itemController.CreateItem(Entities.ItemType.Coin, new Vector2(mouseState.X + HideOutGame.SCREEN_OFFSET_X, mouseState.Y + HideOutGame.SCREEN_OFFSET_Y)); isListening = false; } else if (newState.IsKeyDown(Keys.W) && !oldState.IsKeyDown(Keys.W)) { itemController.CreateItem(Entities.ItemType.WaterBottle, new Vector2(mouseState.X + HideOutGame.SCREEN_OFFSET_X, mouseState.Y + HideOutGame.SCREEN_OFFSET_Y)); isListening = false; } else if (newState.IsKeyDown(Keys.B) && !oldState.IsKeyDown(Keys.B)) { obstacleController.CreateObstacle(Entities.ObstacleType.Bush, new Vector2(mouseState.X + HideOutGame.SCREEN_OFFSET_X, mouseState.Y + HideOutGame.SCREEN_OFFSET_Y)); isListening = false; } else if (newState.IsKeyDown(Keys.T) && !oldState.IsKeyDown(Keys.T)) { obstacleController.CreateObstacle(Entities.ObstacleType.Tree, new Vector2(mouseState.X + HideOutGame.SCREEN_OFFSET_X, mouseState.Y + HideOutGame.SCREEN_OFFSET_Y)); isListening = false; } else if (newState.IsKeyDown(Keys.F) && !oldState.IsKeyDown(Keys.F)) { obstacleController.CreateObstacle(Entities.ObstacleType.Fountain, new Vector2(mouseState.X + HideOutGame.SCREEN_OFFSET_X, mouseState.Y + HideOutGame.SCREEN_OFFSET_Y)); isListening = false; } else if (newState.IsKeyDown(Keys.N) && !oldState.IsKeyDown(Keys.N)) { obstacleController.CreateObstacle(Entities.ObstacleType.Pond, new Vector2(mouseState.X + HideOutGame.SCREEN_OFFSET_X, mouseState.Y + HideOutGame.SCREEN_OFFSET_Y)); isListening = false; } } oldState = newState; }
/// <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) { MouseState mouse = Mouse.GetState(); GamePadState pad1 = GamePad.GetState(PlayerIndex.One); // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } // --- Update logic --- timer++; lsuTimer++; if (lsuTimer == 60) // inc +3 every 1 sec { lsu += 3; if (lsu > 100) { lsu = 100; } lsuTimer = 0; } if (explode) { expTimer++; } if (pFire) { pTimer++; } if (expTimer == 60) { explode = false; expTimer = 0; } // randoms for borg ship if (timer == 1) { time = random.Next(1, 181); //1 to 3s // what time appears direction = random.Next(4); //0 to 3 distUp = random.Next(71); //0 to 70 Y distDown = random.Next(330, 411); //330 to 410 Y distLeft = random.Next(180); //0 to 180 X distRight = random.Next(500, 701); //500 to 700 X screenTime = random.Next(120, 361); //2s to 6s // how long on screen } if (timer == time) { drawShip = true; drawTorp = true; } else if (timer <= time + screenTime && timer >= time) { drawShip = true; } else { drawShip = false; } if (timer == 180 + screenTime) { timer = 0; } // moves borg torpedo if (drawTorp) { if (direction == 0) //up { if (timer == time) { torpRect.X = 380; torpRect.Y = distUp; } torpRect.Y += 4; if (torpRect.Y >= 200) { drawTorp = false; } } else if (direction == 1) //down { if (timer == time) { torpRect.X = 380; torpRect.Y = distDown; } torpRect.Y -= 4; if (torpRect.Y <= 250) { drawTorp = false; } } else if (direction == 2) //left { if (timer == time) { torpRect.X = distLeft; torpRect.Y = 200; } torpRect.X += 4; if (torpRect.X >= 350) { drawTorp = false; } } else if (direction == 3) //right { if (timer == time) { torpRect.X = distRight; torpRect.Y = 200; } torpRect.X -= 4; if (torpRect.X <= 400) { drawTorp = false; } } } // select gun if (pad1.DPad.Up == ButtonState.Pressed && !fire && !explode && !pFire) { up = true; right = false; left = false; down = false; } else if (pad1.DPad.Down == ButtonState.Pressed && !fire && !explode && !pFire) { down = true; right = false; left = false; up = false; } else if (pad1.DPad.Right == ButtonState.Pressed && !fire && !explode && !pFire) { right = true; left = false; up = false; down = false; } else if (pad1.DPad.Left == ButtonState.Pressed && !fire && !explode && !pFire) { left = true; right = false; up = false; down = false; } // select explosive (take) and propulsive (take2) if (!fire) { if (pad1.ThumbSticks.Left.Y > 0 && pad1.ThumbSticks.Left.Y > oldLeftY + 0.000001) { take++; } else if (pad1.ThumbSticks.Left.Y < 0 && pad1.ThumbSticks.Left.Y < oldLeftY - 0.000001) { take--; } if (take < 0) { take = 0; } if (take > 9) { take = 9; } if (pad1.ThumbSticks.Left.X > 0 && pad1.ThumbSticks.Left.X > oldLeftX + 0.000001) { take2++; } else if (pad1.ThumbSticks.Left.X < 0 && pad1.ThumbSticks.Left.X < oldLeftX - 0.000001) { take2--; } if (take2 < 1) { take2 = 1; } if (take2 > 9) { take2 = 9; } } if (pad1.Triggers.Left > 0 && oldPad.Triggers.Left == 0) { fire = true; } // if not enought lsu if (lsu - (take + take2 + take3) < 0 && fire == true && oldFire == false) { fire = false; } if (lsu - (take + take2 + take3) < 0) { red = true; } else { red = false; } // moves torpedo if (fire) { fire = true; if (up) { upRect.Y -= 5; // moves by 5s if (upRect.Y <= -51) { upRect.Y = 130; fire = false; } } else if (down) { downRect.Y += 5; if (downRect.Y >= 480) { downRect.Y = 290; fire = false; } } else if (right) { rightRect.X += 5; if (rightRect.X >= 800) { rightRect.X = 440; fire = false; } } else if (left) { leftRect.X -= 5; if (leftRect.X <= -50) { leftRect.X = 280; fire = false; } } } // phasor color if (pad1.Buttons.X == ButtonState.Pressed && !pFire) { pColor = Color.Blue; } else if (pad1.Buttons.Y == ButtonState.Pressed && !pFire) { pColor = Color.Yellow; } else if (pad1.Buttons.B == ButtonState.Pressed && !pFire) { pColor = Color.Red; } else if (pad1.Buttons.A == ButtonState.Pressed && !pFire) { pColor = Color.Green; } if (pad1.Triggers.Right > 0 && oldPad.Triggers.Right == 0) { pFire = true; } if (pTimer == 60) // on screen for 1 sec { pFire = false; pTimer = 0; } // remove lsu when start if (fire == true && oldFire == false) { removeLsu = true; } // update vars oldFire = fire; oldLeftY = pad1.ThumbSticks.Left.Y; oldLeftX = pad1.ThumbSticks.Left.X; oldPad = pad1; base.Update(gameTime); }
protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); State = MouseState.None; Invalidate(); }
// protected override void Update(GameTime gameTime) { timeSinceLastClick += gameTime.ElapsedGameTime.Milliseconds; // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } if (world == null) { world = new World(gruntSprite, assassinSprite, tankSprite, bulletSprite, towerSprite, trapSprite, gr1, gr2, ar1, ar2, tr1, tr2, font, healthBar, ti, tii, tri, trii, towerSpriteIn, trapSpriteIn); opening = new List <Texture2D>(); opening.Add(c1p1); opening.Add(c1p2); opening.Add(c1p3); opening.Add(c1p4); opening.Add(c1p4); opening.Add(c1p5); opening.Add(c1p6); ending = new List <Texture2D>(); ending.Add(e1); ending.Add(e2); ending.Add(e3); ending.Add(e4); ending.Add(e5); ending.Add(e6); ending.Add(e7); ending.Add(e8); ending.Add(e9); ending.Add(e10); ending.Add(e11); ending.Add(e12); ending.Add(e5); ending.Add(c1p1); ending.Add(c1p2); } // TODO: Add your update logic here mouseLocation = new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1); if (world.won || world.lost) { //timeSinceLastClick = 0.0f; gameState = GameStates.Ending; } if (gameState == GameStates.StartScreen) { if (MediaPlayer.State == MediaState.Stopped) { MediaPlayer.Play(menuTheme); } MouseState mouseState = Mouse.GetState(); if (mouseState.LeftButton == ButtonState.Pressed && timeSinceLastClick >= minTimeBetweenClicks) { timeSinceLastClick = 0.0f; if (mouseLocation.Intersects(play)) { gameState = GameStates.Opening; //menuSelect.Play(); //playVA(); } else if (mouseLocation.Intersects(creditsR)) { gameState = GameStates.Credits; //menuSelect.Play(); } else if (mouseLocation.Intersects(quit)) { //menuSelect.Play(); this.Exit(); } } } else if (gameState == GameStates.Opening) { if (openingFrame == 3) { //playVA(); } if (Mouse.GetState().LeftButton == ButtonState.Pressed && timeSinceLastClick >= minTimeBetweenClicks) { timeSinceLastClick = 0.0f; openingFrame++; if (openingFrame > 6) { openingFrame = 1; gameState = GameStates.HowToPlay; } } } else if (gameState == GameStates.Ending) { if (endingFrame == 3 || endingFrame == 6 || endingFrame == 9 || endingFrame == 12) { //playVA(); } if (Mouse.GetState().LeftButton == ButtonState.Pressed && timeSinceLastClick >= minTimeBetweenClicks) { timeSinceLastClick = 0.0f; endingFrame++; if (endingFrame > 15) { //endingFrame = 1; gameState = GameStates.Credits; } } } else if (gameState == GameStates.HowToPlay) { if (Mouse.GetState().LeftButton == ButtonState.Pressed && timeSinceLastClick >= minTimeBetweenClicks) { timeSinceLastClick = 0.0f; gameState = GameStates.Playing; //MediaPlayer.Stop(); } } else if (gameState == GameStates.Credits) { if (Mouse.GetState().LeftButton == ButtonState.Pressed && timeSinceLastClick >= minTimeBetweenClicks) { timeSinceLastClick = 0.0f; gameState = GameStates.StartScreen; } } else if (gameState == GameStates.Playing) { if (MediaPlayer.State == MediaState.Stopped) { MediaPlayer.Play(gameMusic); } timeSinceLastClick = 0.0f; MouseState mouseState = Mouse.GetState(); KeyboardState keyState = Keyboard.GetState(); if (mouseState.LeftButton == ButtonState.Pressed || keyState.IsKeyDown(Keys.D1)) { world.addTower(new Rectangle(mouseState.X, mouseState.Y, 64, 64), mouseState); } if (mouseState.RightButton == ButtonState.Pressed || keyState.IsKeyDown(Keys.D2)) { world.addTrap(new Rectangle(mouseState.X, mouseState.Y, 32, 32), mouseState); } world.update(gameTime); } base.Update(gameTime); }
public override string OnUpdate(GameTime gameTime, KeyboardState keyState, MouseState mouseState) { // Update network stuff. (Sm as InfiniminerGame).UpdateNetwork(gameTime); // Update the current screen effect. P.screenEffectCounter += gameTime.ElapsedGameTime.TotalSeconds; // Update engines. skyplaneEngine.Update(gameTime); playerEngine.Update(gameTime); interfaceEngine.Update(gameTime); particleEngine.Update(gameTime); // Count down the tool cooldown. if (P.PlayerContainer.PlayerToolCooldown > 0) { P.PlayerContainer.PlayerToolCooldown -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (P.PlayerContainer.PlayerToolCooldown <= 0) { P.PlayerContainer.PlayerToolCooldown = 0; } } // Moving the mouse changes where we look. if (Sm.WindowHasFocus()) { if (mouseInitialized) { int dx = mouseState.X - Sm.GraphicsDevice.Viewport.Width / 2; int dy = mouseState.Y - Sm.GraphicsDevice.Viewport.Height / 2; if ((Sm as InfiniminerGame).InvertMouseYAxis) { dy = -dy; } P.PlayerContainer.PlayerCamera.Yaw -= dx * P.SettingsContainer.MouseSensitivity; P.PlayerContainer.PlayerCamera.Pitch = (float)Math.Min(Math.PI * 0.49, Math.Max(-Math.PI * 0.49, P.PlayerContainer.PlayerCamera.Pitch - dy * P.SettingsContainer.MouseSensitivity)); } else { mouseInitialized = true; } Mouse.SetPosition(Sm.GraphicsDevice.Viewport.Width / 2, Sm.GraphicsDevice.Viewport.Height / 2); } else { mouseInitialized = false; } // Digging like a freaking terrier! Now for everyone! if (mouseInitialized && mouseState.LeftButton == ButtonState.Pressed && !P.PlayerContainer.PlayerDead && P.PlayerContainer.PlayerToolCooldown == 0 && P.PlayerContainer.PlayerTools[P.PlayerContainer.PlayerToolSelected] == PlayerTools.Pickaxe) { P.FirePickaxe(); P.PlayerContainer.PlayerToolCooldown = P.GetToolCooldown(PlayerTools.Pickaxe) * (P.PlayerContainer.PlayerClass == PlayerClass.Miner ? 0.4f : 1.0f); } // Prospector radar stuff. if (!P.PlayerContainer.PlayerDead && P.PlayerContainer.PlayerToolCooldown == 0 && P.PlayerContainer.PlayerTools[P.PlayerContainer.PlayerToolSelected] == PlayerTools.ProspectingRadar) { float oldValue = P.PlayerContainer.RadarValue; P.ReadRadar(ref P.PlayerContainer.RadarDistance, ref P.PlayerContainer.RadarValue); if (P.PlayerContainer.RadarValue != oldValue) { if (P.PlayerContainer.RadarValue == 200) { P.PlaySound(InfiniminerSound.RadarLow); } if (P.PlayerContainer.RadarValue == 1000) { P.PlaySound(InfiniminerSound.RadarHigh); } } } // Update the player's position. if (!P.PlayerContainer.PlayerDead) { UpdatePlayerPosition(gameTime, keyState); } // Update the camera regardless of if we're alive or not. P.UpdateCamera(gameTime); return(nextState); }
/// <summary> /// マウスの座標取得 /// </summary> /// <returns></returns> public Vector2 MouseVector2() { MouseState mouseState = Mouse.GetState(); return(new Vector2(mouseState.X, mouseState.Y)); }
//Added November 26, 2013 //Handles all the input for controller and keyboard private void getInput(KeyboardState keyboardState, GamePadState gamePadState, MouseState mouseState, GameTime gameTime) { //Horizontal movement float stickInput = gamePadState.ThumbSticks.Left.X * MOVE_STICK_SCALE; if (gamePadState.IsConnected) { m_Input.getControllerInput(gamePadState); if (m_Input.m_WasMoveRightButtonDown == true || m_Input.m_WasMoveLeftButtonDown == true) { if (stickInput != 0.0f) { m_Speed = START_SPEED * Math.Abs(stickInput); } else { m_Speed = START_SPEED; } } } else { m_Speed = START_SPEED; m_Input.getKeyBoardInput(keyboardState, mouseState); } #region Button Is Up if (m_Input.m_WasMoveLeftButtonDown == false && m_Input.m_WasMoveRightButtonDown == false && m_Input.m_WasJumpButtonDown == false) { m_Particles.Stop = true; if (m_LastFacing == Facing.RIGHT) { m_Facing = Facing.RIGHT; m_Animate.changAnimation((int)Animations.IDLERIGHT); } else if (m_LastFacing == Facing.LEFT) { m_Facing = Facing.LEFT; m_Animate.changAnimation((int)Animations.IDLELEFT); } } if (m_Input.m_WasJumpButtonDown == false) { m_IsJumping = false; if (m_Facing == Facing.LEFT) { //m_Animate.changAnimation((int)Facing.LEFT); } else if (m_Facing == Facing.RIGHT) { //m_Animate.changAnimation((int)Facing.RIGHT); } } if (m_Input.m_WasRainbowButtonDown == false) { //TODO: Rainbow Teleport logic } if (m_Input.m_WasAttackButtonDown == false) { //TODO: Laser Projectile logic } #endregion #region Button Is Down if (m_Input.m_WasMoveLeftButtonDown == true && m_Input.m_WasJumpButtonDown == false) { //Added November 27, 2013 m_Particles.Stop = false; m_Facing = Facing.LEFT; m_Animate.changAnimation((int)Animations.RUNNINGLEFT); } else if (m_Input.m_WasMoveRightButtonDown == true && m_Input.m_WasJumpButtonDown == false) { //Added November 27, 2013 m_Particles.Stop = false; m_Facing = Facing.RIGHT; m_Animate.changAnimation((int)Animations.RUNNINGRIGHT); } if (m_Input.m_WasJumpButtonDown == true && m_Input.m_WasMoveLeftButtonDown == false && m_Input.m_WasMoveRightButtonDown == false) { if (m_IsOnGround == true) { m_IsOnGround = false; m_IsJumping = true; Sounds.playSound("Jump", 1); } if (m_Facing == Facing.LEFT) { m_Animate.changAnimation((int)Animations.JUMPLEFT); } else if (m_Facing == Facing.RIGHT) { m_Animate.changAnimation((int)Animations.JUMPRIGHT); } } if (m_Input.m_WasJumpButtonDown == true && m_Input.m_WasMoveLeftButtonDown == true) { if (m_IsOnGround == true) { m_IsOnGround = false; m_IsJumping = true; Sounds.playSound("Jump", 1); } m_Facing = Facing.LEFT; m_Animate.changAnimation((int)Animations.JUMPLEFT); } else if (m_Input.m_WasJumpButtonDown == true && m_Input.m_WasMoveRightButtonDown == true) { if (m_IsOnGround == true) { m_IsOnGround = false; m_IsJumping = true; Sounds.playSound("Jump", 1); } m_Facing = Facing.RIGHT; m_Animate.changAnimation((int)Animations.JUMPRIGHT); } if (m_Input.m_WasRainbowButtonDown == true) { //TODO: Rainbow Logic } if (m_Input.m_WasAttackButtonDown == true) { laserState(gameTime); } }
protected override void PostUpdate(float state) => _oldState = _state;
/// <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) { PreviousKeyboardInput = KeyboardInput; KeyboardInput = Keyboard.GetState(); var dt = (float)gameTime.ElapsedGameTime.TotalSeconds; #if WINDOWS PreviousMouseInput = MouseInput; MouseInput = Mouse.GetState(); //Keep the mouse within the screen if (!IsMouseVisible) { Mouse.SetPosition(200, 200); } #endif PreviousGamePadInput = GamePadInput; for (int i = 0; i < 4; i++) { GamePadInput = GamePad.GetState((PlayerIndex)i); if (GamePadInput.IsConnected) { break; } } // Allows the default game to exit on Xbox 360 and Windows if (KeyboardInput.IsKeyDown(Keys.Escape) || GamePadInput.Buttons.Back == ButtonState.Pressed) { Exit(); } //Toggle mouse control. The camera will look to the IsMouseVisible to determine if it should turn. if (WasKeyPressed(Keys.Tab)) { IsMouseVisible = !IsMouseVisible; } #region UI Toggles #if !WINDOWS if (WasButtonPressed(Buttons.Start)) { displayMenu = !displayMenu; } #else if (WasKeyPressed(Keys.F1)) { displayMenu = !displayMenu; } #endif if (WasKeyPressed(Keys.I)) { if (KeyboardInput.IsKeyDown(Keys.RightShift) || KeyboardInput.IsKeyDown(Keys.LeftShift)) { displayActiveEntityCount = !displayActiveEntityCount; } else { displayUI = !displayUI; } } if (WasKeyPressed(Keys.J)) { displayConstraints = !displayConstraints; } if (WasKeyPressed(Keys.K)) { displayContacts = !displayContacts; } if (WasKeyPressed(Keys.U)) { displayBoundingBoxes = !displayBoundingBoxes; } if (WasKeyPressed(Keys.Y)) { displayEntities = !displayEntities; } if (WasKeyPressed(Keys.H)) { displaySimulationIslands = !displaySimulationIslands; } if (WasKeyPressed(Keys.G)) { ModelDrawer.IsWireframe = !ModelDrawer.IsWireframe; } #endregion #region Simulation Switcharoo #if !WINDOWS int switchTo = -2; if (WasButtonPressed(Buttons.DPadLeft)) { switchTo = currentSimulationIndex - 1; } else if (WasButtonPressed(Buttons.DPadRight)) { switchTo = currentSimulationIndex + 1; } if (switchTo != -2) { if (switchTo < 1) { switchTo += demoTypes.Length; } else if (switchTo > demoTypes.Length) { switchTo = 1; } SwitchSimulation(switchTo); } #else foreach (Keys key in KeyboardInput.GetPressedKeys()) { int code = key.GetHashCode(); if (code >= 48 && code <= 57) { int simNumber; if (code == 48) { simNumber = 10; } else { simNumber = code - 48; } if (KeyboardInput.IsKeyDown(Keys.LeftShift)) { simNumber += 10; } if (KeyboardInput.IsKeyDown(Keys.LeftControl)) { simNumber += 20; } if (simNumber <= demoTypes.Length) { SwitchSimulation(simNumber); } } } #endif #endregion currentSimulation.Update(dt); if (displayConstraints) { ConstraintDrawer.Update(); } if (displayEntities) { ModelDrawer.Update(); } base.Update(gameTime); }
protected override void PreUpdate(float state) => _state = Mouse.GetState(_window);
public abstract void Update(MouseState mouseState, KeyboardState keyboardState);
public IState UpdateState(ref GameSettings gameSettings, GameTime gameTime, Camera camera, KeyboardState currentKey, KeyboardState prevKey, MouseState currentMouse, MouseState prevMouse) { if (currentKey.IsKeyDown(Keys.Up) && prevKey.IsKeyUp(Keys.Up)) { _selectedOption -= 1; this.HandleOptionChange(-1); } if (currentKey.IsKeyDown(Keys.Down) && prevKey.IsKeyUp(Keys.Down)) { _selectedOption += 1; this.HandleOptionChange(1); } if (currentKey.IsKeyDown(Keys.Enter) && prevKey.IsKeyUp(Keys.Enter)) { switch (_selectedOption) { case (int)Options.UNPAUSE: return(this._previousState); case (int)Options.GAME_SETTINGS: return(new SettingsState(ref gameSettings, this._content, this)); case (int)Options.SAVE: break; case (int)Options.SAVE_AND_QUIT: return(new TitleState(_content)); } } if (currentKey.IsKeyDown(Keys.Escape) && prevKey.IsKeyUp(Keys.Escape)) { return(this._previousState); } return(this); }
/// <summary> /// マウスのワールド座標取得 /// </summary> /// <returns></returns> public Vector2 WorldMouseVector2() { MouseState mouseState = Mouse.GetState(); return(new Vector2(mouseState.X + Camera.CameraMove.X, mouseState.Y + Camera.CameraMove.Y)); }
public override void update(GameTime gameTime) { m_LastFacing = m_Facing; float elapsedTime = (float)gameTime.ElapsedGameTime.Milliseconds / 1000; m_Timer += elapsedTime; m_HealthTimer += elapsedTime; m_StarTimer += elapsedTime; m_RechargeTimer += elapsedTime; //Added November 27, 2013 Vector2 oldPos = new Vector2(m_PlayerPosition.X, m_PlayerPosition.Y); //Added November 26, 2013 KeyboardState keyboardState = Keyboard.GetState(); GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); MouseState mouseState = Mouse.GetState(); CollisionType collisionType = new CollisionType(); if (m_Health == 0) { instantDeath(); } if (m_HealthTimer < HEALTH_DELAY_TIMER) { //TODO: RED SCREEN GET HIT } crossState(gameTime); rechargeLaser(gameTime); m_LaserManager.update(gameTime); getInput(keyboardState, gamePadState, mouseState, gameTime); levelBounds(); runState(gameTime); collectedHeart(); collectedStars(); jumpState(gameTime); m_Position = m_PlayerPosition; //Added November 27, 2013 base.update(gameTime); m_PlayerPosition = m_Position; m_collisionRectangle = Destination; //Added November 27,2013 m_Particles.update(gameTime); m_Particles.SpawnPoint = m_PlayerPosition; m_Particles.DominantDirection = new Vector2(oldPos.X - m_PlayerPosition.X, oldPos.Y - m_PlayerPosition.Y); }
// This method is provided complete as part of the activity starter. private void updatePlaying(GameTime gameTime, KeyboardState currentKeyboard) { // when playing the game, need to track the mouse state MouseState currentMouse = Mouse.GetState(); if (oldMouseState == null) { oldMouseState = currentMouse; } // when the user left-clicks the mouse if (wasLeftMouseButtonPressed(currentMouse)) { // get mouse click position relative to UpperLeft point on board Vector2 clickPosition = new Vector2(currentMouse.X, currentMouse.Y) - overlay.UpperLeft; // assume the mouse click was not on a valid column and row int col = -1; int row = -1; // now check each row and column (0-2) at the same time for (int i = 0; i < GRID_SIZE; i++) { // calculate the min and max coordinate for this cell // (both horizontal and vertical since it's a square!) int bound1 = i * (CELL_SIZE + LINE_WIDTH); int bound2 = bound1 + CELL_SIZE; // see if the X-position was within this cell boundary if ((clickPosition.X >= bound1) && (clickPosition.X < bound2)) { col = i; // yes user clicked on a valid column } // see if the Y-position was within this cell boundary if ((clickPosition.Y >= bound1) && (clickPosition.Y < bound2)) { row = i; // yes user clicked on a valid row } } // if user clicked on a valid row and column if ((col != -1) && (row != -1)) { // if the target cell is currently null (no marker) if (gameboard[col, row] == null) { // create a new marker, store the current player number Marker marker = new Marker(); marker.Player = currentPlayer; // set the marker texter to X or O based on current player if (currentPlayer == 1) { marker.SetTexture(xTexture); } else { marker.SetTexture(oTexture); } // position the marker on the selected square marker.UpperLeft = new Vector2(col * (CELL_SIZE + LINE_WIDTH), row * (CELL_SIZE + LINE_WIDTH)) + overlay.UpperLeft; // store the marker in the 2D array gameboard[col, row] = marker; // change players now that a valid move has been made if (currentPlayer == 1) { currentPlayer = 2; } else { currentPlayer = 1; } } } // see if there is now a winner int winner = checkForWinner(); // if player 1 has won if (winner == 1) { player1Score++; stopGame("Player 1 Wins!"); } else if (winner == 2) // if player 2 has won { player2Score++; stopGame("Player 2 Wins!"); } else if (winner == 3) // if no player won { stopGame("Tie game!"); } } // save old mouse state for next time oldMouseState = currentMouse; }
/// <summary> /// Give a command when click at icons /// </summary> /// <param name="input"></param> /// <param name="gameView"></param> /// <param name="testGameController"></param> private void giveCommand(MouseState input, View gameView, Controller testGameController) { commandX = gameView.convertScreenLocToGameLoc(input.X, input.Y).X; commandY = gameView.convertScreenLocToGameLoc(input.X, input.Y).Y; if (testGameController.isWithinGameBound(commandX, commandY)) { foreach (ZRTSModel.Entities.Entity entity in testGameController.scenario.getPlayer().SelectedEntities) { switch (currentPlayerCommand) { // Move command case PlayerCommand.MOVE: testGameController.giveActionCommand(entity, new ZRTSLogic.Action.MoveAction(commandX, commandY, testGameController.gameWorld, entity)); break; // Cancel command case PlayerCommand.CANCEL: // TODO: Cancel current action break; // Attack command // TODO: Animation of the attack case PlayerCommand.ATTACK: if (entity.entityType == ZRTSModel.Entities.Entity.EntityType.Unit) { // Select Unit at the clicked Cell. ZRTSModel.Entities.Entity temp = testGameController.scenario.getUnit((int)commandX, (int)commandY); // If there is no Unit, select the StaticEntity on the Cell. if (temp == null) { temp = testGameController.scenario.getGameWorld().map.getCell((int)commandX, (int)commandY).entity; } // If there is an Entity on the Cell. if (temp != null) { System.Console.Out.WriteLine("Selected Attack at " + commandX + ":" + commandY); testGameController.giveActionCommand(entity, new ZRTSLogic.Action.SimpleAttackAction((ZRTSModel.Entities.Unit)entity, temp)); } } break; // Build command case PlayerCommand.BUILD: if (testGameController.makeUnitBuild(entity, new ZRTSModel.Entities.Building(testGameController.scenario.getPlayer(), new ZRTSModel.Entities.BuildingStats()), testGameController.gameWorld.map.getCell((int)commandX, (int)commandY))) { System.Console.Out.WriteLine("Building at " + commandX + ":" + commandY); } else { System.Console.Out.WriteLine("Can't place a building at " + commandX + ":" + commandY); } break; } } } }
protected override void Update(GameTime gameTime) { if (IsActive) { prKeyState = keyState; prMouState = mouState; keyState = Keyboard.GetState(); mouState = Mouse.GetState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { Exit(); } motion = Vector2.Zero; if (keyState.IsKeyDown(Keys.Up)) { ScrollUp(); } if (keyState.IsKeyDown(Keys.Left)) { ScrollLeft(); } if (keyState.IsKeyDown(Keys.Down)) { ScrollDown(); } if (keyState.IsKeyDown(Keys.Right)) { ScrollRight(); } if (keyState.IsKeyDown(Keys.S) && prKeyState.IsKeyUp(Keys.S) && Menu.SelTrain != null) { Menu.SelTrain.Destination = null; } if (mouState.X >= 0 && mouState.Y >= 0 && mouState.X < Main.ScreenWidth && mouState.Y < Main.ScreenHeight) { if (mouState.Y < Main.ScreenHeight - 48) { if (mouState.RightButton == ButtonState.Pressed && prMouState.RightButton == ButtonState.Released && Menu.SelTrain != null) { Point p = GetPos(8, mouState.X + Camera.Position.X, mouState.Y + Camera.Position.Y); if (GetTileType(p.X / 3, p.Y / 3) > -1) { Menu.SelTrain.SetDestination(p.X, p.Y); } } if (mouState.LeftButton == ButtonState.Pressed) { if (Menu.Screen == 0) { Point p = GetPos(24, mouState.X + Camera.Position.X, mouState.Y + Camera.Position.Y); if (GetTileType(p.X, p.Y) > -1 && GetTileType(p.X, p.Y) != Menu.SelType) { map.SetMapPiece(p.X, p.Y, (MyMap.Turn)Menu.SelType); } } else if (Menu.Screen == 1) { Menu.SelTrain = null; foreach (Train t in objects) { if (t.Team == MyTeam && Offset(t.DBox, -Main.defSize / 2, -Main.defSize / 2).Contains(mouState.X, mouState.Y)) { Menu.SelTrain = t; break; } } } } } else if (mouState.LeftButton == ButtonState.Pressed && prMouState.LeftButton == ButtonState.Released) { for (byte i = 0; i < 13; ++i) { if (new Rectangle(i * 50 + 82, Main.ScreenHeight - 32, 32, 32).Contains(mouState.X, mouState.Y)) { if (Menu.Screen == 0) { if (i > 0) { Menu.SelType = (byte)(i - 1); } else { Menu.Screen = 1; } } else if (Menu.Screen == 1) { switch (i) { case 0: Menu.Screen = 0; break; case 1: map.Generate(map.Width, map.Height); Menu.SetText("Map cleared!"); break; case 2: map.LoadMap("Map"); Menu.SetText("Map loaded!"); break; case 3: map.SaveMap("Map"); Menu.SetText("Map saved!"); break; case 4: map.Randomize(); Menu.SetText("Map randomized!"); break; case 5: Menu.W = (short)map.Width; Menu.H = (short)map.Height; Menu.Screen = 2; break; } } else if (Menu.Screen == 2) { switch (i) { case 0: Menu.Screen = 1; break; case 4: --Menu.W; break; case 5: ++Menu.W; break; case 9: --Menu.H; break; case 10: ++Menu.H; break; case 11: Menu.Screen = 1; map.Generate(Menu.W, Menu.H); Menu.SetText("New map created!"); break; } } break; } } } } if (motion != Vector2.Zero) { motion.Normalize(); Camera.Position += motion * Camera.Speed; } foreach (GameObj obj in objects) { obj.Update(); } base.Update(gameTime); } }
public static void Update() { //==================================================Mouse lastMouse = curMouse; curMouse = Mouse.GetState(); if (lastMouse == null) { return; } //left if (curMouse.LeftButton == ButtonState.Pressed && lastMouse.LeftButton == ButtonState.Released) { if (onButtonDown != null) { onButtonDown(new MouseArgs() { curState = curMouse, button = 0 }); eventHandled = false; } } if (curMouse.LeftButton == ButtonState.Released && lastMouse.LeftButton == ButtonState.Pressed) { if (onButtonUp != null) { onButtonUp(new MouseArgs() { curState = curMouse, button = 0 }); eventHandled = false; } } //right if (curMouse.RightButton == ButtonState.Pressed && lastMouse.RightButton == ButtonState.Released) { if (onButtonDown != null) { onButtonDown(new MouseArgs() { curState = curMouse, button = 1 }); eventHandled = false; } } if (curMouse.RightButton == ButtonState.Released && lastMouse.RightButton == ButtonState.Pressed) { if (onButtonUp != null) { onButtonUp(new MouseArgs() { curState = curMouse, button = 1 }); eventHandled = false; } } //==================================================KB lastKeyboard = curKeyboard; curKeyboard = Keyboard.GetState(); if (lastKeyboard == null) { return; } for (int i = 0; i < 256; i++) { if (curKeyboard.IsKeyDown((Keys)i) != lastKeyboard.IsKeyDown((Keys)i)) { if (curKeyboard.IsKeyDown((Keys)i)) { if (onKeyDown != null) { onKeyDown(new KeyboardArgs() { curState = curKeyboard, key = i }); eventHandled = false; } } else { if (onKeyUp != null) { onKeyUp(new KeyboardArgs() { curState = curKeyboard, key = i }); eventHandled = false; } } } } }
public MouseEvents(MouseButton button, MouseState currState, MouseState prevState) { CurrState = currState; PrevState = prevState; Button = button; }
public UnfocusedMouseState(MouseState tkState, bool active, Vector2?mappedPosition) : base(tkState, active, mappedPosition) { }
protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); State = MouseState.Over; Invalidate(); }
public virtual bool MouseMove(MouseState mouse) { return(false); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); State = MouseState.Down; Invalidate(); }
/// <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) { timer += (float)gameTime.ElapsedGameTime.TotalSeconds; // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } if (moorhuener_liste.Count < 20) { if (timer >= 0.5f) { int i = rnd.Next(0, 2); sprite = new AnimatedSprite(texturen[i], 2, 5); moorhuener = new Moorhuener(sprite, rnd); moorhuener_liste.AddFirst(moorhuener); sprite_liste.AddFirst(sprite); timer = 0; Console.WriteLine(i); } } sprite.Update(); foreach (AnimatedSprite a in sprite_liste) { a.Update(); } //foreach (AnimatedSprite a in fallende_huener_liste) //{ // a.Update(); //} if (moorhuener_liste.Count >= 19) { moorhuener_liste.RemoveLast(); sprite_liste.RemoveLast(); } mouse_alt = mouse; mouse = Mouse.GetState(); Rectangle rechteck_mouse = new Rectangle(mouse.X, mouse.Y, 1, 1); List <Moorhuener> abgeschossen = new List <Moorhuener>(); List <Moorhuener> druassen = new List <Moorhuener>(); foreach (Moorhuener a in moorhuener_liste) { if (a.Huhn.Texture == texturen[0]) { a.Position.X += 4.0f; Rectangle rechteck_huhn = new Rectangle((int)a.Position.X, (int)a.Position.Y, a.Huhn.breite, a.Huhn.hoehe); if (a.Position.X <= 1000) { if (rechteck_huhn.Intersects(rechteck_mouse)) { if (mouse.LeftButton == ButtonState.Pressed && mouse_alt.LeftButton == ButtonState.Released) { abgeschossen.Add(a); // fallende_huener_liste.AddFirst(erschossenesHuhn); } } } else { druassen.Add(a); } } else if (a.Huhn.Texture == texturen[1]) { a.Position.X -= 4.0f; Rectangle rechteck_huhn = new Rectangle((int)a.Position.X, (int)a.Position.Y, a.Huhn.breite, a.Huhn.hoehe); if (a.Position.X <= 1000) { if (rechteck_huhn.Intersects(rechteck_mouse)) { if (mouse.LeftButton == ButtonState.Pressed && mouse_alt.LeftButton == ButtonState.Released) { abgeschossen.Add(a); // fallende_huener_liste.AddFirst(erschossenesHuhn); } } } else { druassen.Add(a); } } } foreach (Moorhuener i in druassen) { moorhuener_liste.Remove(i); } foreach (Moorhuener i in abgeschossen) { if (i.Huhn.Texture == texturen[0]) { counter += 5; } else if (i.Huhn.Texture == texturen[1]) { counter += 10; // sprite = new AnimatedSprite(texturen[2], 2, 2); //moorhuener = new Moorhuener(sprite, rnd); } else { counter += 20; } moorhuener_liste.Remove(i); } Rectangle rechteck_fadenkreuz = new Rectangle((int)mousePosition.X, (int)mousePosition.Y, fadenkreuz.Width, fadenkreuz.Height); if (mouse.X != rechteck_fadenkreuz.X && mouse.Y != rechteck_fadenkreuz.Y) { mousePosition = new Vector2(mouse.X - (fadenkreuz.Width / 2), mouse.Y - (fadenkreuz.Height / 2)); } if (mouse.LeftButton == ButtonState.Pressed && mouse_alt.LeftButton == ButtonState.Released) { schuesse -= 1; if (schuesse == 0) { magazin_leer = true; } } KeyboardState keyboard = Keyboard.GetState(); if (keyboard.IsKeyDown(Keys.R)) { if (schuesse <= 0) { magazin_leer = false; schuesse = 8; } } // TODO: Add your update logic here base.Update(gameTime); }
public Vector2 ClientMouseCoordinate(MouseState mouse) { return(ClientCoordinate(new Vector2(mouse.X, mouse.Y))); }
public EntityGenerationController() { oldState = Keyboard.GetState(); oldMouseState = Mouse.GetState(); isListening = false; }
/// <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) { this.Exit(); } // STUDENTS: get current mouse state and update teddy MouseState mouse = Mouse.GetState(); teddy.Update(gameTime, mouse); // check for right click started if (mouse.RightButton == ButtonState.Pressed && rightButtonReleased) { rightClickStarted = true; rightButtonReleased = false; } else if (mouse.RightButton == ButtonState.Released) { rightButtonReleased = true; // if right click finished, add new pickup to list if (rightClickStarted) { rightClickStarted = false; // STUDENTS: add a new pickup to the end of the list of pickups Vector2 target = new Vector2(mouse.X, mouse.Y); targets.Add(target); pickups.Add(new Pickup(pickupSprite, target)); // STUDENTS: if this is the first pickup in the list, set teddy target teddy.SetTarget(targets[0]); } } // STUDENTS: Delete the line saying if (true) and uncomment the three // lines below that AFTER you've created a teddy object in the // LoadContent method // check for collision between collecting teddy and targeted pickup //if (true) if (teddy.Collecting && pickups.Count > 0 && teddy.CollisionRectangle.Intersects(pickups[0].CollisionRectangle)) { // STUDENTS: remove targeted pickup from list (it's always at location 0) pickups.RemoveAt(0); targets.RemoveAt(0); // STUDENTS: if there's another pickup to collect, set teddy target // If not, stop the teddy from collecting if (pickups.Any()) { //Vector2 target = new Vector2(mouse.X, mouse.Y); teddy.SetTarget(targets[0]); } else { teddy.Collecting = false; } } base.Update(gameTime); }
protected override void Update(GameTime gameTime) { if (!this.IsActive || Settings.GUI.Visible) { this.mouseAim = false; } else { Vector3 zero = Vector3.Zero; MouseState state1 = Mouse.GetState(); if (!Settings.GUI.Visible && state1.LeftButton == ButtonState.Pressed && this.mouseState.LeftButton == ButtonState.Released) { this.mouseState = Mouse.GetState(); if (this.showColorWheel && new Rectangle((int)this.colorWheelLocation.X, (int)this.colorWheelLocation.Y, this.colorWheel.Width, this.colorWheel.Height).Contains(new Point(this.mouseState.X, this.mouseState.Y))) { Color[] data = new Color[this.colorWheel.Width * this.colorWheel.Height]; this.colorWheel.GetData <Color>(data); int index = this.mouseState.X + this.mouseState.Y * this.colorWheel.Width; if (index < data.Length) { this.selectedColor = data[index]; } } else { this.mouseAim = !this.mouseAim; } } if (this.mouseAim) { this.camera.Yaw -= (float)(state1.X - this.mouseState.X) * (1f / 500f); this.camera.Pitch -= (float)(state1.Y - this.mouseState.Y) * (1f / 500f); this.camera.Zoom += (float)(this.mouseState.ScrollWheelValue - state1.ScrollWheelValue) * 0.05f; Viewport viewport = this.GraphicsDevice.Viewport; int x = viewport.Width / 2; viewport = this.GraphicsDevice.Viewport; int y = viewport.Height / 2; Mouse.SetPosition(x, y); } this.mouseState = Mouse.GetState(); KeyboardState state2 = Keyboard.GetState(); foreach (Keys pressedKey in state2.GetPressedKeys()) { switch (pressedKey) { case Keys.S: case Keys.End: case Keys.Down: this.camera.Pitch -= 0.025f; break; case Keys.W: case Keys.Home: case Keys.Up: this.camera.Pitch += 0.025f; break; case Keys.LeftShift: --this.camera.Zoom; break; case Keys.Space: ++this.camera.Zoom; break; case Keys.PageDown: case Keys.Right: case Keys.D: this.camera.Yaw -= 0.025f; break; case Keys.Left: case Keys.Delete: case Keys.A: this.camera.Yaw += 0.025f; break; } } if (state2.IsKeyDown(Keys.Tab) && !this.keyboardState.IsKeyDown(Keys.Tab)) { this.CurrentRasterizeState = this.CurrentRasterizeState == this.WireframeRasterizeState ? this.FillRasterizeState : this.WireframeRasterizeState; } if (state2.IsKeyDown(Keys.F10) && !this.keyboardState.IsKeyDown(Keys.F10)) { int backBufferWidth = this.GraphicsDevice.PresentationParameters.BackBufferWidth; int backBufferHeight = this.GraphicsDevice.PresentationParameters.BackBufferHeight; this.Draw(new GameTime()); int[] data = new int[backBufferWidth * backBufferHeight]; this.GraphicsDevice.GetBackBufferData <int>(data); Texture2D texture2D = new Texture2D(this.GraphicsDevice, backBufferWidth, backBufferHeight, false, this.GraphicsDevice.PresentationParameters.BackBufferFormat); texture2D.SetData <int>(data); Stream stream = (Stream)File.OpenWrite("Screenshots/" + (object)Environment.TickCount + ".jpg"); texture2D.SaveAsJpeg(stream, backBufferWidth, backBufferHeight); stream.Dispose(); texture2D.Dispose(); } if (state2.IsKeyDown(Keys.F1) && !this.keyboardState.IsKeyDown(Keys.F1)) { Settings.GUI.Show(); } if (state2.IsKeyDown(Keys.F5) && !this.keyboardState.IsKeyDown(Keys.F5)) { System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); string str = (Settings.Conquer_Path + "c3/weapon/").Replace('/', '\\'); openFileDialog.InitialDirectory = str; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Settings.Scene.LoadModel(openFileDialog.FileName); this.centerCamera(); } } if (state2.IsKeyDown(Keys.F2) && !this.keyboardState.IsKeyDown(Keys.F2)) { System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Settings.Scene.LoadModel(openFileDialog.FileName); this.centerCamera(); } } if (state2.IsKeyDown(Keys.F3) && !this.keyboardState.IsKeyDown(Keys.F3)) { System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (Settings.GUI.SelectedModel == null) { Settings.GUI.SelectedModel = Settings.Scene.Models.FirstOrDefault <GameModel>(); } if (Settings.GUI.SelectedModel != null) { DDSLib.DDSFromFile(openFileDialog.FileName, this.GraphicsDevice, false, out Settings.GUI.SelectedModel.Texture); } } } if (state2.IsKeyDown(Keys.F12) && !this.keyboardState.IsKeyDown(Keys.F12)) { Settings.Scene = new GameScene(); Settings.GUI = new Manager(); } foreach (GameModel model in Settings.Scene.Models) { foreach (Physics physicalObject in model.PhysicalObjects) { if (physicalObject.Motion != null && DateTime.Now > this.nextFrame) { this.nextFrame = DateTime.Now.AddMilliseconds(30.0); physicalObject.FrameIndex = (physicalObject.FrameIndex + 1) % physicalObject.Motion.KeyFrames.Count; } if (!(physicalObject.UV_Step == Vector2.Zero)) { foreach (Vertex normalVertex in physicalObject.NormalVertexes) { normalVertex.UV += physicalObject.UV_Step; } foreach (Vertex alphaVertex in physicalObject.AlphaVertexes) { alphaVertex.UV += physicalObject.UV_Step; } } } } this.keyboardState = state2; base.Update(gameTime); } }
public override void Update(MouseState mouseState, KeyboardState keyboardState) { }
void UpdateCamera() { float c1 = 1; float c2 = 30; // Get the new keyboard and mouse state MouseState mouseState = Mouse.GetState(); KeyboardState keyState = Microsoft.Xna.Framework.Input.Keyboard.GetState(); // Determine how much the camera should turn float deltaX = (float)lastMouseState.X - (float)mouseState.X; float deltaY = (float)lastMouseState.Y - (float)mouseState.Y; float vX = 0; float vY = 0; if (mouseState.X > 0.9 * width) { vX = -1; } else if (mouseState.X < 0.1 * width) { vX = 1; } if (mouseState.Y > 0.9 * height) { vY = -1; } else if (mouseState.Y < 0.1 * height) { vY = 1; } //WriteLine(deltaX); //WriteLine(deltaY); if (scene.Camera is FreeFlyCamera) { FreeFlyCamera camera = scene.Camera as FreeFlyCamera; // Rotate the camera camera.RotateLeftRight((c1 * deltaX + c2 * vX) * .0005f); camera.RotateUpDown(-(c1 * deltaY + c2 * vY) * .0005f); // Determine in which direction to move the camera if (keyState.IsKeyDown(Key.W)) { camera.Move(1, 0); } if (keyState.IsKeyDown(Key.S)) { camera.Move(-1, 0); } if (keyState.IsKeyDown(Key.A)) { camera.Move(0, 1); } if (keyState.IsKeyDown(Key.D)) { camera.Move(0, -1); } // Update the camera camera.Update(); } else if (scene.Camera is OneAxisLevelFlyCamera) { OneAxisLevelFlyCamera camera = scene.Camera as OneAxisLevelFlyCamera; // Rotate the camera camera.RotateLeftRight((c1 * deltaX + c2 * vX) * .0005f); camera.RotateUpDown(-(c1 * deltaY + c2 * vY) * .0005f); // Determine in which direction to move the camera if (keyState.IsKeyDown(Key.W)) { camera.Move(1, 0); } if (keyState.IsKeyDown(Key.S)) { camera.Move(-1, 0); } if (keyState.IsKeyDown(Key.A)) { camera.Move(0, 1); } if (keyState.IsKeyDown(Key.D)) { camera.Move(0, -1); } // Update the camera camera.Update(); } else if (scene.Camera is TwoAxesLevelFlyCamera) { TwoAxesLevelFlyCamera camera = scene.Camera as TwoAxesLevelFlyCamera; // Rotate the camera camera.RotateLeftRight((c1 * deltaX + c2 * vX) * .0005f); camera.RotateUpDown(-(c1 * deltaY + c2 * vY) * .05f); // Determine in which direction to move the camera if (keyState.IsKeyDown(Key.W)) { camera.Move(1, 0); } if (keyState.IsKeyDown(Key.S)) { camera.Move(-1, 0); } if (keyState.IsKeyDown(Key.A)) { camera.Move(0, 1); } if (keyState.IsKeyDown(Key.D)) { camera.Move(0, -1); } // Update the camera camera.Update(); } // Update the mouse state lastMouseState = mouseState; }