In my Tank Game your bullets bounce once if they hit a wall (just like a pool ball). My problem is to figure out the following two things:
Here i check whether i hit a wall from the left/right or top/bottom (is this needed? is this done the right way? My world is 1200 x 800 large).
My second problem is the actual formula. I want to setRotation(someValue) dependent on getRotation().
So it should look like something like this: setRotation(getRotation()-bla+blabla*something%idontknow).
Is checking if i hit left, right, top, bottom of the border walls necessary?
If yes, do i check the right way with th world being rectangular (1200x800)?
What is the formula for the new rotation dependent on the current/old rotation?
Thank you!
1 2 3 4 5 6 7 8 9 10 11 12 | if (getOneIntersectingObject(Wall. class ) != null && bounceCounter < 2 ) { //if touches wall and bounced less than 2 times Wall wall = (Wall) getOneIntersectingObject(Wall. class ); //save wall if (Math.abs(wall.getX()-getX()) < Math.abs(wall.getY()-getY())) { //top bottom side //setNewRotation! move( 5 *QVAL); //get away from wall for next frame } else if (Math.abs(wall.getX()-getX()) < Math.abs(wall.getY()-getY())) { //left right side //setNewRotation! move( 5 *QVAL); //get away from wall for next frame } bounceCounter++; return true ; } |