Test Your Knowledge: Exercise

  1. Let's combine some aspects of this chapter and the previous one. Take the code where we left off at the end of this chapter and modify it to include another nonuser-controlled sprite (use the plus.png image, which is located with the source code for this chapter in the AnimatedSprites\AnimatedSprites\Content\Images folder). Add movement to both nonuser-controlled sprites, as you did in Chapter 2, so that each sprite moves in both the X and Y directions and bounces off the edges of the screen. Add collision detection to the newly added sprite as well. The end result will be a game where you try to avoid two moving sprites. When you hit either sprite, the game ends.

    For clarity in working with the plus.png image, the frame size of the sprite sheet is 75 × 75 pixels, and it has six columns and four rows (note that the rings and skull ball sprite sheets each had six columns and eight rows).

Get Learning XNA 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.