This site requires JavaScript, please enable it in your browser!
Greenfoot back
IronRod
IronRod wrote ...

2016/5/2

Balloon-Popping Game

1
2
3
IronRod IronRod

2016/5/3

#
Ok, this is the Man class:
    public void act() 
    {
}
There's nothing much in there. Any suggestions.
IronRod IronRod

2016/5/3

#
Also may I say again that my problem is that only red balloons ("balloon1.png") pop regardless of the colour of the mans head. What I want to happen: balloons only pop if the colour of the balloon corresponds corresponds to the colour of the mans head (user-controlled).
IronRod IronRod

2016/5/3

#
Everything is working fine apart from that.
danpost danpost

2016/5/3

#
IronRod wrote...
Also may I say again that my problem is that only red balloons ("balloon1.png") pop regardless of the colour of the mans head. What I want to happen: balloons only pop if the colour of the balloon corresponds corresponds to the colour of the mans head (user-controlled).
From what I can tell, the problem is that you are creating the bullets in the World subclass. If you created them from the Head class (which is where the color index they need to retain is located, it would be easier. Right now, you are not calling the 'setColourInt' method of the Bullet class to set the index to the proper value (all bullets will carry an index value of zero -- for red). Also, you do not need to create the initial bullet in the constructor of the world. As well, you do not need the 'isInWorld' boolean field or method in the bullet class. You can just use 'if (getWorld().getObjects(Bullet.class).isEmpty())' to determine when to spawn a bullet.
IronRod IronRod

2016/5/3

#
Can you please post the necessary code to create the bullet from the head class and call the 'setColourInt' method of the Bullet class. This would be much appreciated. Thank you in advance.
danpost danpost

2016/5/3

#
You would basically just move said code from Background to Head. Then, after creating a bullet, call the setColourInt method:
Bullet bullet = new Bullet();
bullet.setColourInt(colorIndex);
addObject(bullet, getX(), getY());
IronRod IronRod

2016/5/3

#
But doesn't the addObject() method belong to the world superclass?
IronRod IronRod

2016/5/3

#
Oh don't worry, I changed it to getWorld().addObject().
IronRod IronRod

2016/5/3

#
I'm quite confused as to where in the head class to put this code. Please could you explain @danpost.
danpost danpost

2016/5/3

#
IronRod wrote...
I'm quite confused as to where in the head class to put this code. Please could you explain @danpost.
You only need to move line 13 from the Background class to the act method of the Head class and lines 37 through 42 of the Background class to the Head class.
IronRod IronRod

2016/5/3

#
Thank you so much @danpost, I really do appreciate all the advice you have given. My game works fine now. ;)
You need to login to post a reply.
1
2
3