import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class ball here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ball extends Actor
{
public int xspeed = 4;
public int yspeed = 4;
public static int ballX, ballY;
/** * Act - do whatever the paddle wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX() + xspeed, getY()+yspeed);
bounce();
ballX = getX ();
ballY = getY ();
}
public void bounce()
{
int worldWidth = getWorld().getWidth();
int worldHeight = getWorld().getHeight();
int spriteWidth = getImage().getWidth()/2;
int spriteHieght = getImage().getHeight()/2;
if(getX() <= spriteWidth)
xspeed = xspeed * -1;
if(getX() >= spriteWidth - spriteWidth)
xspeed = xspeed * -1;
if(getY() <= spriteHieght)
yspeed = yspeed * -1;
if(getY() <= spriteHieght)
yspeed = yspeed * -1;
}
}
