O'Reilly logo

Learning XNA 4.0 by Aaron Reed

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5: Applying Some Object-Oriented Design

Quiz Answers

  1. What class does a game component derive from?

    GameComponent.

  2. If you want to be able to draw on the screen with your game component, what class do you need to derive from?

    DrawableGameComponent.

  3. Fact or fiction: time spent building a solid object-oriented design should not count as time spent developing software, because it is unnecessary and superfluous.

    Absolutely fiction. Creating a proper design up front will help you avoid countless headaches and maintenance issues down the road. Always, no matter what the project, plan ahead and code around a solid design.

  4. What is spontaneous dental hydroplosion?

    As explained by Pam and Jim in The Office episode “Health Care”, spontaneous dental hydroplosion occurs when a person’s teeth turn to liquid and proceed to drip down the back of their throat.

Exercise Answer

Modify the code that you worked on this chapter to create four sprites which move and bounce off all four edges of the screen. To accomplish this, create a new class called BouncingSprite that derives from AutomatedSprite. BouncingSprite should do the same thing that AutomatedSprite does, with the exception that it will check during the Update method to determine whether the sprite has gone off the edge of the screen. If it has, reverse the direction of the sprite by multiplying the speed variable by −1.

Also, make two of the bouncing sprites use the skull image and two of them use the plus image (located with the source code for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required