Part of my grade in my computer programming class is adding my own touch to the scenarios. Right now I am trying to add 3 lives in the asteroid scenario and have the Rocket completely stop after respawning. I have this working somewhat but am running into a few issues. The Rocket does spawn 3 times, and the game ends after the 3rd. Also, the Rocket does come to a complete stop, but ONLY when hit going directly up/down or left/right into an asteroid. If the rocket crashes into the asteroid sideways, it respawns at an uncontrollable speed. I'm not sure why it does this only when the rocket is sideways when intersecting with the asteroid. My Rocket class is almost exactly the same as the pre-made one in Asteroids-3 with the following additions:
-added a private int variable called lives
-added a private int called thrustDelay (prevents you from respawning at a very fast speed)
-set the lives to 3 in the constructor
-set the thrustDelay to 1000000000 in the constructor
-changed the checkCollision to:
I have no idea what could possibly be masking the rocket not come to a stop when intersecting with an asteroid sideways. To make sure it is not a mistake on part, those variables and the checkCollision are the only thing different from the pre-made Asteroid-3. If anyone could provide any insight it would be greatly appreciated. Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | private void checkCollision() { Actor a = getOneIntersectingObject(Asteroid. class ); if (a != null ) { lives--; Space space = (Space) getWorld(); space.addObject( new Explosion(), getX(), getY()); setLocation(space.getWidth()/ 2 , space.getHeight()/ 2 ); addForce( new Vector(getRotation(),-getSpeed())); thrustDelay= 0 ; if (lives<= 0 ) { space.removeObject( this ); space.gameOver(); } } } |