private KeyboardState UpdateInput(KeyboardState oldState, Floor floor, SpriteManager spriteManager) { KeyboardState newState = Keyboard.GetState(); //checking if at the top of the map if (Location.Y != 0) { if (oldState.IsKeyDown(Keys.Up) && !(newState.IsKeyDown(Keys.Up))) { dir = 1; move(floor, new Vector2(0, 1)); } } //checking right if (Location.X != 26) { if (oldState.IsKeyDown(Keys.Right) && !(newState.IsKeyDown(Keys.Right))) { dir = 2; move(floor, new Vector2(-1, 0)); } } //checking down if (Location.Y != 26) { if (oldState.IsKeyDown(Keys.Down) && !(newState.IsKeyDown(Keys.Down))) { dir = 3; move(floor, new Vector2(0, -1)); } } //checking left if (Location.X != 0) { if (oldState.IsKeyDown(Keys.Left) && !(newState.IsKeyDown(Keys.Left))) { dir = 4; move(floor, new Vector2(1, 0)); } } if (oldState.IsKeyDown(Keys.Enter) && !(newState.IsKeyDown(Keys.Enter))) { //ROTATE ADJACENT ROOMS if (newState.IsKeyDown(Keys.A) && Location.X > 0 && rotationEnergy >= 5) { rotate(floor, spriteManager, new Vector2(1, 0)); } else if (newState.IsKeyDown(Keys.D) && Location.X < 26 && rotationEnergy >= 5) { rotate(floor, spriteManager, new Vector2(-1, 0)); } else if (newState.IsKeyDown(Keys.W) && Location.Y > 0 && rotationEnergy >= 5) { rotate(floor, spriteManager, new Vector2(0, 1)); } else if (newState.IsKeyDown(Keys.S) && Location.Y < 26 && rotationEnergy >= 5) { rotate(floor, spriteManager, new Vector2(0, -1)); } else if ((newState.GetPressedKeys().Length == 0) && rotationEnergy >= 2) { //Rotate current room rotate(floor, spriteManager, Vector2.Zero); } //else //spriteManager.PlayCue("error"); } if (oldState.IsKeyDown(Keys.Back) && !(newState.IsKeyDown(Keys.Back)) && level >= 5) { if (newState.IsKeyDown(Keys.A) && Location.X > 0) { if (SubtractEnergy(10)) { CurrentRoom.AddExit(4); floor[Location.X - 1, Location.Y].AddExit(2); } } else if (newState.IsKeyDown(Keys.D) && Location.X < 26) { if (SubtractEnergy(10)) { CurrentRoom.AddExit(2); floor[Location.X + 1, Location.Y].AddExit(4); } } else if (newState.IsKeyDown(Keys.W) && Location.Y > 0) { if (SubtractEnergy(10)) { CurrentRoom.AddExit(1); floor[Location.X, Location.Y - 1].AddExit(3); } } else if (newState.IsKeyDown(Keys.S) && Location.Y < 26) { if (SubtractEnergy(10)) { CurrentRoom.AddExit(3); floor[Location.X, Location.Y + 1].AddExit(1); } } } //if (oldState.IsKeyDown(Keys.Delete) && !(newState.IsKeyDown(Keys.Delete))) //{ // if (newState.IsKeyDown(Keys.A) && Location.X > 0) // { // CurrentRoom.RemoveExit(4); // floor[Location.X - 1, Location.Y].RemoveExit(2); // } // else if (newState.IsKeyDown(Keys.D) && Location.X < 26) // { // CurrentRoom.RemoveExit(2); // floor[Location.X + 1, Location.Y].RemoveExit(4); // } // else if (newState.IsKeyDown(Keys.W) && Location.Y > 0) // { // CurrentRoom.RemoveExit(1); // floor[Location.X, Location.Y - 1].RemoveExit(3); // } // else if (newState.IsKeyDown(Keys.S) && Location.Y < 26) // { // CurrentRoom.RemoveExit(3); // floor[Location.X, Location.Y + 1].RemoveExit(1); // } //} if (oldState.IsKeyDown(Keys.Home) && !(newState.IsKeyDown(Keys.Home))) { SpriteManager.SkipTurn = !SpriteManager.SkipTurn; } if (oldState.IsKeyDown(Keys.E) && !(newState.IsKeyDown(Keys.E))) { Item check = checkInventory(ItemList.Get("Energy Potion")); if (check != null) { check.Use(this); } } if (oldState.IsKeyDown(Keys.P) && !(newState.IsKeyDown(Keys.P))) { Item check = checkInventory(ItemList.Get("Potion")); if (check != null) { check.Use(this); } } //if (oldState.IsKeyDown(Keys.F) && !newState.IsKeyDown(Keys.F)) //{ // AddItem(ItemList.Get("Elixir of Strength")); // AddItem(ItemList.Get("Stoneskin Potion")); //} if (oldState.IsKeyDown(Keys.Escape) && !newState.IsKeyDown(Keys.Escape)) { SpriteManager.ShowOptions(); } if (oldState.IsKeyDown(Keys.Space) && !newState.IsKeyDown(Keys.Space)) { turnTaken = true; } if (oldState.IsKeyDown(Keys.I) && !newState.IsKeyDown(Keys.I)) { ShowInventory(); } if (oldState.IsKeyDown(Keys.C) && !newState.IsKeyDown(Keys.C)) { ShowStatus(); } if (oldState.IsKeyDown(Keys.H) && !newState.IsKeyDown(Keys.H)) { UI.ShowMessage("Controls: "); UI.ShowMessage("Skip Turn: SPACE Quick Use Energy Potion: E Quick Use Potion: P"); UI.ShowMessage("Status: C Inventory: I Volume Controls: ESC Help: H Move: ARROWS"); UI.ShowMessage("Rotate Room: ENTER Rotate Adjacent room: W,A,S,D + ENTER"); UI.ShowMessage("Rotating rooms consumes your energy. 2 for your room, 5 for adjacent"); if (level >= 5) { UI.ShowMessage("(Level 5)Alternate Exit blasts a hole into an adjacent room"); UI.ShowMessage("Alternate Exit: W,A,S,D + BACKSPACE Costs 10 energy"); } } oldState = newState; return(oldState); }
public override void Update(GameTime gameTime, Rectangle clientBounds, Floor floor, SpriteManager spriteManager) { if (Game1.PAUSED) { base.Update(gameTime, clientBounds, floor); return; } if (!turnTaken && Turn) { Game1.BATTLE = spriteManager.BattleChecker(); //oldState = Keyboard.GetState(); } if (distance == 0 && rotation == 0) { if (Animations.CurrentAnimation != "idle") { Animations.CurrentAnimation = "idle"; } if (turnTaken && Turn) { if (!rotated && rotationEnergy < rotationEnergyMax) { rotationEnergy += 1; } if (buffs.Count > 0) { for (int i = 0; i < buffs.Count; i++) { buffs[i].Duration--; if (buffs[i].Duration == 0) { RemoveBuff(buffs[i]); } } } CurrentRoom = floor[Location.X, Location.Y]; CurrentRoom.AddContent(this); spriteManager.NewSpawn(); //Console.WriteLine("end of turn"); Game1.BATTLE = spriteManager.BattleChecker(); if (CurrentRoom.Enemies.Count == 0) { changeTurn(false); rotated = false; } } if (Turn && !Game1.BATTLE) { oldState = UpdateInput(oldState, floor, spriteManager); } } if (rotation > 0) { rotation -= 5; } if (distance > 0) { if (dir == 1) { Position = new Point(Position.X, Position.Y - 5); } if (dir == 2) { Position = new Point(Position.X + 5, Position.Y); } if (dir == 3) { Position = new Point(Position.X, Position.Y + 5); } if (dir == 4) { Position = new Point(Position.X - 5, Position.Y); } distance -= 5; } base.Update(gameTime, clientBounds, floor); }
public void Update(GameTime gameTime, UserControlledSprite player) { if (wContent != "") { Game1.PAUSED = true; unpause = false; } KeyboardState newState = Keyboard.GetState(); volumePer += gameTime.ElapsedGameTime.Milliseconds; if (unpause) { pauseTime += gameTime.ElapsedGameTime.Milliseconds; if (pauseTime >= 200) { Game1.PAUSED = false; unpause = false; pauseTime = 0; } } if (wType == "inventory") { Window description = new Window(); if (wContent != "Empty") { description = UI.ShowMessage(player.Inventory[wIndex].Description + " Worth: " + player.Inventory[wIndex].Value.ToString(), new Point(this.wPosition.X + this.wPosition.Width + borderWidth * 2 + 5, this.wPosition.Y), "description"); } setSelection(); if (oldState.IsKeyDown(Keys.Up) && !newState.IsKeyDown(Keys.Up)) { if (wIndex != 0) { wIndex--; } } if (oldState.IsKeyDown(Keys.Down) && !newState.IsKeyDown(Keys.Down)) { if (wIndex < wLines - 1) { wIndex++; } } if (oldState.IsKeyDown(Keys.Enter) && !newState.IsKeyDown(Keys.Enter)) { //Use Item if (wContent != "Empty") { if (player.UseItem(wIndex) <= 0 && wIndex != 0) { wIndex--; } player.ShowInventory(); if (wContent == "Empty") { description.closeWindow(); } } } if (oldState.IsKeyDown(Keys.I) && !newState.IsKeyDown(Keys.I)) { closeWindow(); description.closeWindow(); } if (oldState.IsKeyDown(Keys.Escape) && !newState.IsKeyDown(Keys.Escape)) { closeWindow(); description.closeWindow(); } } else if (wType == "options") { setSelection(); if (oldState.IsKeyDown(Keys.Up) && !newState.IsKeyDown(Keys.Up)) { if (wIndex != 0) { wIndex--; } } if (oldState.IsKeyDown(Keys.Down) && !newState.IsKeyDown(Keys.Down)) { if (wIndex < wLines - 1) { wIndex++; } } if (wIndex == 0) //Music { if (newState.IsKeyDown(Keys.Left)) { if (Game1.Volume > 0.0f || oldVolume > 0.0f) { if (volumePer >= volumeMax) { if (oldVolume > 0) { Game1.Volume = oldVolume; oldVolume = 0; } if (Game1.Volume > 0.0f) { Game1.Volume -= .01f; } volumePer = 0; SpriteManager.ShowOptions(); } } } if (newState.IsKeyDown(Keys.Right)) { if (Game1.Volume < 1.0f) { //volumePer += gameTime.ElapsedGameTime.Milliseconds; if (volumePer >= volumeMax) { if (oldVolume > 0) { Game1.Volume = oldVolume; oldVolume = 0; } if (Game1.Volume < 1.0f) { Game1.Volume += .01f; } volumePer = 0; SpriteManager.ShowOptions(); } } } if (oldState.IsKeyDown(Keys.Enter) && !newState.IsKeyDown(Keys.Enter)) { if (oldVolume > 0) { Game1.Volume = oldVolume; oldVolume = 0f; SpriteManager.ShowOptions(); } else { oldVolume = Game1.Volume; Game1.Volume = 0.0f; SpriteManager.ShowOptions(); } } } else if (wIndex == 1) { if (newState.IsKeyDown(Keys.Left)) { if (Game1.SEVolume > 0.0f || oldSEVolume > 0.0f) { if (volumePer >= volumeMax) { if (oldSEVolume > 0) { Game1.SEVolume = oldSEVolume; Game1.SE = true; oldSEVolume = 0; } if (Game1.SEVolume > 0.0f) { Game1.SEVolume -= .01f; } volumePer = 0; SpriteManager.SetVolumeSE(); SpriteManager.ShowOptions(); } } } if (newState.IsKeyDown(Keys.Right)) { if (Game1.SEVolume < 1.0f) { //volumePer += gameTime.ElapsedGameTime.Milliseconds; if (volumePer >= volumeMax) { if (oldSEVolume > 0) { Game1.SEVolume = oldSEVolume; Game1.SE = true; oldSEVolume = 0; } if (Game1.SEVolume < 1.0f) { Game1.SEVolume += .01f; } volumePer = 0; SpriteManager.SetVolumeSE(); SpriteManager.ShowOptions(); } } } if (oldState.IsKeyDown(Keys.Enter) && !newState.IsKeyDown(Keys.Enter)) { if (oldSEVolume > 0) { Game1.SEVolume = oldSEVolume; Game1.SE = !Game1.SE; SpriteManager.ShowOptions(); } else { oldSEVolume = Game1.SEVolume; Game1.SE = !Game1.SE; SpriteManager.ShowOptions(); } } } if (oldState.IsKeyDown(Keys.Escape) && !newState.IsKeyDown(Keys.Escape)) { closeWindow(); } } if (wType == "message") { if (oldState.GetPressedKeys().Length > 0 && newState.GetPressedKeys().Length <= 0) { closeWindow(); } } if (wType == "status") { if (oldState.GetPressedKeys().Length > 0 && newState.GetPressedKeys().Length <= 0) { closeWindow(); } } if (wType == "shop") { setSelection(); if (oldState.IsKeyDown(Keys.Up) && !newState.IsKeyDown(Keys.Up)) { if (wIndex != 0) { wIndex--; } } if (oldState.IsKeyDown(Keys.Down) && !newState.IsKeyDown(Keys.Down)) { if (wIndex < wLines - 1) { wIndex++; } } if (oldState.IsKeyDown(Keys.Enter) && !newState.IsKeyDown(Keys.Enter)) { if (wIndex == 0) //Buy { } if (wIndex == 1) //Sell { } } } if (wType == "dialogue") { if (oldState.IsKeyDown(Keys.Escape) && !newState.IsKeyDown(Keys.Escape) && !Game1.WON) { closeWindow(); } if (newState.IsKeyDown(Keys.Enter) && contentIndex < wContent.Length) { messageSpeedMax = 15; speedText = true; } if (!oldState.IsKeyUp(Keys.Enter) && newState.IsKeyUp(Keys.Enter) && contentIndex >= wContent.Length && !speedText) { if (Game1.WON) { Game1.CLOSEGAME = true; } else { closeWindow(); } } if (!newState.IsKeyDown(Keys.Enter)) { messageSpeedMax = 50; speedText = false; } } oldState = newState; }