I have started programming my game for a school project. I am getting an error in the game world when trying to pass the rCounter into helicopter.
My helicopter code:
And here's the code for game, it's giving me the error.
Thanks
public class Helicopter extends Actor
{
rCounter rCounter;
dCounter dCounter;
/**
* These are the counters that count how many people have been rescued and how many people have died.
*/
public Helicopter(rCounter rcounter,dCounter dcounter)
{
rCounter = rcounter;
dCounter = dcounter;
}
/**
* Movement for the helicopter.
*/
public void act()
{
if(Greenfoot.isKeyDown("up"))
{
setRotation(90);
move(-6);
setRotation(0);
}
if(Greenfoot.isKeyDown("down"))
{
setRotation(90);
move(6);
setRotation(0);
}
if(Greenfoot.isKeyDown("left"))
{
move(-6);
}
if(Greenfoot.isKeyDown("right"))
{
move(6);
}
}
/**
* The resuce person code.
*/
public void rescuePerson()
{
if(isTouching(Person.class) == true)
{
rCounter add;
//Greenfoot.playSound("");
}
}
/**
* This adds a point to the rescue counter
*/
public void addR()
{
rCounter.addR(1);
}
/**
* Tests to see if the helicopter is touching a person.
*/
public boolean isTouchingPerson()
{
return getIntersectingObjects(Person.class) != (null);
}
/**
* What happens after we win the game.
*/
public void gameWin()
{
// Greenfoot.playSound("");
Greenfoot.setWorld(new Win());
}
/**
* What happens after we lose the game.
*/
public void gameLose()
{
//Greenfoot.playSound("");
Greenfoot.setWorld(new Lose());
}
}public class Game extends World
{
private rCounter;
private dCounter;
/**
* Constructor for objects of class Game.
*
*/
public Game()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
//prepare the world
//add items needed by helicopter to the world
Helicopter myHelicopter = new Helicopter(rCounter,dCounter);
}
}
