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

2017/2/22

Shooting Range

joshuadswa joshuadswa

2017/2/22

#
Hello, i need help with range, is theres a method to check if Actor "A" passing through the range of Actor "B",then actor "A" will be removed here my code .-. public void shootingRange() { Actor pp = (Actor) getWorld().getObjects(Projectile2.class).get(0); List<Projectile2> isi = getObjectsInRange(300,Projectile2.class); if(//need help here) { getWorld().removeObject(pp); }
Super_Hippo Super_Hippo

2017/2/22

#
"passing through the range" I am not 100 % sure what you mean, but if you want to remove every projectiles which comes nearer than 300 cells to an object of the class in which this code is, then this should work:
List<Projectile2> isi = getObjectsInRange(300,Projectile2.class);
if (!isi.isEmpty()) getWorld().removeObjects(isi);
joshuadswa joshuadswa

2017/2/22

#
well what i want is, lets say actor A is hero and actor b is bullet xD so when the hero shoot the bullet theres a limit where the bullet can go >< sorry for my english
danpost danpost

2017/2/22

#
If the bullet is to have a range, then that is a state of the bullet and should be addressed in the class of the bullet -- nowhere else. You can give the bullet an 'age' field to count act cycles the bullet is present in the world. When it reaches a certain value, have the bullet remove itself.
Super_Hippo Super_Hippo

2017/2/22

#
If you need the certain distance, you can save the location where the bullet was fired and then calculate the distance to this location when it moves. If the distance is above 300, you remove it.
joshuadswa joshuadswa

2017/2/23

#
OK thx all :D
You need to login to post a reply.