Exemple #1
0
        public void GameLoop()
        {
            while (win.IsRunning())
            {
                gameTimer.MeasureTime();
                while (gameTimer.ShouldUpdate())
                {
                    win.PollEvents();

                    GalagaBus.GetBus().ProcessEvents();
                    stateMachine.ActiveState.UpdateGameLogic();
                }

                if (gameTimer.ShouldRender())
                {
                    win.Clear();

                    stateMachine.ActiveState.RenderState();

                    win.SwapBuffers();
                }

                if (gameTimer.ShouldReset())
                {
                    // 1 second has passed - display last captured ups and fps
                    win.Title = "Galaga | UPS: " + gameTimer.CapturedUpdates + ", FPS: " +
                                gameTimer.CapturedFrames;
                }
            }
        }
Exemple #2
0
 private void Die()
 {
     GalagaBus.GetBus().RegisterEvent(
         GameEventFactory <object> .CreateGameEventForAllProcessors(
             GameEventType.GameStateEvent,
             this,
             "CHANGE_STATE",
             "GAME_OVER", ""));
 }
Exemple #3
0
 public LifeBar()
 {
     GalagaBus.GetBus().Subscribe(GameEventType.PlayerEvent, this);
     for (int i = 1; i < 4; i++)
     {
         playerLives.Add(new PlayerLife(
                             new StationaryShape(
                                 new Vec2F(0f, 0f),
                                 new Vec2F(0.05f, 0.05f)),
                             i));
     }
 }
Exemple #4
0
        public Game()
        {
            win       = new Window("Film", 500, 500);
            gameTimer = new GameTimer(60, 144);

            GalagaBus.GetBus().InitializeEventBus(new List <GameEventType> {
                GameEventType.InputEvent,
                GameEventType.WindowEvent,
                GameEventType.PlayerEvent,
                GameEventType.GameStateEvent
            });
            win.RegisterEventBus(GalagaBus.GetBus());
            GalagaBus.GetBus().Subscribe(GameEventType.WindowEvent, this);


            stateMachine = new StateMachine();
            GalagaBus.GetBus().Subscribe(GameEventType.GameStateEvent, stateMachine);
            GalagaBus.GetBus().Subscribe(GameEventType.InputEvent, stateMachine);
        }
Exemple #5
0
 public Player(DynamicShape shape) : base(shape, Player.stride)
 {
     GalagaBus.GetBus().Subscribe(GameEventType.PlayerEvent, this);
     lives = 3;
 }