Example #1
0
    void Awake()
    {
        DontDestroyOnLoad(this);
        instance = this;

        Game = new GameStateManager();
        Game.Initialize();

        Game.AddState("WaitingForPlayers", new WaitingForPlayers());
        Game.AddState("Playing", new Playing());
        Game.AddState("GameOver", new GameOver());

        Game.ChangeState("WaitingForPlayers");
    }
Example #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            stateManager = GameStateManager.Instance;
            stateManager.SetContentManager(Content);
            stateManager.AddState(new MainMenuState(graphics.GraphicsDevice)
            {
                ID = 1
            });
            stateManager.AddState(new TestState(graphics.GraphicsDevice)
            {
                ID = 2
            });

            base.Initialize();
        }
Example #3
0
        /// <summary>
        /// Starts the engine
        /// </summary>
        /// <param name="state">The state the engine will start running with. (Start-up state)</param>
        public void Run(GameState state)
        {
            // Throw exception if the game (engine) is already running (not sure if possible)
            if (_isRunning)
            {
                throw new Exception("Engine is already running.");
            }

            // Mark the game (engine) as running
            _isRunning = true;

            // Add the starup state
            if (state != null)
            {
                _states.AddState(state);
            }

            // Gameloop
            while (_isRunning)
            {
                GameLoop();
            }

            // Clear game components
            GameConsole.WriteLine("Cleaning up...");
            _states.Clear();

            // End
            GameConsole.WriteLine("Game ended.");
        }
Example #4
0
        public void LoadWorld(WorldProvider worldProvider, INetworkProvider networkProvider)
        {
            PlayingState playState = new PlayingState(this, GraphicsDevice, worldProvider, networkProvider);

            LoadingWorldState loadingScreen = new LoadingWorldState();

            GameStateManager.AddState("loading", loadingScreen);
            GameStateManager.SetActiveState("loading");

            worldProvider.Load(loadingScreen.UpdateProgress).ContinueWith(task =>
            {
                GameStateManager.RemoveState("play");
                GameStateManager.AddState("play", playState);

                if (networkProvider.IsConnected)
                {
                    GameStateManager.SetActiveState("play");
                }
                else
                {
                    GameStateManager.RemoveState("play");
                    worldProvider.Dispose();
                }

                GameStateManager.RemoveState("loading");
            });
        }
Example #5
0
        protected override void LoadContent()
        {
            var fontStream = Assembly.GetEntryAssembly().GetManifestResourceStream("Alex.Resources.DebugFont.xnb");

            DebugFont = (WrappedSpriteFont)Content.Load <SpriteFont>(fontStream.ReadAllBytes());

            _spriteBatch = new SpriteBatch(GraphicsDevice);
            InputManager = new InputManager(this);
            GuiRenderer  = new GuiRenderer(this);
            GuiManager   = new GuiManager(this, InputManager, GuiRenderer);

            GuiDebugHelper = new GuiDebugHelper(GuiManager);

            AlexIpcService = new AlexIpcService();
            Services.AddService <AlexIpcService>(AlexIpcService);
            AlexIpcService.Start();

            OnCharacterInput += GuiManager.FocusManager.OnTextInput;

            GameStateManager = new GameStateManager(GraphicsDevice, _spriteBatch, GuiManager);

            var splash = new SplashScreen();

            GameStateManager.AddState("splash", splash);
            GameStateManager.SetActiveState("splash");

            WindowSize = this.Window.ClientBounds.Size;
            //	Log.Info($"Initializing Alex...");
            ThreadPool.QueueUserWorkItem((o) => { InitializeGame(splash); });
        }
Example #6
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            gameObjectSpriteBatch = new SpriteBatch(GraphicsDevice);
            overlaySpriteBatch    = new SpriteBatch(GraphicsDevice);

            // Init AssetManager and DrawingHelper
            AssetManager.Init(Content);
            DrawingHelper.Init(GraphicsDevice);

            // Load the main configuration file, load all subconfigs
            LoadConfiguration();

            // Load players
            Player blue = new Player("Blue", "Blue", Color.SteelBlue, mainConfiguration.GetProperty <int>("player.startingMoney"));
            Player red  = new Player("Red", "Red", Color.IndianRed, mainConfiguration.GetProperty <int>("player.startingMoney"));

            // Adds battleState to the GamestateManager
            GameStateManager.AddState("economy", new EconomyState(blue, red));
            GameStateManager.AddState("battle", new BattleState(blue, red));
            GameStateManager.AddState("mainMenu", new MainMenuState());
            GameStateManager.AddState("settingsMenu", new SettingsMenuState());
            GameStateManager.AddState("playerWin", new PlayerWinState());
            GameStateManager.SwitchState("mainMenu", true);
        }
