what method could i use so that the paddle moves when the mouse presses it and follows it so that it can hit the puck
private boolean mouseKeyDown = false;
public void act() {
if (!mouseKeyDown && Greenfoot.mousePressed(null)) {
mouseKeyDown = true;
}
else if (mouseKeyDown && Greenfoot.mouseClicked(null)) {
mouseKeyDown = false;
}
if (mouseKeyDown) {
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse != null) {
setLocation(mouse.getX(), mouse.getY());
}
}
}//in your puck class:
private int speed = 5;
public void act() {
move(speed);
}
public void setSpeed(int speed) {
this.speed = speed;
}//in your paddle class:
public void act() {
//the mouse follower stuff;
Puck puck = getOneIntersectingObject(Puck.class);
if (puck != null) {
puck.setSpeed(7);//or any other value;
}
}