I just started learning game development using Java.
I have created
- ArrayList of class Zombie
- ArrayList of class Bullet
Each of the object in the two ArrayList has a variable called rect of type Rectangle which surrounds their own graphics on screen.
My aim is to make an effect when any bullet meets any zombie.
My problem is I don't know how to do "any bullet meets any zombie."
My method: I used the rect variable to test whether both of the object have collided with each other by using the method rect.intersect(r). I'm testing every single bullet in the Bullet ArrayList to see if it has collided with any zombie in the Zombie ArrayList, which means I run through the two ArrayList completely per frame just to carry this feature out. There must be better ways..??