/// <summary> /// Handles the movement of the viewport, what button does what /// </summary> /// <param name="state">The current state of the keyboard</param> private void handleViewPortMovement(KeyboardState state) { if (state.IsKeyDown(Keys.Up)) { currentLoc.Y -= 1; } else if (state.IsKeyDown(Keys.Down)) { currentLoc.Y += 1; } if (state.IsKeyDown(Keys.Left)) { currentLoc.X -= 1; } else if (state.IsKeyDown(Keys.Right)) { currentLoc.X += 1; } // Zoom in if (state.IsKeyDown(Keys.OemPlus)) { viewPortSize.X -= 5; viewPortSize.Y -= 5; } // zoom out else if (state.IsKeyDown(Keys.OemMinus)) { viewPortSize.X += 5; viewPortSize.Y += 5; } // Go the menu if (!keyLocker.KeyPressed && state.IsKeyDown(Keys.Escape) && !oldState.IsKeyDown(Keys.Escape)) { gameStateManager.Change("menu"); keyLocker.LockKey(Keys.Escape); } // Go the inventory else if (!keyLocker.KeyPressed && state.IsKeyDown(Keys.I) && !oldState.IsKeyDown(Keys.I)) { gameStateManager.Change("inventory", player); keyLocker.LockKey(Keys.I); } // Play the stage if it is selectable else if (!keyLocker.KeyPressed && state.IsKeyDown(Keys.Enter) && !oldState.IsKeyDown(Keys.Enter)) { if (selectedStage != 0) { gameStateManager.Change("stage", selectedStage, player); keyLocker.LockKey(Keys.Enter); } } keyLocker.CheckInputLock(state, Keys.Enter); keyLocker.CheckInputLock(state, Keys.Escape); keyLocker.CheckInputLock(state, Keys.I); }
public void HandleInput(KeyboardState state) { if (!keylock) { if (state.IsKeyDown(Keys.Down) && !oldState.IsKeyDown(Keys.Down)) { if (index < buttons.Count() - 1) { index++; CurrentButton.Play(); CurrentButton.setSelected(false); CurrentButton = buttons[index]; CurrentButton.setSelected(true); } else { } } if (state.IsKeyDown(Keys.Up) && !oldState.IsKeyDown(Keys.Up)) { if (index > 0) { index--; CurrentButton.Play(); CurrentButton.setSelected(false); CurrentButton = buttons[index]; CurrentButton.setSelected(true); } } if (state.IsKeyDown(Keys.Enter) && !oldState.IsKeyDown(Keys.Enter)) { if (CurrentButton == buttons[0]) { gameStateManager.Change("worldmap", new Player()); } else if (CurrentButton == buttons[1]) { gameStateManager.Change("worldmap"); } else if (CurrentButton == buttons[2]) { //load game code here } else if (CurrentButton == buttons[3]) { //save game code here } else if (CurrentButton == buttons[4]) { App.Current.Exit(); } } } oldState = state; }
public void HandleInput(KeyboardState state) { if (state.IsKeyDown(Keys.B)) { if (boundingBox) { boundingBox = false; } else { boundingBox = true; } } if (state.IsKeyDown(Keys.Escape)) { gameStateManager.Change("worldmap"); } if (state.IsKeyDown(Keys.Space)) { jumping = true; } if (state.IsKeyUp(Keys.Space)) { jumping = false; } foreach (var map in _currentStage.GameObjects) { if (state.IsKeyUp(Keys.Left)) { //map.Position = new Vector2(map.Position.X - 2f, map.Position.Y); } if (state.IsKeyUp(Keys.Right)) { //map.Position = new Vector2(map.Position.X + 2f, map.Position.Y); } } player.HandleInput(state); }
/// <summary> /// 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. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); GameServices.AddService <GraphicsDevice>(GraphicsDevice); GameServices.AddService <ContentManager>(Content); gameStateManager = new GameStateManager(); gameStateManager.Add("worldmap", new WorldMapGameState(gameStateManager)); gameStateManager.Add("inventory", new InventoryGameState(gameStateManager)); gameStateManager.Add("stage", new StageGameState(gameStateManager)); gameStateManager.Add("menu", new MenuGameState(gameStateManager)); gameStateManager.Add("pause", new PauseGameState(gameStateManager)); gameStateManager.Change("menu"); }