Here is code for ball : import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class GoldenBall here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class GoldenBall extends Actor
{
/**
* Act - do whatever the GoldenBall wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
key();
win();
checkballoon();
}
public boolean canMove(int x, int y)
{
Actor sand;
sand=getOneObjectAtOffset(x,y,sandroad.class);
//the section below checks if there is a block you can move to
// if there is it sets sand to a vlaue otherwise it says null
// The errors are in this section
boolean flag=false;
if (sand !=null)
{
flag=true;
}
return flag;
}
/**
* Check if ball hits balloon
*/
private void checkballoon()
{
Actor balloon= getOneIntersectingObject(balloon.class);
if (balloon !=null )
{
getWorld().removeObject(balloon);
}
}
public void key()
{
//Note 1: Down the page increase the y value and going to the right increases the x value
//Note 2: Each block is 60 pixels wide and high
int leftChange=-60;
int rightChange=60;
int upChange=-60;
int downChange=60;
if (Greenfoot.isKeyDown("left"))
{
if (canMove(leftChange, 0)==true){
setLocation(getX()+leftChange, getY()) ;}
}
if (Greenfoot.isKeyDown("right"))
{
if (canMove(rightChange, 0)==true){
setLocation(getX()+rightChange, getY()) ;}
}
if (Greenfoot.isKeyDown("up"))
{
if (canMove(0, upChange)==true){
setLocation(getX(), getY()+upChange) ;}
}
if (Greenfoot.isKeyDown("down"))
{
if (canMove(0, downChange)==true){
setLocation(getX(), getY()+downChange) ;}
}
}
public void win()
{
Actor win;
win=getOneObjectAtOffset(0,0,Goal.class);
if (win !=null)
{
Greenfoot.stop();
}
}
}
And here is code for balloon: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class balloon here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class balloon extends Actor
{
/**
* Act - do whatever the balloon wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(15);
setRotation(Greenfoot.getRandomNumber(540));
}
}
If you could please help me with this i'll be very thankful.

