i had the reload working but then i added a ammo limit and now it wont work here is the code for the class that the reload is in:
import greenfoot.*; import greenfoot.MouseInfo; public class Player extends Actor { // all the variables for the players stats public final int speed = 3; public int firerate = 20; int health = 100; int stamina = 10; int cash = 0; int wave = 1; int ammo = 20; public int pause = 100; int kills = 0; int survivedTime = 0; // creates the player character public Player(){ setImage(new GreenfootImage(70, 50)); getImage().setColor(Color.YELLOW); getImage().fillOval(0, 0, 50, 50); getImage().setColor(Color.BLACK); getImage().fillRect(50, 20, 70, 10); } // tells the player character to use all the methods that have been created as long as the conditions are right for the given method public void act() { move(); turnAround(); reload(); shoot(); } // tells the actor to turn to face the mouse public void turnAround(){ button button = new button(); if (Color.BLACK.equals(button.getCurrentColor())){ if(Greenfoot.getMouseInfo() != null){ turnTowards(Greenfoot.getMouseInfo().getX(), Greenfoot.getMouseInfo().getY()); } } } // tells the actor to do if the button is black and if it isnt black public void shoot() { button button = new button(); if (Color.BLACK.equals(button.getCurrentColor())){ manualShoot(); } else { autoShoot(); } } // returns the buttons color to determine what the firemode is public static int getColor() { return button.colorValue; } // one of the firemodes that is player skilled based private void manualShoot() { MouseInfo mouse = Greenfoot.getMouseInfo(); if(pause>0){ pause --; } if(pause == 0){ if(ammo>0){ if (!Greenfoot.mousePressed(null)) return; turnTowards(mouse.getX(),mouse.getY()); Actor bullet = new bullet(); getWorld().addObject(bullet, getX(), getY()); bullet.turnTowards(mouse.getX(), mouse.getY()); GreenfootImage drawedImage = new GreenfootImage("gunshot.png");//the image that is drawed; getImage().drawImage(drawedImage, 70, 50); ammo--; } pause = firerate; } } // the second fire mode that is more of a auto fire to the nearest enemy private void autoShoot() { if(pause>0){ pause --; } if(pause == 0){ if(ammo>0){ if (getWorld().getObjects(Zombie.class).isEmpty()) return; Actor closest = null; int closeness = 9999; for (Object obj : getWorld().getObjects(Zombie.class)) { Actor enemy = (Actor)obj; int dist = (int)Math.hypot(getX()-enemy.getX(), getY()-enemy.getY()); if (dist < closeness) { closeness = dist; closest = enemy; } Actor bullet = new bullet(); getWorld().addObject(bullet, getX(), getY()); bullet.turnTowards(closest.getX(), closest.getY()); } GreenfootImage drawedImage = new GreenfootImage("gunshot.png");//the image that is drawed; getImage().drawImage(drawedImage, 70, 50); ammo--; pause = firerate; } } } // gets the users inputs and moves the player accordingly public void move(){ if(Greenfoot.isKeyDown("W")||Greenfoot.isKeyDown("UP")){ setLocation( getX(), getY()-speed); } if(Greenfoot.isKeyDown("A")||Greenfoot.isKeyDown("LEFT")){ setLocation( getX()-speed, getY()); } if(Greenfoot.isKeyDown("S")||Greenfoot.isKeyDown("DOWN")){ setLocation( getX(), getY()+speed); } if(Greenfoot.isKeyDown("D")||Greenfoot.isKeyDown("RIGHT")){ setLocation( getX()+speed, getY()); } } // tells the character to reload his gun when the user hits r private void reload(){ if((Greenfoot.isKeyDown("R"))){ pause = firerate; if(pause>0){ pause --; } if(pause == 0){ ammo = 20; } } } }