Example #7
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here

            gameStateManager.AddState(new GameStates.TitleState(), "title");
        }
Example #8
0
        // Constructor(s)
        public GameEngine(GameArgs args)
        {
            // Copy arguments (to avoid outside editing of the arguments)
            _args = new GameArgs(args);

            // Console
            GameConsole.Initialize();

            // Content
            _content = new ContentManager(args.Content);

            // GameStates
            _states = new GameStateManager(this, args.States);

            // Graphics
            _graphics = new GraphicsRenderer();
            _graphics.SetRenderSize(args.Graphics.ResolutionWidth, args.Graphics.ResolutionHeight);

            // Input
            _input = new InputManager(args.Input);

            //
            _users = new UserManager(9001);

            // Time
            _time = new TimeManager(args.Time);

            // Window
            CreateWindow(args.Window);

            // Add Debug GameState
            if (args.Debug.Activated)
            {
                _states.AddState(new Debugging.DebugGameState(args.Debug));
            }
        }
        protected override void LoadContent()
        {
            //Create play state.
            var playState = new PlayState(GraphicsDevice, Content);

            playState.Initialize();
            playState.LoadLevel("Maps/debug0.tmx");

            keyboard.KeyDown += e => {
                if (e.Key == Keys.F2)
                {
                    playState.ReloadLevel();
                }
            };

            //screen.DebugProfilers.RegisterProfiler(typeof(Entity), new EntityDebugProfiler());
            //screen.DebugProfilers.RegisterProfiler(typeof(Player), new PlayerDebugProfiler());

            playState.Enabled = true;
            playState.Visible = true;

            //Load it into the manager.
            GameStateManager.AddState(playState);
        }
 private void InitGameStateManager()
 {
     StateManager = new GameStateManager(new MenuState());
     StateManager.AddState(new GameState());
     StateManager.AddState(new GameOverState());
 }
Example #11
0
        protected override void LoadContent()
        {
            var options = Services.GetService <IOptionsProvider>();

            options.Load();

            DebugFont = (WrappedSpriteFont)Content.Load <SpriteFont>("Alex.Resources.DebugFont.xnb");

            ResourceManager.BlockEffect    = Content.Load <Effect>("Alex.Resources.Blockshader.xnb").Clone();
            ResourceManager.LightingEffect = Content.Load <Effect>("Alex.Resources.Lightmap.xnb").Clone();
            //	ResourceManager.BlockEffect.GraphicsDevice = GraphicsDevice;

            _spriteBatch = new SpriteBatch(GraphicsDevice);
            InputManager = new InputManager(this);

            GuiRenderer = new GuiRenderer();
            //GuiRenderer.Init(GraphicsDevice);

            GuiManager = new GuiManager(this, Services, InputManager, GuiRenderer, options);
            GuiManager.Init(GraphicsDevice, Services);

            options.AlexOptions.VideoOptions.UseVsync.Bind((value, newValue) => { SetVSync(newValue); });
            if (options.AlexOptions.VideoOptions.UseVsync.Value)
            {
                SetVSync(true);
            }

            options.AlexOptions.VideoOptions.Fullscreen.Bind((value, newValue) => { SetFullscreen(newValue); });
            if (options.AlexOptions.VideoOptions.Fullscreen.Value)
            {
                SetFullscreen(true);
            }

            options.AlexOptions.VideoOptions.LimitFramerate.Bind((value, newValue) =>
            {
                SetFrameRateLimiter(newValue, options.AlexOptions.VideoOptions.MaxFramerate.Value);
            });

            options.AlexOptions.VideoOptions.MaxFramerate.Bind((value, newValue) =>
            {
                SetFrameRateLimiter(options.AlexOptions.VideoOptions.LimitFramerate.Value, newValue);
            });

            if (options.AlexOptions.VideoOptions.LimitFramerate.Value)
            {
                SetFrameRateLimiter(true, options.AlexOptions.VideoOptions.MaxFramerate.Value);
            }

            options.AlexOptions.VideoOptions.Antialiasing.Bind((value, newValue) =>
            {
                SetAntiAliasing(newValue > 0, newValue);
            });

            options.AlexOptions.MiscelaneousOptions.Language.Bind((value, newValue) =>
            {
                GuiRenderer.SetLanguage(newValue);
            });
            GuiRenderer.SetLanguage(options.AlexOptions.MiscelaneousOptions.Language);

            SetAntiAliasing(options.AlexOptions.VideoOptions.Antialiasing > 0,
                            options.AlexOptions.VideoOptions.Antialiasing.Value);

            GuiDebugHelper = new GuiDebugHelper(GuiManager);

            OnCharacterInput += GuiManager.FocusManager.OnTextInput;

            GameStateManager = new GameStateManager(GraphicsDevice, _spriteBatch, GuiManager);

            var splash = new SplashScreen();

            GameStateManager.AddState("splash", splash);
            GameStateManager.SetActiveState("splash");

            WindowSize = this.Window.ClientBounds.Size;
            //	Log.Info($"Initializing Alex...");
            ThreadPool.QueueUserWorkItem(() =>
            {
                try
                {
                    InitializeGame(splash);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, $"Could not initialize! {ex}");
                }
            });
        }
