So I recently started an endeavor to recreate pong with my own little twists. So I added three internal walls that are their own actors, one moves up the other two down and they hit the walls and come back the other way. I have created goals. A top barrier wall, lower barrier wall, and goal barriers(4 of them, each is the same actor), and two paddles. My issue is with the ball. The ball bounces off the walls and paddles relatively good, however, it gets stuck, gets launched out of the world, or rotates in the same spot for awhile then launches out again. Here is the code I am using for the ball and its interactions with other objects outside of the goals.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | public void ballHitSomething() { if (isAtEdge()) { turn(Greenfoot.getRandomNumber( 541 )+getRotation()); } if (isTouching(LeftPaddle. class )) { turn(Greenfoot.getRandomNumber( 541 )-getRotation()); } if (isTouching(RightPaddle. class )) { turn(Greenfoot.getRandomNumber( 541 )-getRotation()); } if (isTouching(TopWall. class )) { turn(Greenfoot.getRandomNumber( 361 )-getRotation()); } if (isTouching(BottomWall. class )) { turn(Greenfoot.getRandomNumber( 361 )+getRotation()); } if (isTouching(WallMiddle. class )) { turn(Greenfoot.getRandomNumber( 541 )+getRotation()); } if (isTouching(WallRight. class )) { turn(Greenfoot.getRandomNumber( 541 )+getRotation()); } if (isTouching(WallLeft. class )) { turn(Greenfoot.getRandomNumber( 541 )+getRotation()); } if (isTouching(GoalBarrier. class )) { turn(Greenfoot.getRandomNumber( 541 )+getRotation()); } } |