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

                while (gameTimer.ShouldUpdate())
                {
                    win.PollEvents();
                    GalagaBus.GetBus().ProcessEvents();
                    stateMachine.ActiveState.GameLoop();
                }

                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
        public Game()
        {
            GalagaBus.GetBus().InitializeEventBus(new List <GameEventType>()
            {
                GameEventType.InputEvent,    // key press / key release
                GameEventType.WindowEvent,   // messages to the window
                GameEventType.GameStateEvent // changes to the game state
            });
            win = new Window("Galaga", 500, 500);

            win.RegisterEventBus(GalagaBus.GetBus());
            GalagaBus.GetBus().Subscribe(GameEventType.WindowEvent, this);
            GalagaBus.GetBus().Subscribe(GameEventType.GameStateEvent, this);

            gameTimer = new GameTimer(60, 60);

            stateMachine = new StateMachine();
        }
Exemple #3
0
        private void KeyPress(string key)
        {
            switch (key)
            {
            case "KEY_ESCAPE":
                GalagaBus.GetBus().RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.WindowEvent, this, "CLOSE_WINDOW", "", ""));
                break;

            case "KEY_RIGHT":
                Direction(new Vec2F(0.01f, 0.0f));
                break;

            case "KEY_LEFT":
                Direction(new Vec2F(-0.01f, 0.0f));
                break;

            case "KEY_SPACE":
                AddShots(Game);
                break;
            }
        }