Exemplo n.º 1
0
 public void GameLoop()
 {
     while (win.IsRunning())
     {
         gameTimer.MeasureTime();
         while (gameTimer.ShouldUpdate())
         {
             win.PollEvents();
             GalagaBus.GetBus().ProcessEvents();
             stateMachine.ActiveState.UpdateGameLogic();
             playerShots    = newPlayerShots;
             newPlayerShots = new List <PlayerShot>();
         }
         if (gameTimer.ShouldRender())
         {
             win.Clear();
             stateMachine.ActiveState.RenderState();
             foreach (var elem in playerShots)
             {
                 elem.RenderEntity();
             }
             win.SwapBuffers();
         }
         if (gameTimer.ShouldReset())
         {
             win.Title = "Galaga | UPS: " + gameTimer.CapturedUpdates +
                         ", FPS: " + gameTimer.CapturedFrames;
         }
     }
 }
Exemplo n.º 2
0
        public StateMachine()
        {
            ActiveState = MainMenu.GetInstance();

            GalagaBus.GetBus().Subscribe(GameEventType.GameStateEvent, this);
            GalagaBus.GetBus().Subscribe(GameEventType.InputEvent, this);
        }
Exemplo n.º 3
0
 private void KeyRelease(string key)
 {
     if (key.Equals("KEY_A") || key.Equals("KEY_D"))
     {
         GalagaBus.GetBus().RegisterEvent(
             GameEventFactory <object> .CreateGameEventForSpecificProcessor(
                 GameEventType.PlayerEvent, this, GameRunning.GetInstance(this).player, "stop move", "", ""));
     }
 }
Exemplo n.º 4
0
 public Player(DynamicShape shape, IBaseImage image)
 {
     //this.game = game;
     GalagaBus.GetBus().Subscribe(GameEventType.PlayerEvent, this);
     entity          = new Entity(shape, image);
     PlayerShots     = new List <PlayerShot>();
     PlayerShotImage = new Image(
         Path.Combine("Assets", "Images", "BulletRed2.png"));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor for Game class
        /// </summary>
        public Game()
        {
            win       = new Window("Galaga", 500, 500);
            gameTimer = new GameTimer(60, 60);


            eventBus = GalagaBus.GetBus();
            eventBus.InitializeEventBus(new List <GameEventType> {
                GameEventType.InputEvent,  // key press / key release
                GameEventType.WindowEvent, // messages to the window
                GameEventType.PlayerEvent,
                GameEventType.GameStateEvent
            });
            win.RegisterEventBus(eventBus);
            eventBus.Subscribe(GameEventType.WindowEvent, this);
            stateMachine = new StateMachine();
        }
Exemplo n.º 6
0
 public Game()
 {
     win       = new Window("test", 500, 500);
     gameTimer = new GameTimer(60, 60);
     GalagaBus.GetBus().InitializeEventBus(new List <GameEventType>()
     {
         GameEventType.InputEvent,
         GameEventType.WindowEvent,
         GameEventType.GameStateEvent,
         GameEventType.PlayerEvent
     });
     win.RegisterEventBus(GalagaBus.GetBus());
     stateMachine = new StateMachine(this);
     shotImages   = new Image(Path.Combine("Assets", "Images", "BulletRed2.png"));
     playerShots  = new List <PlayerShot>();
     GalagaBus.GetBus().Subscribe(GameEventType.InputEvent, this);
     GalagaBus.GetBus().Subscribe(GameEventType.WindowEvent, this);
 }
Exemplo n.º 7
0
        public Game()
        {
            gameTimer = new GameTimer();
            win       = new Window("Galaca", 500, AspectRatio.R1X1);

            // eventBus for various GameEvents
            eventBus = GalagaBus.GetBus();
            eventBus.InitializeEventBus(new List <GameEventType>()
            {
                GameEventType.GameStateEvent,
                GameEventType.InputEvent,
                GameEventType.WindowEvent,
                GameEventType.PlayerEvent
            });

            // The eventBus is linked to the window
            win.RegisterEventBus(eventBus);
            eventBus.Subscribe(GameEventType.WindowEvent, this);

            stateMachine = new StateMachine();
        }