1
Graphics / Collision detection between two sprites in different classes
« on: February 08, 2011, 05:25:21 am »
Right now what my program does is this:
It creates and renders a Player sprite, a Bullet sprite, and a Centipede sprite. The Bullet and Player sprite are in one class, and the Centipede sprite in a different class. The Bullet sprite is 'parented' to the Player sprite: When it moves, the Bullet moves too.
When I press spacebar, the bullet sprite changes color and moves until it reaches the top of the screen. When it does, it changes it's color back to white, and continues following the Player sprite. However, when the Bullet sprite touches the Centipede sprite, (It's X coordinate is greater then it's left corner, but less then it's right corner, etc.) I want the Centipede sprite to disappear to show it's been hit.
What would be the best way to do this? (The player has a reference of the Centipede instance, so I can just call a function)
Do I remove the entire instance of the Centipede class using the delete command, or just the sprite? Do I just set the color of the sprite to black?
It creates and renders a Player sprite, a Bullet sprite, and a Centipede sprite. The Bullet and Player sprite are in one class, and the Centipede sprite in a different class. The Bullet sprite is 'parented' to the Player sprite: When it moves, the Bullet moves too.
When I press spacebar, the bullet sprite changes color and moves until it reaches the top of the screen. When it does, it changes it's color back to white, and continues following the Player sprite. However, when the Bullet sprite touches the Centipede sprite, (It's X coordinate is greater then it's left corner, but less then it's right corner, etc.) I want the Centipede sprite to disappear to show it's been hit.
What would be the best way to do this? (The player has a reference of the Centipede instance, so I can just call a function)
Do I remove the entire instance of the Centipede class using the delete command, or just the sprite? Do I just set the color of the sprite to black?