using System; using Foresight.Engine; using Foresight.Engine.Renderer; using Foresight.Engine.Scenes; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; using Vision.Client; namespace Foresight { public class MainGame : Game { private readonly RendererManager _renderManager; private readonly SceneManager _sceneManager; private readonly LoadingScene _loadingScene; private readonly LoadingScene _mapLoadingScene; private FiestaClient _fiestaClient; public MainGame() { Content.RootDirectory = "Content"; IsMouseVisible = true; _renderManager = new RendererManager(this); _sceneManager = new SceneManager(this); _loadingScene = new LoadingScene(this); _mapLoadingScene = new LoadingScene(this, "Rou"); _sceneManager.SetScene(_loadingScene); _renderManager.Add2DRenderable(_sceneManager); } protected override void LoadContent() { base.LoadContent(); } protected override void UnloadContent() { _renderManager.Dispose(); base.UnloadContent(); } protected override void Update(GameTime gameTime) { var keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.Escape)) Exit(); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); LoadingDemoUpdate(); _renderManager.Render(gameTime); base.Draw(gameTime); } private enum LoadState { LS_LOADINGGAME, LS_LOADEDGAME, LS_LOADINGMAP, LS_LOADEDMAP } private LoadState loadState = LoadState.LS_LOADINGGAME; private double _progress; private const double ProgressStep = 0.01d; private void LoadingDemoUpdate() { switch (loadState) { case LoadState.LS_LOADINGGAME: { _loadingScene.Update(_progress += ProgressStep); if (_progress >= 1.5d) // extra to add delay { loadState = LoadState.LS_LOADEDGAME; } break; } case LoadState.LS_LOADEDGAME: { _progress = 0; _sceneManager.SetScene(_mapLoadingScene); loadState = LoadState.LS_LOADINGMAP; break; } case LoadState.LS_LOADINGMAP: { _mapLoadingScene.Update(_progress += ProgressStep); if (_progress >= 1.5) { loadState = LoadState.LS_LOADEDMAP; } break; } case LoadState.LS_LOADEDMAP: { break; } } } } }