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

2013/5/21

How do I make it to where there is a recharge to a gun?

Gzuzfrk Gzuzfrk

2013/5/21

#
I'm making a shooting type game but I want it to where you cant just hold the space bar and it will fire 5 thousand. How can I make it to where you cant do that?
bourne bourne

2013/5/21

#
Do you mean so that there is some small duration of time between shots? An overheating feature? Or just single shot per press on space bar?
Gzuzfrk Gzuzfrk

2013/5/21

#
A single shot but right now if I hold the space bar a lot fire so I want like a small duration between shots And also how do i get it to where the bullet will dissappear after it gets so far away from an object?
bourne bourne

2013/5/21

#
For a small duration between the shots you could have something like:
private final int DURATION = 20; // Some number for duration before next shot
private int firing;

public void act()
{
    if (firing != 0)
        firing--;
    if (Greenfoot.isKeyDown("space") && firing == 0)
    {
        // Shoot bullet

        firing = DURATION;
    }
}
Then for disappearing after some distance, could have something like:
private final int STEP = 5; // Some distance to move per act cycle
private final int MAX = 300; // Some distance when to disappear
private int distance = 0;

public Bullet(int rotation)
{
    setRotation(rotation);
}
public void act()
{
    move(STEP);
    distance += STEP;
    if (distance >= MAX)
    {
        // Disappear
    }
}
You need to login to post a reply.