Hello everyone,
I am trying to create a Pacman for my school project and I am having some trouble with my game. The fact is that I want give my Pacman the ability to eat the other Ghosts in the world when he ate one "bonus food".
Here is the code in my Ghost Class :
/**
* This method is used whenever the Pacman eats a "bonusFood". If he does, the ghosts will be changed into "Ghosts_e" which are edible by the Pacman.
*/
public void changeGhost()
{
int Xi = getX();
int Yi = getY();
if(Pacman.bonusEaten)
{
getWorld().removeObject(this);
getWorld().addObject(new Ghost_e(), Xi, Yi);
}
}
And here is the code in my Pacman class :
public void lookForFood()
{
if ( canSee(Food.class) )
{
eat(Food.class);
Greenfoot.playSound("pacman_chomp.wav");
foodEaten = foodEaten + 1;
}
if ( canSee(BonusFood.class))
{
eat(BonusFood.class);
bonusEaten = true;
Greenfoot.playSound("pacman_eatfruit.wav");
Greenfoot.playSound("pacman_intermission.wav");
Greenfoot.playSound("pacman_intermission.wav");
//Method used to wait 10 sec (duration of 2x intermission.wav)
//bonusEaten=false;
}
if (foodEaten >= 135)
{
Greenfoot.playSound("pacman_beginning.wav");
Greenfoot.stop();
}
if(bonusEaten && canSee(Ghost_e.class))
{
eat(Ghost_e.class);
Greenfoot.playSound("pacman_eatghost.wav");
}
}
}
The problem is that I can't access the boolean "bonusEaten" from my Ghost class. I already tried to follow this tutorial : http://www.greenfoot.org/doc/howto-1. But I wasn't able to fix my problem.
Everytime I try to compile my game I have this error : "non static variable bonusEaten cannot be referenced from a static context".
Thanks ahead for your help!