The basic premise of my game is very simple; you are a seal, and you are trying to eat grapes and kill camels. You have to hold space to kill the camels, and if you don't they kill you. I want there to be a cool down time for the space bar press, so you can hold it for 3 seconds, then you have to wait two or something like that.
This is the code for my seal, and the spacebar:
public void nom()
{
Actor camel;
camel = getOneObjectAtOffset(0, 0, camel.class);
if(Greenfoot.isKeyDown("space"))
{
if(camel != null)
{
World world;
world = getWorld();
world.removeObject(camel);
area1 area1 = (area1)world;
counter counter = area1.getCounter();
counter.addScore();
camelseaten++;
if(camelseaten == 10)
done();
}
}
Actor grape;
grape = getOneObjectAtOffset(0, 0, grape.class);
if(grape != null)
{
World world;
world = getWorld();
world.removeObject(grape);
area1 area1 = (area1)world;
counter counter = area1.getCounter();
counter.addScore();
grapeseaten++;
}
}
I also have a score counter for the grapes and the camels. Tell me if you need anything else.
