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

2013/5/19

This code

Avik Avik

2013/5/19

#
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * A simple balloon that can move up and down. * * @author Avik */ public class balloon extends Actor { public void act() { if (Greenfoot.isKeyDown("up") ) { setLocation (getX(), getY() - 2); } if (Greenfoot.isKeyDown("down") ) { setLocation (getX(), getY() + 2); Actor coin; coin = getOneObjectAtOffset(0,0, coin.class) ; if (coin != null) { World world; world = getWorld(); world.removeObject(coin); } } } public void explode() { if(getX()==4X && getY()==4Y) { getWorld().addObject(new Explosion(), getX(), getY()); getWorld().removeObject(this); } } } WHATS WRONG WITH THIS? What is the aim? What do I change the aim to?
danpost danpost

2013/5/19

#
(1) something is missing before the 'Actor coin;' line (probably a closing curly bracket to close out the previous 'if' statement) (2) you still have '4X' and '4Y' in your code, which are illegal in Java coding. Where, or at what situation is the balloon supposed to explode?
Avik Avik

2013/5/19

#
when it hits a skyscraper
danpost danpost

2013/5/19

#
Then the 'explode' method should be something like this:
public void explode()
{
    if(getOneIntersectingObject(SkyScraper.class) != null)
    {
        getWorld().addObject(new Explosion(), getX(), getY());
        getWorld().removeObject(this);
    }
}
Avik Avik

2013/5/19

#
thankyou, is there anything I have to put I the explosion cass?
Avik Avik

2013/5/19

#
Do I have to Put anything in the Explosion Subclass?
Avik Avik

2013/5/19

#
please help me as I am really really really really really stuck!!!!!!!!!!!
danpost danpost

2013/5/19

#
I though you had gotten one from another scenario (including 'gif' images).
You need to login to post a reply.