Example #12
0
        protected override void LoadContent()
        {
            Stopwatch loadingStopwatch = Stopwatch.StartNew();

            var builtInFont = ResourceManager.ReadResource("Alex.Resources.default_font.png");

            var image = Image.Load <Rgba32>(builtInFont);

            OnResourcePackPreLoadCompleted(image, McResourcePack.BitmapFontCharacters.ToList());

            var options = Services.GetService <IOptionsProvider>();

            options.Load();

            //	DebugFont = (WrappedSpriteFont) Content.Load<SpriteFont>("Alex.Resources.DebugFont.xnb");

            //	ResourceManager.EntityEffect = Content.Load<Effect>("Alex.Resources.Entityshader.xnb").Clone();
#if DIRECTX
            ResourceManager.BlockEffect    = Content.Load <Effect>("Alex.Resources.Blockshader_dx.xnb").Clone();
            ResourceManager.LightingEffect = Content.Load <Effect>("Alex.Resources.Lightmap_dx.xnb").Clone();
#else
            ResourceManager.BlockEffect    = Content.Load <Effect>("Alex.Resources.Blockshader.xnb").Clone();
            ResourceManager.LightingEffect = Content.Load <Effect>("Alex.Resources.Lightmap.xnb").Clone();
#endif
            //	ResourceManager.BlockEffect.GraphicsDevice = GraphicsDevice;

            _spriteBatch = new SpriteBatch(GraphicsDevice);
            InputManager = new InputManager(this);

            GuiRenderer = new GuiRenderer();
            //GuiRenderer.Init(GraphicsDevice);

            GuiManager = new GuiManager(this, Services, InputManager, GuiRenderer, options);
            GuiManager.Init(GraphicsDevice, Services);

            options.AlexOptions.VideoOptions.FancyGraphics.Bind(
                (value, newValue) =>
            {
                Block.FancyGraphics = newValue;
            });

            Block.FancyGraphics = options.AlexOptions.VideoOptions.FancyGraphics.Value;

            options.AlexOptions.VideoOptions.UseVsync.Bind((value, newValue) => { SetVSync(newValue); });

            if (options.AlexOptions.VideoOptions.UseVsync.Value)
            {
                SetVSync(true);
            }

            options.AlexOptions.VideoOptions.Fullscreen.Bind((value, newValue) => { SetFullscreen(newValue); });

            if (options.AlexOptions.VideoOptions.Fullscreen.Value)
            {
                SetFullscreen(true);
            }

            options.AlexOptions.VideoOptions.LimitFramerate.Bind(
                (value, newValue) =>
            {
                SetFrameRateLimiter(newValue, options.AlexOptions.VideoOptions.MaxFramerate.Value);
            });

            options.AlexOptions.VideoOptions.MaxFramerate.Bind(
                (value, newValue) =>
            {
                SetFrameRateLimiter(options.AlexOptions.VideoOptions.LimitFramerate.Value, newValue);
            });

            if (options.AlexOptions.VideoOptions.LimitFramerate.Value)
            {
                SetFrameRateLimiter(true, options.AlexOptions.VideoOptions.MaxFramerate.Value);
            }

            options.AlexOptions.VideoOptions.Antialiasing.Bind(
                (value, newValue) => { SetAntiAliasing(newValue > 0, newValue); });

            options.AlexOptions.MiscelaneousOptions.Language.Bind(
                (value, newValue) => { GuiRenderer.SetLanguage(newValue); });

            if (!GuiRenderer.SetLanguage(options.AlexOptions.MiscelaneousOptions.Language))
            {
                GuiRenderer.SetLanguage(CultureInfo.InstalledUICulture.Name);
            }

            options.AlexOptions.VideoOptions.SmoothLighting.Bind(
                (value, newValue) => { ResourcePackBlockModel.SmoothLighting = newValue; });

            ResourcePackBlockModel.SmoothLighting = options.AlexOptions.VideoOptions.SmoothLighting.Value;

            SetAntiAliasing(
                options.AlexOptions.VideoOptions.Antialiasing > 0, options.AlexOptions.VideoOptions.Antialiasing.Value);

            GuiDebugHelper = new GuiDebugHelper(GuiManager);

            OnCharacterInput += GuiManager.FocusManager.OnTextInput;

            GameStateManager = new GameStateManager(GraphicsDevice, _spriteBatch, GuiManager);

            var splash = new SplashScreen();
            GameStateManager.AddState("splash", splash);
            GameStateManager.SetActiveState("splash");

            WindowSize = this.Window.ClientBounds.Size;

            //	Log.Info($"Initializing Alex...");
            ThreadPool.QueueUserWorkItem(
                (o) =>
            {
                try
                {
                    InitializeGame(splash);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, $"Could not initialize! {ex}");
                }
                finally
                {
                    loadingStopwatch.Stop();
                    Log.Info($"Startup time: {loadingStopwatch.Elapsed}");
                }
            });
        }
