Example #1
0
        /// <summary>
        /// Recursively looks for an optimal place to spawn an NPC car where it won't collide with any other NPCs
        /// </summary>
        /// <param name="pcCar"></param>
        /// <param name="list"></param>
        /// <param name="car">The car we intend to spawn</param>
        /// <param name="laneNum">the lane on the freeway the car belongs to</param>
        /// <param name="rand">a random number generator we pass by reference</param>
        /// <param name="attemptCount">the number of attempts it has taken us to spawn this car</param>
        public void OptimizeSpawnPosition(PcCar pcCar, IList<Car> list, Car car, int laneNum, ref Random rand, ref int attemptCount)
        {
            Car collisionCar;

            if ((CheckNpcHardCollision(list, car.SoftCollisionBoundary, out collisionCar)
                    || pcCar.SoftCollisionBoundary.Intersects(car.HardCollisionBoundary)
                ) && attemptCount <= MaxSpawnAttempts)
            {

                /* All of this code needs to execute whenever an NPC car has:
                 *  1. Spawned on top of another NPC
                 *  2. Spawned on top of the PC
                 *  3. And the maxmimum number of spawn attempts has not been reached.
                */

                attemptCount++;
                InitializeNpcCar(car, laneNum, ref rand);
                OptimizeSpawnPosition(pcCar, list, car, laneNum, ref rand, ref attemptCount);
            }
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            _backGroundTexture = Content.Load<Texture2D>("Content\\Images\\road");
            _whitecarTexture = Content.Load<Texture2D>("Content\\Images\\whitecar");
            _redcarTexture = Content.Load<Texture2D>("Content\\Images\\redcar");
            _bluecarTexture = Content.Load<Texture2D>("Content\\Images\\bluecar");
            World.Explosions = new List<Texture2D>
                              {
                                  Content.Load<Texture2D>("Content\\Images\\explosion_1"),
                                  Content.Load<Texture2D>("Content\\Images\\explosion_2"),
                                  Content.Load<Texture2D>("Content\\Images\\explosion_3"),
                                  Content.Load<Texture2D>("Content\\Images\\explosion_4")
                              };
            _explosionSoundEffect = Content.Load<SoundEffect>("Content\\Audio\\Explosion");
            _font = Content.Load<SpriteFont>("Content\\Fonts\\GameText");
            _background.LoadContent(GraphicsDevice, _backGroundTexture);
            _world = new World(new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height));
            _scoreBoard = new ScoreBoard("Your Score: ", ref _world.Bounds, _font);

            _pc = new PcCar(_redcarTexture);
            _world.InitializePcCar(_pc);
            _pc.LoadNpcCars(_world, Cars, 17, new Texture2D[] { _whitecarTexture, _bluecarTexture });

            TouchPanel.EnabledGestures = GestureType.FreeDrag;
        }
Example #3
0
 public void CheckNpcSoftCollision(IList<Car> cars, PcCar pc)
 {
 }