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

2018/7/11

Spawning bullets

B_rob1 B_rob1

2018/7/11

#
I am in need of a more efficient code to make my bullets spawn a certain distance from my tower but still in the correct direction
public void addBullet()
    {
        List<unit> ammotoward = getObjectsInRange(maxRange, unit.class);
        if(ammotoward.size() != 0 && reload >= 0)
        {
            LazerAmmo bullet = new LazerAmmo();
            getWorld().addObject(bullet, getX(),getY());
            bullet.setRotation(getRotation());
            
            
            reload -=reloadtimer;
        }
        if (reload < 0)
        {
            reload +=1;
        }
    }
danpost danpost

2018/7/11

#
B_rob1 wrote...
I am in need of a more efficient code to make my bullets spawn a certain distance from my tower but still in the correct direction << Code Omitted >>
Make line 9:
bullet.move(10);
Adjust the distance as needed.
B_rob1 B_rob1

2018/7/11

#
Thanks,
You need to login to post a reply.