/// <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) { float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; keyboard.Update(); mouse.Update(); { //Update player position Vector2 velocity = new Vector2(keyboard.GetAxis(Keys.Q, Keys.D), keyboard.GetAxis(Keys.Z, Keys.S)); if (velocity.X != 0 && velocity.Y != 0) { velocity.Normalize(); } players.SetPlayerVelocity(playerId, velocity.Y, velocity.X); players.UpdatePlayers(deltaTime); Player player = players.GetPlayerSnapshot(playerId); client.Send(Commands.UpdatePlayerLocation(playerId, player.Y, player.X, player.YVelocity, player.XVelocity)); } if (keyboard.IsPressed(Keys.Escape)) { Exit(); } if (keyboard.IsPressed(Keys.D1)) { Player player = players.GetPlayerSnapshot(playerId); client.Send(Commands.PlantCrop(playerId, (byte)player.Y, (byte)player.X, CropType.Carrot)); } if (keyboard.IsPressed(Keys.D2)) { Player player = players.GetPlayerSnapshot(playerId); client.Send(Commands.HarvestCrop(playerId, (byte)player.Y, (byte)player.X)); } if (keyboard.IsPressed(Keys.D3)) { Player player = players.GetPlayerSnapshot(playerId); client.Send(Commands.PlaceStructure(playerId, (byte)player.Y, (byte)player.X, StructureType.Container)); } if (keyboard.IsPressed(Keys.D4)) { Player player = players.GetPlayerSnapshot(playerId); client.Send(Commands.DestroyStructure(playerId, (byte)player.Y, (byte)player.X)); } if (mouse.ScrollWheelState != ScrollWheelState.Idle) { playerHotbar.SelectSlot(playerHotbar.SelectedSlot + (int)mouse.ScrollWheelState); } base.Update(gameTime); }