/// <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 ); var startAsteroid = new Asteroid( this.graphics.PreferredBackBufferWidth, this.graphics.PreferredBackBufferHeight, this.Content ); startAsteroid.Destroyed += new EventHandler( ( sender, e ) => { score += ( sender as Asteroid ).Score; } ); asteroids.Add( startAsteroid ); dino = new Dinosaur( graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, Content ); dino.Killed += new EventHandler( HandleGameOver ); scoreFont = Content.Load<SpriteFont>( "Fonts/scorefont" ); // TODO: use this.Content to load your game content here font = Content.Load<SpriteFont>( "spriteFont1" ); }
/// <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 ) { if ( GamePad.GetState( PlayerIndex.One ).Buttons.Back == ButtonState.Pressed ) { Exit(); } if ( !IsGameOver ) { foreach ( var asteroid in asteroids ) { asteroid.Update( gameTime ); if ( asteroid.Bounds.Intersects( dino.Bounds ) ) { dino.Kill(); } } asteroids.RemoveAll( x => x.destroyed == true ); while ( asteroids.Count < 10 ) { var asteroid = new Asteroid( this.graphics.PreferredBackBufferWidth, this.graphics.PreferredBackBufferHeight, this.Content ); asteroid.Destroyed += new EventHandler( ( sender, e ) => score += ( sender as Asteroid ).Score ); asteroids.Add( asteroid ); } dino.Update( gameTime ); } // TODO: Add your update logic here base.Update( gameTime ); }