public GameManager(GameLayout game, string contentDirectory)
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = contentDirectory;

            Template = new Template();
            penumbra = new PenumbraComponent(this);

            Services.AddService(penumbra);

            gameLayout = game;

            // Systems
            systems.Add(renderer         = new Renderer());
            systems.Add(collisionHandler = new CollisionHandler());
            systems.Add(physicsHandler   = new PhysicsHandler());
            systems.Add(animationHandler = new AnimationHandler(Content));
            systems.Add(lightHandler     = new LightHandler(penumbra));
        }
Example #2
0
        public void Run()
        {
            DateTime currentTime = DateTime.UtcNow;
            var      accum       = new TimeSpan();
            TimeSpan maxDt       = TickRate * updateLimit;

            bool playerTurn = false;

            while (!_exiting)
            {
                DateTime newTime   = DateTime.UtcNow;
                TimeSpan frameTime = newTime - currentTime;
                if (frameTime > maxDt)
                {
                    frameTime = maxDt;
                }

                currentTime = newTime;
                accum      += frameTime;

                while (accum >= TickRate)
                {
                    accum -= TickRate;

                    if (!playerTurn)
                    {
                        EventScheduler.FastForward();
                        playerTurn = EventScheduler.UpdateTick();

                        // eat any input if its not the player's turn to act
                        if (Terminal.HasInput())
                        {
                            Terminal.Read();
                        }

                        ProcessTurnEvents();
                    }
                    else
                    {
                        Option <ICommand> action = StateHandler.HandleInput();
                        EventScheduler.ExecuteCommand(Player, action);

                        action.MatchSome(_ =>
                        {
                            if (!PrevCancelled)
                            {
                                ProcessTurnEvents();
                                ProcessPlayerTurnEvents();
                                playerTurn = false;
                            }
                            else
                            {
                                PrevCancelled = false;
                            }
                        });
                    }
                }

                double remaining = accum / TickRate;
                AnimationHandler.Update(frameTime, remaining);
                Render();
            }

            Terminal.Close();
        }