I am currently attempting to work on a shield for an Asteroids game. The shield is supposed to reflect or "bounce" the Asteroids off it for a set period of acts.
I have the code for the time and creation but *even after a few hours of looking at examples* that I cannot figure out how to write the code in the Asteroids class for it to bounce off the shield when it is hit.
The Asteroids are a SmoothMover subclass as well as it is has a Vector class.
Any help would be appreciated!
Heres what I currently have for code
I have tried another version of code for this but was soon stuck
I tried using the same type of code as It would be for bullets hitting the asteroid but became stuck when I could not figure out how to change the direction of the asteroid.
1 2 3 4 5 6 7 | public void checkCollision() { List<Asteroid> a = (List<Asteroid>) getOneIntersectingObject(Shield. class ); if (a != null ) { //The Asteroids will bounce off the shield when it intersects } } |
1 2 3 4 5 6 7 | public void checkCollision() { Asteroid a = (Asteroid) getOneIntersectingObject(Shield. class ); if (a != null ) { //The Asteroids will bounce off the shield when it intersects } } |