public override void HandleInput(InputHelper inputHelper) { if (inputHelper.CurrentPressedKeys().Length == 0) { timer = -1; return; } if (inputHelper.IsKeyDown(Keys.Back) && text.Length > 0) { timer++; if (timer == 0) { text = text.Substring(0, text.Length - 1); } if (timer > 44 && timer % 3 == 0) { text = text.Substring(0, text.Length - 1); } return; } // Enter the value if (inputHelper.KeyPressed(Keys.Enter)) { hh.SubmitScore(text, Wave, TotalEnemiesKilled, totalResourcesGathered, FinalScore); Kill = true; Console.WriteLine("NEW ENTRY: " + text); return; } // SPACE if (inputHelper.KeyPressed(Keys.Space)) { text = text + " "; return; } for (int i = 65; i < 97; i++) { Keys k = (Keys)i; if (inputHelper.KeyPressed(k)) { AddChar(k, inputHelper); return; } } for (int i = 48; i < 58; i++) { Keys k = (Keys)i; if (inputHelper.KeyPressed(k)) { AddNumber(i, inputHelper); return; } } }
public override void HandleInput(InputHelper inputHelper) { base.HandleInput(inputHelper); //Change the texture of the selected node if (inputHelper.MouseLeftButtonDown() && inputHelper.MouseInGameWindow) { GridPlane currentPlane; try { currentPlane = GameWorld.FindByType <Camera>()[0].currentPlane; //Get the index for the current plane for (int x = 0; x < LEVEL_SIZE.X; ++x) { for (int y = 0; y < LEVEL_SIZE.Y; ++y) { GridNode node = currentPlane.grid[x, y]; //store in node for easy acces if (node.selected) { node.texture = selected; } } } } catch (Exception e) { Console.WriteLine(e.Message); } } //Change the selected texture if (inputHelper.AnyKeyPressed) { //Get the currently pressed keys Keys[] keys = inputHelper.CurrentPressedKeys(); try { char[] str = keys[0].ToString().ToArray <char>(); //Get the char array of the name of the pressed key if (str.Length < 2) { return; } //Eliminate the "D" Key itself if (str[0] == 'D') //Is it a number key? { int s = int.Parse(str[1].ToString()); //Get the number pressed if (s < toolList.Count) //is it in range of the available toollist? { selected = s; //Select a new texture } } } catch (Exception e) { Console.WriteLine(e.Message); } } }
public override void HandleInput(InputHelper inputHelper) { base.HandleInput(inputHelper); if (inputHelper.MouseLeftButtonPressed() && inputHelper.MouseInGameWindow) { try { GridNode nodeAt = CameraGridPlane.NodeAt(inputHelper.MousePosition - CameraPosition); //Get the node at the mouse Type t = Type.GetType(toolList[selected].name); //Get the type of the object object temp = Activator.CreateInstance(t); //Create an instance of that object GameObject obj = temp as GameObject; //Cast it as a GameObject obj.Position = nodeAt.Position; //Set it's position at the mouse node CameraGridPlane.Add(obj); //Add it to the plane } catch (Exception e) { Console.WriteLine(e.Message); } } //Change the selected object if (inputHelper.AnyKeyPressed) { //Get the currently pressed keys Keys[] keys = inputHelper.CurrentPressedKeys(); try { char[] str = keys[0].ToString().ToArray <char>(); //Get the char array of the name of the pressed key if (str.Length < 2) { return; } //Eliminate the "D" Key itself if (str[0] == 'D') //Is it a number key? { int s = int.Parse(str[1].ToString()); //Get the number pressed if (s < toolList.Count) //is it in range of the available toollist? { selected = s; //Select a new object } } } catch (Exception e) { Console.WriteLine(e.Message); } } }
public override void HandleInput(InputHelper inputHelper) { if (inputHelper.CurrentPressedKeys().ToList().Contains(Keys.D) && inputHelper.CurrentPressedKeys().ToList().Contains(Keys.LeftShift)) { GameEnvironment.GameStateManager.AddGameState("GameOverState", new GameOverState()); GameEnvironment.GameStateManager.SwitchTo("GameOverState"); } if (inputHelper.IsKeyDown(Keys.LeftShift) && inputHelper.IsKeyDown(Keys.H)) { if (inputHelper.IsKeyDown(Keys.W)) { GameStats.Wave++; } if (inputHelper.IsKeyDown(Keys.D)) { GameStats.Wave++; } if (inputHelper.IsKeyDown(Keys.R)) { GameStats.EcResources += 10; } if (inputHelper.IsKeyDown(Keys.L)) { GameStats.BaseHealth += 2; } } //zoom Vector2 oldScale = scale; if (inputHelper.ScrollUp()) { if (scale.X < 1f) { scale *= new Vector2(1.07f); } } if (inputHelper.ScrollDown()) { if ((LEVEL_SIZE.X * NODE_SIZE.X * scale.X > GAME_WINDOW_SIZE.X + 96)) { scale *= new Vector2(1 / 1.07f); } } if (inputHelper.IsKeyDown(Keys.Q)) { if (scale.X < 1f) { scale *= new Vector2(1.02f); } } if (inputHelper.IsKeyDown(Keys.A)) { if ((LEVEL_SIZE.X * NODE_SIZE.X * scale.X > GAME_WINDOW_SIZE.X + 96)) { scale *= new Vector2(1 / 1.02f); } } Vector2 dScale = scale - oldScale; position -= (position + (SCREEN_SIZE.toVector())) * dScale / oldScale; //Focus on base if (inputHelper.IsKeyDown(Keys.Space)) { position += (-position - LEVEL_CENTER * scale + scale * GAME_WINDOW_SIZE.toVector() / 2) / 22; } //Manually handle the input of the active plane currentPlane.HandleInput(inputHelper); //Camera Movement Vector2 mp = inputHelper.MousePosition; float spd = SLIDE_SPEED / scale.X; if (mp.X < SLIDE_BORDER) { position.X += spd; } if (mp.X > SCREEN_SIZE.X - SLIDE_BORDER) { position.X -= spd; } if (mp.Y < SLIDE_BORDER) { position.Y += spd; } if (mp.Y > SCREEN_SIZE.Y - SLIDE_BORDER) { position.Y -= spd; } //Make sure the camera doesn't move out of bounds if (position.X > -NODE_SIZE.X / 2 - GridNode.origin.X / 2) { position.X = -NODE_SIZE.X / 2 - GridNode.origin.X / 2; } if (position.Y > -NODE_SIZE.Y / 2 - GridNode.origin.Y) { position.Y = -NODE_SIZE.Y / 2 - GridNode.origin.Y; } if (position.X < -NODE_SIZE.X * LEVEL_SIZE.X + GAME_WINDOW_SIZE.X / scale.X) { position.X = -NODE_SIZE.X * LEVEL_SIZE.X + GAME_WINDOW_SIZE.X / scale.X; } if (position.Y < -NODE_SIZE.Y / 2 * LEVEL_SIZE.Y + GAME_WINDOW_SIZE.Y / scale.Y) { position.Y = -NODE_SIZE.Y / 2 * LEVEL_SIZE.Y + GAME_WINDOW_SIZE.Y / scale.Y; } base.HandleInput(inputHelper); }