示例#1
0
        /// <summary>
        /// Runs all the features and methods that are being used in the game.
        /// Takes the active states features and methods and render those.
        /// </summary>
        public void GameLoop()
        {
            while (win.IsRunning())
            {
                gameTimer.MeasureTime();
                while (gameTimer.ShouldUpdate())
                {
                    win.PollEvents();
                    SpaceBus.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 from the timer
                    win.Title = "Space Taxi | UPS: " + gameTimer.CapturedUpdates + ", FPS: " +
                                gameTimer.CapturedFrames;
                    Game.KeepTrackOfUpdates = gameTimer.CapturedUpdates;
                }
            }
        }
示例#2
0
        public void KeyPress(string key)
        {
            switch (key)
            {
            case "KEY_ESCAPE":
                win.CloseWindow();
                break;

            case "KEY_F12":
                Console.WriteLine("Saving screenshot");
                win.SaveScreenShot();
                break;

            case "KEY_UP":
                SpaceBus.GetBus().RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.PlayerEvent, this, "BOOSTER_UPWARDS", "", ""));
                break;

            case "KEY_LEFT":
                SpaceBus.GetBus().RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.PlayerEvent, this, "BOOSTER_TO_LEFT", "", ""));
                break;

            case "KEY_RIGHT":
                SpaceBus.GetBus().RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.PlayerEvent, this, "BOOSTER_TO_RIGHT", "", ""));
                break;
            }
        }
示例#3
0
        public Game()
        {
            // window
            win = new Window("Space Taxi Game v0.1", 500, AspectRatio.R1X1);

            // event bus
            SpaceBus.GetBus().InitializeEventBus(new List <GameEventType> {
                GameEventType.InputEvent,     // key press / key release
                GameEventType.WindowEvent,    // messages to the window, e.g. CloseWindow()
                GameEventType.GameStateEvent, // commands issued to the player object, e.g. move,
                GameEventType.PlayerEvent     // destroy, receive health, etc.
            });
            stateMachine = new StateMachine();
            win.RegisterEventBus(SpaceBus.GetBus());

            // game timer
            gameTimer = new GameTimer(60); // 60 UPS, no FPS limit


            // event delegation
            SpaceBus.GetBus().Subscribe(GameEventType.InputEvent, this);
            SpaceBus.GetBus().Subscribe(GameEventType.WindowEvent, this);
            SpaceBus.GetBus().Subscribe(GameEventType.PlayerEvent, this);
            SpaceBus.GetBus().Subscribe(GameEventType.GameStateEvent, this);
        }
示例#4
0
        public Player()
        {
            shape = new DynamicShape(new Vec2F(), new Vec2F());
            taxiBoosterOffImageLeft =
                new Image(Path.Combine("Assets", "Images", "Taxi_Thrust_None.png"));
            taxiBoosterOffImageRight =
                new Image(Path.Combine("Assets", "Images", "Taxi_Thrust_None_Right.png"));

            Entity = new Entity(shape, taxiBoosterOffImageLeft);
            SpaceBus.GetBus().Subscribe(GameEventType.PlayerEvent, this);
        }
示例#5
0
        public Game()
        {
            // window
            win          = new Window("Space Taxi Game v0.1", 500, AspectRatio.R1X1);
            stateMachine = new StateMachine();

            // event bus
            SpaceBus.GetBus().InitializeEventBus(new List <GameEventType>()
            {
                GameEventType.InputEvent,      // key press / key release
                GameEventType.WindowEvent,     // messages to the window, e.g. CloseWindow()
                GameEventType.PlayerEvent,     // commands issued to the player object, e.g. move, destroy, receive health, etc.
                GameEventType.GameStateEvent,
                GameEventType.TimedEvent
            });
            win.RegisterEventBus(SpaceBus.GetBus());
            SpaceBus.GetBus().Subscribe(GameEventType.WindowEvent, this);
            SpaceBus.GetBus().Subscribe(GameEventType.GameStateEvent, stateMachine);
            SpaceBus.GetBus().Subscribe(GameEventType.InputEvent, stateMachine);

            // game timer, events
            gameTimer = new GameTimer(60, 60); // 60 UPS, no FPS limit

            Game.levelInfo = new List <string[]>();
            Game.levels    = new List <EntityContainer>();
            //_levelObstacles = new List<CollisionChecker>();
            Game.legendsDictionary      = new Dictionary <char, string>();
            Game.levelDiffrentPlatforms = new List <Dictionary <char, List <Entity> > >();
            Game.levelObstacles         = new List <EntityContainer>();
            Game.levelPlatforms         = new List <EntityContainer>();
            Game.playerXcoordinates     = new List <float>();
            Game.playerYcoordinates     = new List <float>();

            for (var i = 0; i < filePath.Length; i++)
            {
                CreateMap(filePath, i);
            }
        }
示例#6
0
        public void KeyRelease(string key)
        {
            switch (key)
            {
            case "KEY_LEFT":
                SpaceBus.GetBus().RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.PlayerEvent, this, "STOP_ACCELERATE_LEFT", "", ""));
                break;

            case "KEY_RIGHT":
                SpaceBus.GetBus().RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.PlayerEvent, this, "STOP_ACCELERATE_RIGHT", "", ""));
                break;

            case "KEY_UP":
                SpaceBus.GetBus().RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.PlayerEvent, this, "STOP_ACCELERATE_UP", "", ""));
                break;
            }
        }