Example #1
0
        /// <summary>
        /// GameLoop utilizes the GameTimer class to ensure that the game runs at a steady speed on all systems.
        /// We update both rendering and game logic in the loop. The speed of the updates are specified in the gameTimer object.
        /// </summary>
        public void GameLoop()
        {
            //AddEnemies();
            row.CreateEnemies(enemyStrides);

            while (win.IsRunning())
            {
                gameTimer.MeasureTime();
                while (gameTimer.ShouldUpdate())
                {
                    win.PollEvents();
                    eventBus.ProcessEvents();

                    player.Move();

                    movementStrategy.MoveEnemies(row.Enemies);

                    IterateShots();
                }

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

                    player.entity.RenderEntity();

                    row.Enemies.Iterate(entity => entity.RenderEntity());

                    foreach (var shot in playerShots)
                    {
                        shot.RenderEntity();
                    }

                    explosions.RenderAnimations();

                    score.RenderScore();

                    win.SwapBuffers();
                }

                if (gameTimer.ShouldReset())
                {
                    // 1 second has passed - display last captured ups and fps
                    win.Title = "Galaga | UPS: " + gameTimer.CapturedUpdates +
                                ", FPS: " + gameTimer.CapturedFrames;
                }
            }
        }
Example #2
0
        public void MoveFunction(string moveFunc)
        {
            switch (moveFunc)
            {
            case "down":
                moveDown.MoveEnemies(createEnemiesLine.Enemies);
                break;

            case "zigzag":
                zigZagDown.MoveEnemies(createEnemiesSpot.Enemies);
                break;

            case "nomove":
                noMove.MoveEnemies(createEnemiesZig.Enemies);
                break;
            }
        }