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

2017/8/20

Help with shooting

Tomster175 Tomster175

2017/8/20

#
hey everyone I need some help with my shooting speed I have got some code from a friend and have no idea how to slow the shooting speed =/
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

public class Arrow extends Actor
{
    public void act()
    {
        setLocation(getX() + speed, getY());
        checkBoundaries();
        destroyEnemies();
    }
    
    public void checkBoundaries()
    {
        if(getX() > getWorld().getWidth() - 1) 
            getWorld().removeObject(this);
        else if(getX() < 1) 
            getWorld().removeObject(this);
        if(getY() > getWorld().getHeight() - 1) 
            getWorld().removeObject(this);
        else if(getY() < 1) 
            getWorld().removeObject(this);
    }
    
    public void destroyEnemies()
    {
        Actor Zombie = getOneIntersectingObject(Zombie.class);
        if(Zombie != null) {
            getWorld().removeObject(Zombie);
            getWorld().removeObject(this);
        }
    }
    private int speed = 10;
}
Super_Hippo Super_Hippo

2017/8/20

#
To decrease the flying/moving speed, you could set the 10 in line 32 to a lower value. And you could move this line to the beginning, so you can find it easier the next time. ;) If you want less arrows appear in the same time, you need to change the code from where the arrow is added to the world.
You need to login to post a reply.