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

2018/2/8

Ak47 can't be put in help.

Bandito Bandito

2018/2/8

#
I have a button that when I press it and go to my main world it should add it to the world but it doesn't work for some reason and I can't figure it out please help. Here is my Ak47 class
public class Ak47 extends Guns
{
    Human hooman;
    private static GreenfootImage rightImage= new GreenfootImage("Ak47Right.png");
    private static GreenfootImage leftImage= new GreenfootImage("Ak47Left.png");    
    public Ak47()
    {
        Human.fireRate = 17;
        Human.clipSize = 10;
        Human.clip = 10;
        Human.reloadTime = 200;
        if (hooman.direction == "a" && hooman.life > 0)
        {
            setLocation (hooman.getX() -10, hooman.getY() -4); 
        }
        else if (hooman.direction == "d" && hooman.life > 0)
        {
            setLocation(hooman.getX() +10, hooman.getY() -4); 
        }
    }

    public void act() 
    {
        turn();
        move();
    }    

    public void turn()
    {
        if (hooman.direction == "a")
        {
            setImage(leftImage);
        }
        else if(hooman.direction == "d")
        {
            setImage(rightImage);
        }
    }

    public void move()
    {
        Human hooman = (Human) getWorld().getObjects(Human.class).get(0);            
        if (hooman.direction == "a" && hooman.life > 0)
        {
            setLocation(hooman.getX() -10, hooman.getY() -4); 
        }
        else if (hooman.direction == "d" && hooman.life > 0)
        {
            setLocation(hooman.getX() +10, hooman.getY() -4); 
        }
    }
}
and here is the problematic part of my Human class
public void checkForGun()
    // This is where the guns are spawned in
    {
        if(boughtAk == true && spawnedAk == false)
        {
            getWorld().addObject (new Ak47(), getX(), getY());
            spawnedAk = true;
        }

        if(boughtDeagle == true && spawnedDeagle == false)
        {
            getWorld().addObject(new DesertEagle(), getX(), getY());
            spawnedDeagle = true;
        }

        if(boughtDeagle == true && boughtAk == true)
        {
            getWorld().removeObject(deserteagle);
        }
    }
Vercility Vercility

2018/2/8

#
What exactly doesnt work.. Is there an error? Nothing happens?
danpost danpost

2018/2/8

#
Please show all the field declaration lines in the Human class.
Bandito Bandito

2018/2/8

#
nvm the computer just didn't decide to work
You need to login to post a reply.