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

2015/1/11

Firing Bullets

DesaGrammer DesaGrammer

2015/1/11

#
Hey all I want to fire more than one bullet at a time. can anyone help me? Many Thanks
xFabi xFabi

2015/1/11

#
Not Really a lot of information. Just use addObject twice, where is The problem :0? If you want To shoot in in another direction turn(180); before the 2nd Bullet or getX() +/- 20 To Change the Location Also please Post your Code..
DesaGrammer DesaGrammer

2015/1/11

#
This is my code
1
2
3
4
5
6
7
8
9
public void fireOnCommand()
{
    if(Greenfoot.isKeyDown("f")) {
        World myWorld = getWorld();
        myWorld.addObject(laser, 0, 0);
        laser.setLocation(getX(),getY());
        laser.setRotation(getRotation());
    }
}
danpost danpost

2015/1/11

#
Side by side shooting:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// create multiple bullets
Bullet bullet = new Bullet();
Bullet bullet2 = new Bullet();
// add bullets into world at location of spawner
getWorld().addObject(bullet, getX(), getY());
getWorld().addObject(bullet2, getX(), getY());
// turn bullets toward left and right of spawner
bullet.setRotation(this.getRotation()-90);
bullet2.setRotation(this.getRotation()+90);
// move bullets apart
bullet.move(10);
bullet2.move(10):
// turn bullets toward front of spawner
bullet.turn(90);
bullet2.turn(-90);
// move bullets to front of spawner
bullet.move(20);
bullet2.move(20);
This can be done using a 'for' loop to accommodate any number of bullets; but, for only two bullets it did not seem necessary.
DesaGrammer DesaGrammer

2015/1/11

#
Thank that helped alot
You need to login to post a reply.