Example #13
0
        private void InitializeGame(IProgressReceiver progressReceiver)
        {
            progressReceiver.UpdateProgress(0, "Initializing...");
            Extensions.Init(GraphicsDevice);
            MCPacketFactory.Load();

            ConfigureServices();

            var options = Services.GetService <IOptionsProvider>();

            string pluginDirectoryPaths = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            var pluginDir = options.AlexOptions.ResourceOptions.PluginDirectory;

            if (!string.IsNullOrWhiteSpace(pluginDir))
            {
                pluginDirectoryPaths = pluginDir;
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(LaunchSettings.WorkDir) && Directory.Exists(LaunchSettings.WorkDir))
                {
                    pluginDirectoryPaths = LaunchSettings.WorkDir;
                }
            }

            foreach (string dirPath in pluginDirectoryPaths.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                string directory = dirPath;
                if (!Path.IsPathRooted(directory))
                {
                    directory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), dirPath);
                }

                PluginManager.DiscoverPlugins(directory);
            }


            ProfileManager.LoadProfiles(progressReceiver);

            //	Log.Info($"Loading resources...");
            Resources = new ResourceManager(GraphicsDevice, Storage, options);
            if (!Resources.CheckResources(GraphicsDevice, progressReceiver,
                                          OnResourcePackPreLoadCompleted))
            {
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();
                Exit();
                return;
            }

            GuiRenderer.LoadResourcePack(Resources.ResourcePack);
            AnvilWorldProvider.LoadBlockConverter();

            GameStateManager.AddState <TitleState>("title");

            if (LaunchSettings.ConnectOnLaunch && ProfileService.CurrentProfile != null)
            {
                ConnectToServer(LaunchSettings.Server, ProfileService.CurrentProfile, LaunchSettings.ConnectToBedrock);
            }
            else
            {
                GameStateManager.SetActiveState <TitleState>("title");
                var player = new Player(GraphicsDevice, this, null, null, new Skin(), null, PlayerIndex.One);
                player.Inventory.IsPeInventory = true;
                Random rnd = new Random();
                for (int i = 0; i < player.Inventory.SlotCount; i++)
                {
                    player.Inventory[i] = new ItemBlock(BlockFactory.AllBlockstates.ElementAt(rnd.Next() % BlockFactory.AllBlockstates.Count).Value)
                    {
                        Count = rnd.Next(1, 64)
                    };
                }
                //GuiManager.ShowDialog(new GuiPlayerInventoryDialog(player, player.Inventory));
            }

            GameStateManager.RemoveState("splash");
        }