public override void Update(GameTime gameTime) { keyboard.Update(gameTime); if (InputEngine.IsKeyPressed(Keys.Enter) && !firstText && !Done) { Name = Output; Output = string.Empty; firstText = true; keyboard.Output = string.Empty; InputEngine.ClearState(); } if (InputEngine.IsKeyPressed(Keys.Enter) && firstText && !Done) { Output = string.Empty; keyboard.Output = string.Empty; Done = true; Enabled = false; Visible = false; } if (InputEngine.IsKeyPressed(Keys.Back)) { if (Output.Length > 0) { Output = Output.Remove(Output.Length - 1); } } if (InputEngine.IsKeyPressed(Keys.Space)) { Output += " "; } base.Update(gameTime); }
public void Clear() { firstText = false; Name = string.Empty; output = string.Empty; input.KeysPressedInLastFrame.Clear(); keyboard.Output = string.Empty; InputEngine.ClearState(); Done = false; }
private void typeMessage() { loginKeyboard.Visible = true; //Clears anything written before this point InputEngine.ClearState(); if (loginKeyboard.Done) { textMessage = loginKeyboard.Name; loginKeyboard.Clear(); InputEngine.ClearState(); //checks to see if the connection is connected if (textMessage != null) { sendAllClientMessage(textMessage); } } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (!connected) { return; } MouseState mouse = Mouse.GetState(); switch (CurrentGameState) { case GAMESTATE.MAINMENU: if (btnLogIn.isClicked == true) { CurrentGameState = GAMESTATE.LOGIN; } btnLogIn.Update(mouse); break; case GAMESTATE.LOGIN: //Activates the login Keyboard CheckLogedInPlayers(); if (InputEngine.IsKeyPressed(Keys.F10) && !loginKeyboard.Visible) { loginKeyboard.Visible = true; //Clears anything written before this point InputEngine.ClearState(); } if (loginKeyboard.Done) { gamerTag = loginKeyboard.Name; password = loginKeyboard.Password; loginKeyboard.Clear(); InputEngine.ClearState(); //checks to see if the connection is connected if (connection.State == ConnectionState.Connected) { if (gamerTag != null && password != null) { getPlayer(); subscribeToMessages(); CheckLogedInPlayers(); //getPlayerData(); } } } if (loggedIn == true) { if (allLogedInPlayers.Count >= 2) { if (btnSubmit.isClicked == true) { CurrentGameState = GAMESTATE.PLAYING; } } btnSubmit.Update(mouse); } break; case GAMESTATE.PLAYING: if (Keyboard.GetState().IsKeyDown(Keys.Q)) { myPlayer = new speedyPlayer(new Texture2D[] { Content.Load <Texture2D>(@"Player Images\characterSpriteSheet1"), Content.Load <Texture2D>(@"Player Images\cherryPlayer") }, centreScreen, 2, 9f); gameStart = true; q = true; } if (Keyboard.GetState().IsKeyDown(Keys.W)) { myPlayer = new ladyPlayer(new Texture2D[] { Content.Load <Texture2D>(@"Player Images\character2SspriteSheet"), Content.Load <Texture2D>(@"Player Images\cherryPlayer") }, centreScreen, 2, 6f); gameStart = true; w = true; } if (Keyboard.GetState().IsKeyDown(Keys.E)) { myPlayer = new healthyPlayer(new Texture2D[] { Content.Load <Texture2D>(@"Player Images\characterSpriteSheet3"), Content.Load <Texture2D>(@"Player Images\cherryPlayer") }, centreScreen, 2, 6f); gameStart = true; e = true; } if (Keyboard.GetState().IsKeyDown(Keys.R)) { myPlayer = new sneakPlayer(new Texture2D[] { Content.Load <Texture2D>(@"Player Images\character4SpriteSheet"), Content.Load <Texture2D>(@"Player Images\cherryPlayer") }, centreScreen, 2, 4.5f); gameStart = true; r = true; } if (gameStart) // play the game { Vector2 StartingPos = myPlayer.position; sendNewPlayerStartingPosition(centreScreen); //updating the player myPlayer.Update(gameTime); sendNewPlayerPosition(myPlayer.position); subscribeToMessages(); foreach (Player othPlayer in OtherPlayers) { othPlayer.Update(gameTime); } cherry.Update(gameTime); if (cherry.visible == true) { if (myPlayer.collisionDetect(cherry)) { cherry.visible = false; myPlayer.cherryform = true; } } // no going through the walls foreach (Wall w in walls) { if (w.visible) { if (w.collisionDetect(myPlayer)) { if (myPlayer.sneaky == false) { myPlayer.position = StartingPos; } } } } //clamping the player to the border myPlayer.position = Vector2.Clamp(myPlayer.position, Vector2.Zero, (new Vector2(screenWidth, screenHeight) - new Vector2(myPlayer.SpriteWidth, myPlayer.SpriteHeight))); //updating the collectables for (int i = 0; i < collectables.Count; i++) { collectables[i].Update(gameTime); } //updating the collectables collision detection for (int i = 0; i < collectables.Count; i++) { if (myPlayer.collisionDetect(collectables[i])) { if (collectables[i].visible) { // collectedAmount++; myPlayer.score += collectables[i].CollectableScore; collectables[i].visible = false; } } } //updating collision detect for chasers for (int i = 0; i < chasers.Length; i++) { if (myPlayer.collisionDetect(chasers[i])) { if (chasers[i].visible) { // myPlayer.health -= Utility.NextRandom(40, 60); myPlayer.score += Utility.NextRandom(25, 40); } chasers[i].visible = false; } } //dealing with health when hitting enemies if (myPlayer.health <= 0) { lives -= 1; myPlayer.position = centreScreen; myPlayer.health = 100; } //updating chasers foreach (ChasingEnemy chaser in chasers) { chaser.follow(myPlayer); chaser.Update(gameTime); chaser.position = Vector2.Clamp(chaser.position, Vector2.Zero, (new Vector2(screenWidth, screenHeight) - new Vector2(chaser.SpriteWidth, chaser.SpriteHeight))); } //turning the score int into a string so we can write it scoreMessage = Convert.ToString(myPlayer.score); if (Keyboard.GetState().IsKeyDown(Keys.F12)) { typeMessage(); } } break; // TODO: Add your update logic here } base.Update(gameTime); }