Now, we are going to add a very simple collision detection capability to the sprites.
Note
This is not a precise collision detection algorithm. We are going to use a very simple technique to give some life to the game. However, we will improve our collision detection algorithms later in the following chapters. Our current focus is on a good object-oriented design for the sprites and on the modification of the game loop.
We want the aliens to show a different color when they collide with the ship. We want to see the changes necessary to add some logic to the game. We will do that by following these steps:
1. Stay in the
SilverlightInvaders2DVector
project.2. Open the code for the superclass
SpriteWrapper
.3. Add the following
public
method to return a rectangle with the sprite's bounds:public Rect UCBounds() { return new Rect(_location, _size); }
4. Add the following public method to determine whether the
SpriteWrapper
instance received...