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

2020/5/17

How do i create a pick able ammo and add it in the ammo counter

MichaelKurniawan MichaelKurniawan

2020/5/17

#
i had a school project. and i want to make some survival game. but i don't know how to spawn ammo in the world and make a pick able ammo . syringe is a throwing weapon. i already trying my best to make ammo counter. can anyone help me about this thanks
public class Chara extends Actor
{
 public int ammo = 3;

 public void act() 
    {
        // Add your action code here.
        movement();
        CharaX = getX();
        CharaY = getY();
        collectAmmo();
    } 

public void Shoot()
    {
        if(Greenfoot.isKeyDown("space"))
        {
            if(ammo>0)
            {
                Syringe syringe = new Syringe();
                getWorld().addObject(syringe, getX(), getY());
                syringe.setRotation(direction);
                ammo--;
            }
        else
        {
            
        }
        }
    }

public void movement()
    {
        //move up
        if(Greenfoot.isKeyDown("W"))
        {
            setLocation(getX(), getY() - 2);
            if(isTouching(Wall.class))
            setLocation(getX(), getY() + 2);
            if(Greenfoot.isKeyDown("shift"))
            {
                setLocation(getX(), getY() - 3);
                if(isTouching(Wall.class))
                setLocation(getX(), getY() + 3);
            }
            if(AnimationCounter % 6 == 0)
            AnimateUp();
            direction = -90;
        }
        //move down
        if(Greenfoot.isKeyDown("S"))
        {
            setLocation(getX(), getY() + 2); 
            if(isTouching(Wall.class))
            setLocation(getX(), getY() - 2);
            if(Greenfoot.isKeyDown("shift"))
            {
                setLocation(getX(), getY() + 3); 
                if(isTouching(Wall.class))
                setLocation(getX(), getY() - 3);
            }
            if(AnimationCounter % 6 == 0)
            direction = 90;
        }
        //move right
        if(Greenfoot.isKeyDown("D"))
        {
            setLocation(getX() + 2, getY()); 
            if(isTouching(Wall.class))
            setLocation(getX() - 2, getY());
            if(Greenfoot.isKeyDown("shift"))
            {
                setLocation(getX() + 3, getY()); 
                if(isTouching(Wall.class))
                setLocation(getX() - 3, getY());
            }
            if(AnimationCounter % 6 == 0)
            AnimateRight();
            direction = 360;
        }
        //move left
        if(Greenfoot.isKeyDown("A"))
        {
            setLocation(getX() - 2, getY()); 
            if(isTouching(Wall.class))
            setLocation(getX() + 2, getY());
            if(Greenfoot.isKeyDown("shift"))
            {
                setLocation(getX() - 3, getY()); 
                if(isTouching(Wall.class))
                setLocation(getX() + 3, getY());
            }
            if(AnimationCounter % 6 == 0)
            AnimateLeft();
            direction = 180;
        }
        //shooting
        if("space".equals(Greenfoot.getKey()))
        {
            Shoot();
        }
    }
}
MichaelKurniawan MichaelKurniawan

2020/5/17

#
please ignore line 11 i forgot to delete it
You need to login to post a reply.