Scenario: There is a man in the middle. There are different coloured balloons moving towards him from all four directions. He has to pop the balloons before they reach him. He can only pop the balloon if the colour of his head corresponds with the colour of the balloon.
Problem: I am having problems with the boolean variables that compare the colour of the man's head and balloon.
Here is the code (this is in the code of the bullet that hits the balloon):
Please help!
public static boolean redBalloon=true;
public static boolean blueBalloon=false;
public static boolean yellowBalloon=false;
public static boolean redHead=true;
public static boolean blueHead=false;
public static boolean yellowHead=false;
public void act()
{
hitAndMiss();
}
public void hitAndMiss()
{
getBalloonColour();
getHeadColour();
pop();
}
public void pop()
{
Actor balloon = getOneIntersectingObject(Balloon.class);
if (balloon != null)
{
if (redHead==true && redBalloon==true||blueHead==true && blueBalloon==true||yellowHead==true && yellowBalloon==true)
{
getWorld().removeObject(balloon);
}
else
{
getWorld().removeObject(this);
}
}
}
public void getBalloonColour()
{
Actor balloon = getOneIntersectingObject(Balloon.class);
if (balloon != null)
{
if (balloon.getImage().equals("balloon1.png"))
{
redBalloon=true;
blueBalloon=false;
yellowBalloon=false;
}
if (balloon.getImage().equals("balloon2.png"))
{
redBalloon=false;
blueBalloon=true;
yellowBalloon=false;
}
if (balloon.getImage().equals("balloon3.png"))
{
redBalloon=false;
blueBalloon=false;
yellowBalloon=true;
}
}
}
public void getHeadColour()
{
Head head = (Head) getWorld().getObjects(Head.class).get(0);
if (head.getImage().equals("button-red.png"))
{
redHead=true;
blueHead=false;
yellowHead=false;
}
if (head.getImage().equals("button-blue.png"))
{
redHead=false;
blueHead=true;
yellowHead=false;
}
if (head.getImage().equals("button-yellow.png"))
{
redHead=false;
blueHead=false;
yellowHead=true;
}
}
}
