/// <summary> /// Main update loop that controls all other game states /// </summary> /// <param name="gameTime"></param> public void Update(float gameTime) { // If the cursor is on the screen, take input if (DriverInstance.IsActive) { Input.Tick(); } // Update interface and network InterfaceManager.Update(gameTime); NetworkManager.Update(gameTime); // Gamestate management switch (CurState) { case State.Menu: // Decrease blur if (Shader.BlurAmount >= 0f) { Shader.ChangeBlurAmount(Shader.BlurAmount - 0.2f); } // Play the menu music AudioManager.PlaySound("menuMusic", AudioManager.MusicVolume); // Interface Logic if (InterfaceManager.Clicked(Input, "defaultMenu", "playButton")) { InterfaceManager.HidePage("optionsMenu"); InterfaceManager.ShowPage("playMenu"); AudioManager.PlaySound("buttonclick", AudioManager.UiVolume); } else if (InterfaceManager.Clicked(Input, "defaultMenu", "optionsButton")) { InterfaceManager.HidePage("playMenu"); InterfaceManager.ShowPage("optionsMenu"); AudioManager.PlaySound("buttonclick", AudioManager.UiVolume); } else if (InterfaceManager.Clicked(Input, "defaultMenu", "quitButton")) { DriverInstance.Exit(); } else if (InterfaceManager.Clicked(Input, "defaultMenu", "mapEditorButton")) { InterfaceManager.HideAll(); AudioManager.PlaySound("buttonclick", AudioManager.UiVolume); CurState = State.LevelEditor; Editor = new LevelEditor(this); } if (InterfaceManager.Clicked(Input, "playMenu", "connectButton")) { InterfaceManager.HideAll(); AudioManager.PlaySound("buttonclick", AudioManager.UiVolume); CurState = State.Lobby; } break; case State.Options: break; case State.Lobby: switch (NetworkManager.CurState) { case NetworkManager.NetState.Disconnected: if (Input.Tapped(Keys.Escape)) { CurState = State.Menu; } else if (Input.Tapped(Keys.Enter)) { // If the user has entered their name, initiaize connection with the server if (!enterName) { enterName = true; } else { // Connect to the server and initialize game NetworkManager.Connect(Address, Username); GameEngine.Initialize(NetworkManager, AudioManager, Input, DriverInstance.Assets); GameEngine.CurState = GameEngine.GameEngineState.Loaded; AudioManager.StopAllSounds(); } } else { // Get address before name if (!enterName) { Address = Input.GetText(Address); } else { Username = Input.GetText(Username); } } break; case NetworkManager.NetState.Connected: // If the content hasn't been loaded, load the // content first before entering the game if (DriverInstance.Assets.GameContentLoaded) { CurState = State.InGame; InterfaceManager.ShowPage("teamSelectMenu"); } else { DriverInstance.Assets.LoadGameContent(); DriverInstance.Assets.LoadMapContent(); Camera.ResetZoom(); Camera.Position = new Vector2(DriverInstance.Assets.MapData.MapArea.Width / 2f, DriverInstance.Assets.MapData.MapArea.Height / 2f); } break; } break; case State.LevelEditor: // If the editor is exiting, show the menu if (Editor.CurrentState != LevelEditor.EditorStates.Exit) { Editor.Update(gameTime); } else { CurState = State.Menu; InterfaceManager.ShowPage("defaultMenu"); } break; case State.InGame: // Update engine logic GameEngine.Update(gameTime); break; } // If the cursor is on the screen, update input if (DriverInstance.IsActive) { Input.Tock(); } }