Exemple #1
0
        protected override void Initialize()
        {
            // Init shape collision dispatching
            Shape.initialiseCollisionTests();

            // Load tracks
            TrackManager.loadTracks(this);

            // Camera
            camera = new Camera(this);

            // States initialization
            states = new Dictionary <State.Type, State>();
            states[State.Type.MENU]    = new MenuState(this);
            states[State.Type.GAME]    = new GameState(this);
            states[State.Type.VICTORY] = new VictoryState(this);
            states[State.Type.DEFEAT]  = new DefeatState(this);

            currentState = states[State.Type.MENU];

            base.Initialize();
        }
Exemple #2
0
        public override void update(GameTime gameTime)
        {
            if (loaded)
            {
                // Update time
                remainingTime -= gameTime.ElapsedGameTime.Milliseconds;
                playTime      += gameTime.ElapsedGameTime.Milliseconds;

                // Update car
                car.update(gameTime);

                // Update time bonuses
                foreach (TimeBonus timeBonus in timeBonuses)
                {
                    timeBonus.update(gameTime);
                }

                // Update check points
                foreach (CheckPoint checkpoint in checkPoints)
                {
                    checkpoint.update(gameTime);
                }

                // Update scene objects
                foreach (GameObject sceneObject in sceneObjects)
                {
                    sceneObject.update(gameTime);
                }

                // Update camera position (following car)
                game.camera.update(gameTime, car);

                // Collision detection
                collisionManager.checkCollisions();

                // Erase dead elements
                removeErasedCheckPoints();
                removeErasedTimeBonuses();

                // Game state changes
                if (remainingTime <= 0)
                {
                    // Stop engine
                    car.engine.Stop(AudioStopOptions.Immediate);

                    // Defeat
                    game.changeState(State.Type.DEFEAT);
                }

                else if (checkPoints.Count == 0)
                {
                    // Stop engine
                    car.engine.Stop(AudioStopOptions.Immediate);

                    // Check possible record
                    VictoryState victoryState = (VictoryState)(game.states[Type.VICTORY]);
                    victoryState.recordTime = playTime;

                    if (TrackManager.setNewRecord(levelName, playTime))
                    {
                        victoryState.isRecord = true;
                        TrackManager.saveTracks(game);
                    }
                    else
                    {
                        victoryState.isRecord = false;
                    }

                    // Victory
                    game.changeState(State.Type.VICTORY);
                }
            }
        }