예제 #1
0
 /// <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.
     pixel = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
     pixel.SetData(new[] { Color.White });
     spriteBatch = new SpriteBatch(GraphicsDevice);
     var startAsteroid = new Asteroid(this.graphics.PreferredBackBufferWidth, this.graphics.PreferredBackBufferHeight, this.Content, pixel);
     startAsteroid.Destroyed += new EventHandler((sender, e) =>
     {
         score += (sender as Asteroid).Score;
         //asteroids.Remove((Asteroid)sender);
     });
     asteroids.Add(startAsteroid);
     dino = new Dinosaur(this.graphics.PreferredBackBufferWidth, this.graphics.PreferredBackBufferHeight, this.Content, pixel);
     dino.Killed += new EventHandler(HandleGameOver);
     scoreFont = Content.Load<SpriteFont>("Fonts/scorefont");
     // TODO: use this.Content to load your game content here
 }
예제 #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();
            if (!IsGameOver)
            {
                foreach (var asteroid in asteroids)
                {
                    asteroid.Update(gameTime);
                    if (asteroid.Bounds.Intersects(dino.Bounds))
                    {
                        //Debug.WriteLine("He dead");
                        dino.Kill();
                    }
                }
                asteroids.RemoveAll(x => x.destroyed == true);
                while (asteroids.Count < 10)
                {
                    var asteroid = new Asteroid(this.graphics.PreferredBackBufferWidth, this.graphics.PreferredBackBufferHeight, this.Content, pixel);
                    asteroid.Destroyed += new EventHandler((sender, e) => score += (sender as Asteroid).Score);
                    asteroids.Add(asteroid);
                }
                dino.Update(gameTime);
            }

            base.Update(gameTime);
        }