I am trying to have a ball reflect off of a tilted paddle. This does not include any gravity. For example: a ball moving left from the left side of the screen would reflect downwards from a paddle tilted at -45 degrees.
Ball class
Paddle Class:
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 | import greenfoot.*; import java.awt.Color; public class Ball extends SmoothMover { public Ball(String side) { GreenfootImage img = new GreenfootImage( 22 , 22 ); img.setColor(Color.GREEN); img.fillOval( 0 , 0 , 22 , 22 ); setImage(img); if (side.equals( "left" )) { addForce( new Vector( 0 , 3 )); } if (side.equals( "right" )) { addForce( new Vector( 180 , 3 )); } if (side.equals( "top" )) { addForce( new Vector( 90 , 3 )); } if (side.equals( "bottom" )) { addForce( new Vector( 270 , 3 )); } } public void act() { move(); collide(); } public void collide() { Paddle pad = (Paddle) getOneIntersectingObject(Paddle. class ); if (pad != null ) { } } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import greenfoot.*; public class Paddle extends Actor { private int rotation; public Paddle( int angle) { GreenfootImage img = new GreenfootImage( 5 , 50 ); img.fill(); setRotation(angle); rotation = angle; setImage(img); } public void act() { } public int getAngle() { return rotation; } } |