Hello, for a final project, I am making a "Frogger" clone. I basically have a fly on top of the map, and when you put the frog over the fly, the fly creates another fly at the bottom of the map. I created a Counter so that you would be able to know how many flies you ate.
However in its current state, when the frog tries to eat the fly, it throws out an Exception.
The Following is for the TopFly (it has the same code as the fly on the bottom):
The Following is for the World:
The following is for the Counter:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class TopFly extends Actor
{
int x;
int y;
int gen;
public void act()
{
collected();
}
public void collected()
{
Actor fly = getOneObjectAtOffset(0, 0, Frog.class);
if(fly != null)
{
newFlyX();
StageOne world = (StageOne) getWorld();
world.score();
getWorld().addObject(new BottomFly(), x , 110);
getWorld().removeObject(this);
}
}
public void newFlyX()
{
gen = Greenfoot.getRandomNumber(10);
if (gen > 4)
{
x = 27 + (Greenfoot.getRandomNumber(2)*22);
}
else
{
x = 110 + (Greenfoot.getRandomNumber(2)*22);
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class StageOne extends World
{
int key;
int s;
private Counter counter;
public StageOne()
{
super(160, 116, 5);
prepare();
gameStart();
}
private void prepare()
{
Greenfoot.start();
}
private void gameStart()
{
addObject( new Frog(), getWidth() / 2, 110);
addObject( new TopFly() , getWidth() / 2 , 5);
addObject(new Counter(), getWidth() / 2 , getHeight() / 2);
}
public void score()
{
System.out.println("161");
counter.point();
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
public class Counter extends Actor
{
int count;
public Counter()
{
count = 0;
GreenfootImage theImage = new GreenfootImage( 80, 58 );
setImage(theImage);
updateImage();
}
public void point()
{
System.out.println("162");
count = count + 1;
}
public void updateImage()
{
GreenfootImage myImage = getImage();
myImage.clear();
myImage.setColor(Color.BLACK);
String message = "Count: " + count;
myImage.drawString( message, 10, 30);
}
