this is the code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Gem here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Gem extends All
{
public int xSpeed= 3;
public int ySpeed= 3;
/**
* Act - do whatever the Gem wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move();
paddleBounce();
wallBounce();
}
public void move()
{setLocation( getX() + xSpeed, getY() + ySpeed);
}
public void wallBounce()
{
if(getX() >= getWorld().getWidth()-getImage().getWidth()/2)
{
xSpeed= xSpeed *-1;
}
if(getY() >= getWorld().getHeight()-getImage().getHeight()/2)
{
ySpeed= ySpeed * 1;
}
}
public Gem()
{
GreenfootImage myImage = getImage();
int myNewHeight = (int)myImage.getHeight()/12;
int myNewWidth = (int)myImage.getWidth()/12;
myImage.scale(myNewWidth, myNewHeight);
}
public void paddleBounce()
{
Actor bar = getOneIntersectingObject(Bar.class);
if(bar !=null)
{
ySpeed=ySpeed*-1;
}
Actor ComputerBar = getOneIntersectingObject(ComputerBar.class);
if(ComputerBar !=null)
{
ySpeed=ySpeed*-1;
}
}
}
