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:
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) {
}
}
}
}
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;
}
}
