public class Paddle extends Actor
{
private Ball myBall;
public boolean attCheck= false;
public Paddle()
{
GreenfootImage myImage = getImage();
int myNewHeight = (int)myImage.getHeight()/2;
int myNewWidth = (int)myImage.getWidth()/2;
myImage.scale(myNewWidth, myNewHeight);
}
public void incSize()
{
GreenfootImage myImage = getImage();
int myNewHeight = (int)myImage.getHeight()/2;
int myNewWidth = (int)myImage.getWidth()/2+55;
myImage.scale(myNewWidth, myNewHeight);
}
public void addedtoWorld(World world)
{
newBall();
}
public void act()
{
if (Greenfoot.isKeyDown("left"))
moveSideways(-8);
if (Greenfoot.isKeyDown("right"))
moveSideways(8);
if (haveBall() && Greenfoot.isKeyDown ("space")) {
releaseBall();
}
}
public void moveSideways(int dist)
{setLocation(getX() + dist, getY());
if(myBall!= null )
myBall.move(dist);
}
public void newBall()
{
myBall= new Ball();
getWorld().addObject (myBall, getX()+6, getY()+18);
}
public boolean haveBall()
{
return myBall != null;
}
public void releaseBall()
{
myBall.release();
myBall = null;
}
}