using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework; namespace ConqueringOneself { public static class Input { static Main main; static KeyboardState oldState; static KeyboardState newState = Keyboard.GetState(); static int titleScreenDelete = 0; static float pgUpDownDelay = -1; static float SCROLL_DELAY = 200; public static void Initialize(Main main) { Input.main = main; } public static bool KeyPressed(Keys key) { return (newState.IsKeyDown(key) && !oldState.IsKeyDown(key)); } public static void Update(GameTime gameTime) { oldState = newState; newState = Keyboard.GetState(); if (pgUpDownDelay > 0) pgUpDownDelay -= (float)gameTime.ElapsedGameTime.TotalMilliseconds; switch (main.gameState) { case Main.GameState.SelectingMove: case Main.GameState.TitleScreen: case Main.GameState.LevelUp: if (KeyPressed(Keys.Up)) main.MoveSelection(-1); else if (KeyPressed(Keys.Down)) main.MoveSelection(1); else if (KeyPressed(Keys.Enter)) main.Select(); //Delete saved data if(main.gameState == Main.GameState.TitleScreen && Graphics.TITLE_MENU_OPTIONS[main.selectedItem] == "ERASE SAVED DATA") { if (titleScreenDelete == 0 && KeyPressed(Keys.Y)) { Audio.PlaySound("hit"); titleScreenDelete++; } else if (titleScreenDelete == 1 && KeyPressed(Keys.E)) { Audio.PlaySound("gethit"); titleScreenDelete++; } else if (titleScreenDelete == 2 && KeyPressed(Keys.S)) { titleScreenDelete = 0; main.EraseSavedData(); } } else { titleScreenDelete = 0; } //Scrolling if (main.gameState == Main.GameState.TitleScreen && (Graphics.TITLE_MENU_OPTIONS[main.selectedItem] == "ANALYSIS" || Graphics.TITLE_MENU_OPTIONS[main.selectedItem] == "VIEW HIGH SCORES")) { if (pgUpDownDelay < 0) { if (newState.IsKeyDown(Keys.PageDown)) { int maximum = 0; if (Graphics.TITLE_MENU_OPTIONS[main.selectedItem] == "ANALYSIS") maximum = main.enemyPattern.Count - 1; else if (Graphics.TITLE_MENU_OPTIONS[main.selectedItem] == "VIEW HIGH SCORES") maximum = HighScores.scores.Count - 1; if (Graphics.scroll < maximum) Graphics.scroll++; pgUpDownDelay = SCROLL_DELAY; Graphics.DisplayTitle(); } else if (newState.IsKeyDown(Keys.PageUp)) { if (Graphics.scroll > 0) Graphics.scroll--; pgUpDownDelay = SCROLL_DELAY; Graphics.DisplayTitle(); } } } break; case Main.GameState.HandlingText: if (KeyPressed(Keys.Enter)) { Graphics.hurryUp = true; } break; case Main.GameState.ClickToContinue: if (KeyPressed(Keys.Enter)) { main.FinishText(); } break; case Main.GameState.Tutorial: if (KeyPressed(Keys.Enter)) { main.tutorialState++; switch (main.tutorialState) { case 0: VBXSE.SpriteEngine.EraseGObject(main.tutorialSprite); Graphics.EraseCombatLog(); main.HideAll(); main.Newbie(); break; case 1: VBXSE.SpriteEngine.EraseGObject(main.tutorialSprite); main.StartCombat(); break; case 3: VBXSE.SpriteEngine.EraseGObject(main.tutorialSprite); main.tutorialSprite = VBXSE.SpriteEngine.CreateSprite("explanation", Vector2.Zero); main.tutorialSprite.depth = -2000; break; case 4: VBXSE.SpriteEngine.EraseGObject(main.tutorialSprite); main.GoToTitleScreen(); break; } } break; case Main.GameState.NameEntry: { if (newState.IsKeyDown(Keys.LeftShift) || newState.IsKeyDown(Keys.RightShift)) { if (KeyPressed(Keys.A)) AL("A"); if (KeyPressed(Keys.B)) AL("B"); if (KeyPressed(Keys.C)) AL("C"); if (KeyPressed(Keys.D)) AL("D"); if (KeyPressed(Keys.E)) AL("E"); if (KeyPressed(Keys.F)) AL("F"); if (KeyPressed(Keys.G)) AL("G"); if (KeyPressed(Keys.H)) AL("H"); if (KeyPressed(Keys.I)) AL("I"); if (KeyPressed(Keys.J)) AL("J"); if (KeyPressed(Keys.K)) AL("K"); if (KeyPressed(Keys.L)) AL("L"); if (KeyPressed(Keys.M)) AL("M"); if (KeyPressed(Keys.N)) AL("N"); if (KeyPressed(Keys.O)) AL("O"); if (KeyPressed(Keys.P)) AL("P"); if (KeyPressed(Keys.Q)) AL("Q"); if (KeyPressed(Keys.R)) AL("R"); if (KeyPressed(Keys.S)) AL("S"); if (KeyPressed(Keys.T)) AL("T"); if (KeyPressed(Keys.U)) AL("U"); if (KeyPressed(Keys.V)) AL("V"); if (KeyPressed(Keys.W)) AL("W"); if (KeyPressed(Keys.X)) AL("X"); if (KeyPressed(Keys.Y)) AL("Y"); if (KeyPressed(Keys.Z)) AL("Z"); } else { if (KeyPressed(Keys.A)) AL("a"); if (KeyPressed(Keys.B)) AL("b"); if (KeyPressed(Keys.C)) AL("c"); if (KeyPressed(Keys.D)) AL("d"); if (KeyPressed(Keys.E)) AL("e"); if (KeyPressed(Keys.F)) AL("f"); if (KeyPressed(Keys.G)) AL("g"); if (KeyPressed(Keys.H)) AL("h"); if (KeyPressed(Keys.I)) AL("i"); if (KeyPressed(Keys.J)) AL("j"); if (KeyPressed(Keys.K)) AL("k"); if (KeyPressed(Keys.L)) AL("l"); if (KeyPressed(Keys.M)) AL("m"); if (KeyPressed(Keys.N)) AL("n"); if (KeyPressed(Keys.O)) AL("o"); if (KeyPressed(Keys.P)) AL("p"); if (KeyPressed(Keys.Q)) AL("q"); if (KeyPressed(Keys.R)) AL("r"); if (KeyPressed(Keys.S)) AL("s"); if (KeyPressed(Keys.T)) AL("t"); if (KeyPressed(Keys.U)) AL("u"); if (KeyPressed(Keys.V)) AL("v"); if (KeyPressed(Keys.W)) AL("w"); if (KeyPressed(Keys.X)) AL("x"); if (KeyPressed(Keys.Y)) AL("y"); if (KeyPressed(Keys.Z)) AL("z"); } if (KeyPressed(Keys.Space)) AL(" "); if (KeyPressed(Keys.Back) || KeyPressed(Keys.Delete)) { Audio.PlaySound("blip"); if (main.player.name.Length > 0) main.player.name = main.player.name.Substring(0, main.player.name.Length - 1); main.nameEntry2.text = main.player.name + "_"; } if (KeyPressed(Keys.Enter)) { if (main.player.name != "") { Audio.PlaySound("select"); VBXSE.SpriteEngine.EraseGObject(main.nameEntry1); VBXSE.SpriteEngine.EraseGObject(main.nameEntry2); main.Newbie(); } } } break; } //General purpose input if ((KeyPressed(Keys.F) && main.gameState != Main.GameState.NameEntry) || KeyPressed(Keys.F4) || ((newState.IsKeyDown(Keys.LeftAlt) || newState.IsKeyDown(Keys.RightAlt)) && KeyPressed(Keys.Enter))) VBXSE.SpriteEngine.ToggleFullscreen(); } public static void AL(string letter) { if (main.player.name.Length < 25) { Audio.PlaySound("blip"); main.player.name += letter; main.nameEntry2.text = main.player.name + "_"; } } } }