/** <summary> Returns true if the control is up. </summary> */ public override bool Up() { return((Ctrl != (Keyboard.IsKeyDown(Keys.LCtrl) || Keyboard.IsKeyDown(Keys.RCtrl))) || (Shift != (Keyboard.IsKeyDown(Keys.LShift) || Keyboard.IsKeyDown(Keys.RShift))) || (Alt != (Keyboard.IsKeyDown(Keys.LAlt) || Keyboard.IsKeyDown(Keys.RAlt))) || Keyboard.IsKeyUp(KeyCode)); }
/** <summary> Returns true if the control was released. </summary> */ public override bool Released() { return((Ctrl == (Keyboard.IsKeyDown(Keys.LCtrl) || Keyboard.IsKeyDown(Keys.RCtrl))) && (Shift == (Keyboard.IsKeyDown(Keys.LShift) || Keyboard.IsKeyDown(Keys.RShift))) && (Alt == (Keyboard.IsKeyDown(Keys.LAlt) || Keyboard.IsKeyDown(Keys.RAlt))) && Keyboard.IsKeyReleased(KeyCode)); }
// Allows the game to perform any initialization it needs to before starting to run. // This is where it can query for any required services and load any non-graphic // related content. Calling base.Initialize will enumerate through any components // and initialize them as well. protected override void Initialize() { Console.WriteLine("Begin Initialize"); Console.WriteLine("Initializing Input"); Keyboard.Initialize(); Mouse.Initialize(); GamePad.Initialize(); game = new GameManager(launchParameters); base.Initialize(); if (!isContentLoaded) { // BAD STUFF. Exit(); return; } // Create and initialize the game. game.Initialize(this); Window.ClientSizeChanged += OnClientSizeChanged; Console.WriteLine("End Initialize"); }
//----------------------------------------------------------------------------- // Updating //----------------------------------------------------------------------------- // Called every step to update the game. public void Update(float timeDelta) { //prop.Update(1.0 / 60.0, new Point2I(ScreenSize.X - Property<int>.Width, ScreenSize.Y / 2)); //if (Keyboard.IsKeyPressed(Keys.F4)) // GameBase.IsFullScreen = !GameBase.IsFullScreen; // Update the menu Controls.Update(); // Toggle debug mode if (Keyboard.IsKeyPressed(Keys.F2) || (GamePad.IsButtonDown(Buttons.Back) && GamePad.IsButtonPressed(Buttons.RightStickButton))) { debugMode = !debugMode; } // Update the game-state stack. if (!isGamePaused) { gameStateStack.Update(); } elapsedTicks++; // DEBUG: Update debug keys. GameDebug.GameControl = gameControl; GameDebug.UpdateRoomDebugKeys(); }
//=========== UPDATING =========== #region Updating /** <summary> Updates the debug menu while it's open. </summary> */ public void Update() { if (Mouse.IsMouseMoved()) { if (Mouse.GetDistance().Length > 2.0 && mouseHoverItem != null) { controlMode = MenuControlMode.Mouse; } } if (Keyboard.IsKeyPressed(Keys.Left) || Keyboard.IsKeyPressed(Keys.Right) || Keyboard.IsKeyPressed(Keys.Up) || Keyboard.IsKeyPressed(Keys.Down) || Keyboard.IsKeyPressed(Keys.X) || Keyboard.IsKeyPressed(Keys.Z) || Keyboard.IsKeyPressed(Keys.Space) || Keyboard.IsKeyPressed(Keys.Enter) || Keyboard.IsKeyPressed(Keys.Escape)) { controlMode = MenuControlMode.Keyboard; } else if (GamePad.IsButtonPressed(Buttons.DPadLeft) || GamePad.IsButtonPressed(Buttons.DPadRight) || GamePad.IsButtonPressed(Buttons.DPadUp) || GamePad.IsButtonPressed(Buttons.DPadDown) || GamePad.IsButtonPressed(Buttons.LeftStickLeft) || GamePad.IsButtonPressed(Buttons.LeftStickRight) || GamePad.IsButtonPressed(Buttons.LeftStickUp) || GamePad.IsButtonPressed(Buttons.LeftStickDown) || GamePad.IsButtonPressed(Buttons.A) || GamePad.IsButtonPressed(Buttons.B) || GamePad.IsButtonPressed(Buttons.Start) || GamePad.IsButtonPressed(Buttons.Back) || GamePad.IsButtonPressed(Buttons.Y)) { controlMode = MenuControlMode.GamePad; } if (controlMode == MenuControlMode.Mouse) { UpdateMouseControls(); } else if (controlMode == MenuControlMode.Keyboard) { UpdateKeyboardControls(); } else { UpdateGamePadControls(); } }
//----------------------------------------------------------------------------- // Updating //----------------------------------------------------------------------------- // Allows the game to run logic such as updating the world, // checking for collisions, gathering input, and playing audio. protected override void Update(GameTime gameTime) { if (!isContentLoaded) { Exit(); return; } // Update the fullscreen mode. UpdateFullScreen(); if (windowSizeChanged) { game.ScreenResized(); windowSizeChanged = false; } // Update the frame rate. UpdateFrameRate(gameTime); // Update the listeners. if (Form.Focused) { Keyboard.Enable(); GamePad.Enable(); Mouse.Enable(); Keyboard.Update(gameTime); GamePad.Update(gameTime); Mouse.Update(gameTime, (IsFullScreen ? -new Vector2F(Window.ClientBounds.Location) : Vector2F.Zero)); } else { Keyboard.Disable(false); GamePad.Disable(false); Mouse.Disable(false); } AudioSystem.Update(gameTime); // Update the game logic. //game.Update((float) gameTime.ElapsedGameTime.TotalSeconds); // DEBUG: Hold 1 to speed up the game. if (Keyboard.IsKeyDown(Keys.D1)) { for (int i = 0; i < 16; i++) { game.Update((float)gameTime.ElapsedGameTime.TotalSeconds); } } // DEBUG: Hold 2 to slow down the game. else if (Keyboard.IsKeyDown(Keys.D2)) { slowTimer++; if (slowTimer >= 10) { slowTimer = 0; game.Update((float)gameTime.ElapsedGameTime.TotalSeconds); } } else { // Update the game logic. game.Update((float)gameTime.ElapsedGameTime.TotalSeconds); } base.Update(gameTime); // Update screenshot requests. UpdateScreenShot(); //windowSizeChanged = false; }
public override bool Up() { return(Keyboard.IsKeyUp(KeyCode)); }
public override bool Down() { return(Keyboard.IsKeyDown(KeyCode)); }
public override bool Released() { return(Keyboard.IsKeyReleased(KeyCode)); }
public override bool Pressed() { return(Keyboard.IsKeyPressed(KeyCode)); }
/** <summary> Updates the debug menu with keyboard controls. </summary> */ private void UpdateKeyboardControls() { Keys keyNextItem = Keys.Down; Keys keyPrevItem = Keys.Up; Keys keyStepInto = Keys.Right; Keys keyStepOut = Keys.Left; if (currentItem.Root.Root == null) { keyNextItem = Keys.Right; keyPrevItem = Keys.Left; keyStepInto = Keys.Down; keyStepOut = Keys.Up; } // Select next root menu item. if (Keyboard.IsKeyPressed(Keys.Right) && currentItem.Items.Count == 0 && CurrentMenu != menu) { int index = currentPath[0]; currentItem = menu.Items[index]; currentPath.Clear(); currentPath.Add(index); SelectNextItem(); StepIntoSubMenu(); } // Step into a sub-menu. else if (Keyboard.IsKeyPressed(keyStepInto)) { StepIntoSubMenu(); } // Select previous root menu item. if (Keyboard.IsKeyPressed(Keys.Left) && CurrentMenu.Root == menu) { currentItem = CurrentMenu; currentPath.RemoveAt(currentPath.Count - 1); SelectPreviousItem(); StepIntoSubMenu(); } // Step out of a sub-menu. else if (Keyboard.IsKeyPressed(keyStepOut)) { StepOutOfSubMenu(); } // Select next item. if (Keyboard.IsKeyPressed(keyNextItem)) { SelectNextItem(); } // Select previous item. if (Keyboard.IsKeyPressed(keyPrevItem)) { SelectPreviousItem(); } // Step out of a sub-menu. if (Keyboard.IsKeyPressed(Keys.X) || Keyboard.IsKeyPressed(Keys.Escape)) { StepOutOfSubMenu(); } // Press item. if (Keyboard.IsKeyPressed(Keys.Enter) || Keyboard.IsKeyPressed(Keys.Z) || Keyboard.IsKeyPressed(Keys.Space)) { if (currentItem.Items.Count == 0) { currentItem.Press(); if (!Keyboard.IsKeyPressed(Keys.Space)) { Close(); } } else { StepIntoSubMenu(); } } }