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

2013/11/16

bullet help

1
2
danpost danpost

2013/11/17

#
RUMMAKER wrote...
you also don't need the if(getWorld() != null) thing in this case
Actually, that is not true; unless you put 'shotasteriod' at the end of the method (the check for 'getWorld() != null' must be placed between 'shotasteroid();' and 'if (atWorldEdge(){...}'.
KevinWelch2001 KevinWelch2001

2013/11/17

#
ty a lot it works now
danpost danpost

2013/11/17

#
As an alternative, you could use this:
shotasteroid();
if (getWorld() != null && atWorldEdge())
{
    // code processed when at world edge
}
KevinWelch2001 KevinWelch2001

2013/11/17

#
one more question this is my last how do I change the size of my bullet
danpost danpost

2013/11/17

#
As a third option, the class could be coded as follows:
import greenfoot.*;

public class Bullet extends Actor
{
    public void act() 
    {
        move(5);
        if ( shotasteroid() || atWorldEdge() )
        {
            getWorld().removeObject(this);        
        } 
    }

    public boolean shotasteroid()
    {
        Asteroid asteroid = getOneObjectAtOffset(2, 2, asteroid.class);
        if(asteroid != null)
        {
            Greenfoot.playSound("Explosion.mp3");
            getWorld().removeObject(asteroid);
            return true;
        }
        return false;
    }

    public boolean atWorldEdge()
    {
        if(getX() < 10 || getX() > getWorld().getWidth() - 10)
            return true;
        if(getY() < 10 || getY() > getWorld().getHeight() - 10)
            return true;
        else
            return false;
    }
}
RUMMAKER RUMMAKER

2013/11/17

#
change the image you use for the bullet. or if you mean in game then use the scale method. GreenfootImage i = getImage().scale(width, height); (maybe its height, width ... just check the documents) setImage(i);
danpost danpost

2013/11/17

#
If you want the bullet to start at a different size and stay that size throughout its existence, then you would add a constructor to scale its image:
public Bullet()
{
    GreenfootImage image = getImage();
    image.scale(image.getWidth()*(n/d), image.getHeight()*(n/d));
}
where '(n/d)' is a ratio of integers, as like ('2/3', '1/2', '3/4' or whatever).
KevinWelch2001 KevinWelch2001

2013/11/17

#
ty
You need to login to post a reply.
1
2