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

2013/5/18

EXPLODING

Avik Avik

2013/5/18

#
can someone please send me the simple code- where when the balloon hits the point I want it to explode.
Kartoffelbrot Kartoffelbrot

2013/5/18

#
public void explode()
{
if(getX()==aimX && getY()==aimY)
getWorld().removeObject(this);
}
danpost danpost

2013/5/18

#
@Kartoffelbrot, you forgot the 'explode' bit.
public void explode()
{
    if(getX()==aimX && getY()==aimY)
    {
        getWorld().addObject(new Explosion(), getX(), getY());
        getWorld().removeObject(this);
    }
}
Avik Avik

2013/5/18

#
where do I put this?
Avik Avik

2013/5/18

#
I mean which subclass do I put it into?
danpost danpost

2013/5/18

#
You put this in your Balloon class and substitute the coordinates (aimX, aimY) for the point at which the balloon will explode with the actual coordinates (or declare and assign 'aimX' and 'aimY' with the appropriate values.
Avik Avik

2013/5/18

#
what does aim mean?
danpost danpost

2013/5/18

#
It is just a field name that Kartofffelbrot created and used for the coordinate at which you want the balloon to explode.
Avik Avik

2013/5/18

#
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?
danpost danpost

2013/5/18

#
if(getX()==4X && getY()==4Y) The compiler cannot figure out what these are. They are not variable-names; nor are they values or legal expressions. What location is being compared to the location of the balloon?
Avik Avik

2013/5/18

#
sorry im quite new, what does that mean?
You need to login to post a reply.