private int fireDelay = 0; //Delays multiple firing
private int currentLocationX = 0;
private int currentLocationY = 0;
public int scoreMultiplier = 1;
private int imageOffsetX = 0;
private int imageOffsetY = 0;
public int publicOffsetX;
public int publicOffsetY;
/**
* Act - do whatever the Person wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
movePerson();
eatFood();
fire();
increaseScoreMultiplier();
declareImageOffsets;
}
public declareImageOffsets()
{
imageOffsetX = publicOffsetX;
imageOffsetY = publicOffsetY;
}
public void assignImageOffsetsHard()
{
publicOffsetX = 50;
publicOffsetY = 50;
}
public void assignImageOffsetEasy()
{
publicOffsetX = 300;
publicOffsetY = 300;
}
public void fire()
{
if (Greenfoot.isKeyDown("space"))
{
if (fireDelay == 0)
{//Ignore any space bar presses if the fire delay counter is pressed
fireDelay = 50; //Set the fire delay counter
Urban urban = (Urban)getWorld();
if (urban != null)
{//Add the banana projectile to the world at the position of the Person object
urban.addObject(new Projectile(), getX()+ imageOffsetX, getY()+ imageOffsetY);
}
}
}
if (fireDelay > 0)
{//Decrement the fire counter if it is set
fireDelay = fireDelay - 1;
}
}
public void increaseScoreMultiplier()
{
if (isTouching(ScoreMultiplier.class))
{
removeTouching(ScoreMultiplier.class);
scoreMultiplier = scoreMultiplier + 1;
}
}
public void eatFood()
{
if (isTouching(Plum.class))
{
removeTouching(Plum.class);
Greenfoot.playSound("Eating.wav");
respawn();
}
}
public void respawn()
{ //Cast the SuperClass World to the SubClass Urban
Urban urban = (Urban)getWorld();
if (urban != null)
{
urban.addObject(new Plum(), Greenfoot.getRandomNumber(urban.getWidth()),
Greenfoot.getRandomNumber(urban.getHeight()));
urban.Score(1 * scoreMultiplier);
}
}
public void movePerson()
{
currentLocationX = getX();
currentLocationY = getY();
if (Greenfoot.isKeyDown("left"))
{
move(-5);
}
else if (Greenfoot.isKeyDown("right"))
{
move(5);
}
else if (Greenfoot.isKeyDown("up"))
{
setLocation( currentLocationX , (currentLocationY - 5));
}
else if (Greenfoot.isKeyDown("down"))
{
setLocation( currentLocationX, (currentLocationY + 5));
}
}
}