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?
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; } }
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 } }