using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework.Input; namespace TalkingIsAFreeAction { public static class Input { public static float CLIMBSPEED = 200; public static KeyboardState oldState = Keyboard.GetState(); public static KeyboardState newState = Keyboard.GetState(); public static void Update(double milliseconds) { oldState = newState; newState = Keyboard.GetState(); //------------FREE MODE ONLY--------- if (Main.currentMode == Main.Mode.Free) { //Check if stepped off ladder Object climbingLadder = null; for (int i = 0; i < Main.currentArea.objects.Count; i++) { Object theObject = Main.currentArea.objects[i]; if (theObject.special == "ladder") { if (Util.CheckCollision(Main.player, theObject)) { climbingLadder = theObject; } } } if (climbingLadder == null) Main.climbing = false; if (newState.IsKeyDown(Keys.Left)) Physics.TryAccelerateX(Main.player, -30); else if (newState.IsKeyDown(Keys.Right)) Physics.TryAccelerateX(Main.player, 30); else Main.player.velocityX = 0; //Jump or climb ladder if (newState.IsKeyDown(Keys.Up)) { if (climbingLadder != null) //Climb { //Center player... Main.player.x = climbingLadder.x + (climbingLadder.width / 2 - Main.player.width / 2); //Climb up float targetY = Main.player.y - CLIMBSPEED * ((float)milliseconds / 1000f); //Check for collisions if (Physics.CheckIfPassable(Main.player.x, targetY, Main.player.width, Main.player.height)) { Main.player.y = targetY; } Main.player.velocityY = 0; Main.climbing = true; } else //Jump { if (Main.player.onGroundTimer > 0.1f) { Main.player.velocityY = -500; Main.player.onGroundTimer = 0f; } } } else if (newState.IsKeyDown(Keys.Down)) { if (climbingLadder != null) //Climb { //Center player... Main.player.x = climbingLadder.x + (climbingLadder.width / 2 - Main.player.width / 2); //Climb down float targetY = Main.player.y + CLIMBSPEED * ((float)milliseconds / 1000f); //Check for collisions if (Physics.CheckIfPassable(Main.player.x, targetY, Main.player.width, Main.player.height)) { Main.player.y = targetY; } Main.player.velocityY = 0; Main.climbing = true; } } //Interact if (KeyPressed(Keys.Z) || KeyPressed(Keys.W)) Main.Interact(); //Carry or drop if (KeyPressed(Keys.X) || KeyPressed(Keys.Y)) Main.Carry(); if (KeyPressed(Keys.Escape)) { bool atMenu = false; if (Main.currentArea != null) { if (Main.currentArea.name == "menu") atMenu = true; } if (atMenu) Environment.Exit(0); else Main.SwitchLevel("menu"); } } //------------TEXT MODE ONLY-------- else if (Main.currentMode == Main.Mode.Text) { Main.player.velocityX = 0; if (KeyPressed(Keys.Z)) Textbox.Poke(); } if (KeyPressed(Keys.F)) VBXSE.SpriteEngine.ToggleFullscreen(); if ((newState.IsKeyDown(Keys.LeftAlt) || newState.IsKeyDown(Keys.RightAlt)) && KeyPressed(Keys.Enter)) VBXSE.SpriteEngine.ToggleFullscreen(); } public static bool KeyPressed(Keys key) { return (newState.IsKeyDown(key) && oldState.IsKeyUp(key)); } } }