Adding a short delay between bullets

Posted by Sun on Game Development See other posts from Game Development or by Sun
Published on 2012-05-26T18:02:31Z Indexed on 2012/11/02 11:20 UTC
Read the original article Hit count: 220

Filed under:
|

I'm having some trouble simulating bullets in my 2D shooter. I want similar mechanics to Megaman, where the user can hold down the shoot button and a continues stream of bullets are fired but with a slight delay. Currently, when the user fires a bullet in my game a get an almost laser like effect. Below is a screen shot of some bullets being fired while running and jumping.

Bullets being fired

In my update method I have the following:

if(gc.getInput().isKeyDown(Input.KEY_SPACE) ){
    bullets.add(new Bullet(player.getPos().getX() + 30,player.getPos().getY() +  17));  
}

Then I simply iterate through the array list increasing its x value on each update.

Moreover, pressing the shoot button (Space bar) creates multiple bullets instead of just creating one even though I am adding only one new bullet to my array list. What would be the best way to solve this problem?

© Game Development or respective owner

Related posts about java

Related posts about slick