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

2012/8/13

firing direction

davemib123 davemib123

2012/8/13

#
Hi, I have my boss firing bullets using:
public void fireHunterMissile(){
    if (missileLimiter > 30){
            missileLimiter = 0;         
            BossMissile fireMissile1 = new BossMissile();
            getWorld().addObject(fireMissile1, getX() + xPosition, getY()+ yPosition);
        }
    }
and
public class BossMissile extends Missiles
{
    public BossMissile(){
        this.velocity = 8;
    }

    /**
     * Act - do whatever the EnemyMissile wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        moveLeft();
        checkHeroCollision();
    }    
}
Question is if I include 3 bullets how do I get each of them to fire at a slightly different angle:
public void fireHunterMissile(){
    if (missileLimiter > 30){
            missileLimiter = 0;         
            BossMissile fireMissile1 = new BossMissile();
            BossMissile fireMissile2 = new BossMissile();
            BossMissile fireMissile3 = new BossMissile();
            getWorld().addObject(fireMissile1, getX() + xPosition, getY()+ yPosition);
            getWorld().addObject(fireMissile2, getX() + xPosition, getY()+ yPosition);
            getWorld().addObject(fireMissile3, getX() + xPosition, getY()+ yPosition);
        }
    }
SPower SPower

2012/8/13

#
Change act to:
public void act()
{  
    move(/*the number of cells*/);  
    checkHeroCollision();
}
You need to login to post a reply.