Collision between two ArrayList elements

Hi everyone!

I’m currently at University in Multimedia and I’m learning Processing (which is pretty cool).

For my lastest project, I need to do a game where there is some collisions. The problem is that I know how to do some hits test object (collisions) between some elements in my own class, but the collisions need to be between two different objects.

Actually, I have an ArrayList where there are Enemies (they spawn according to some rules I made) and I have an other ArrayList where there are Bullets (need to kill the enemy). So I don’t really know how to detect a collision between two different ArrayList elements.

By the way, my game is in 3D. I don’t think it will make a difference because i just need to put an other value to the dist(), but I wanted to say it anyway hehe!.

Thanks in advance!

Studio.ProcessingTogether.com/sp/pad/export/ro.9qPrLGrYGkr2o
Studio.ProcessingTogether.com/sp/pad/export/ro.9K-kjhuONcJDZ

Thanks a lot!

But is there a way to do with instance or extends class?

You can make a base class w/ methods & fields that should be shared for all subclasses. :bulb:

Do you want a collision direction – like a 3D bouncing ball? Or is this just hitbix detection?

Well, I simply need a collision detection.

Like… There are some enemies flying (move in many directions) and when the user MousePressed(), there is a bullet that move in the Z axes (the user need to aim and kill the enemy).

It would be simplier if Java could support a superclass that can inherit many classes

Use an interface for that.

1 Like

thanks a lot guys! I read the documentation and I didn’t know there was such thing as an Interface with implements. Great community :smiley:

Docs.Oracle.com/javase/tutorial/java/concepts/index.html

1 Like

See also a recent related discussion for examples of interface, and other approaches: