Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualwarnexus

Posted 31 March 2013 - 01:30 PM

Hmm, I'm not a fan of that method. You'll probably check for collisions twice for each object pair then when you don't need to.

 

Typically you place objects which can collide into a list and only check collisions against objects which are further along in the list, then call a callback method for both objects to resolve the collision or do damage etc.

 

You may also want to place objects in collision groups (e.g. bullets can't collide with each other, etc.) which can be implemented as separate lists or by having a bitfield which stores which objects are able to collide with each other.

 

Remember to only do expensive collision with objects where one or both are actually moving as well.

the collision detection methods I posted up only happens when the projectiles are in the ArrayList named gameObjects which is when the projectiles are drawn on screen. 

 

Something I forgot to mention the laser is coming from the ship towards the monsters and the ghost skill is coming from the enemy towards the ship. But I see where you are coming from. I going to try to restructure the code better. Thanks for the heads-up.


#3warnexus

Posted 30 March 2013 - 07:12 PM

Hmm, I'm not a fan of that method. You'll probably check for collisions twice for each object pair then when you don't need to.

 

Typically you place objects which can collide into a list and only check collisions against objects which are further along in the list, then call a callback method for both objects to resolve the collision or do damage etc.

 

You may also want to place objects in collision groups (e.g. bullets can't collide with each other, etc.) which can be implemented as separate lists or by having a bitfield which stores which objects are able to collide with each other.

 

Remember to only do expensive collision with objects where one or both are actually moving as well.

the collision detection methods I posted up only happens when the projectiles are in the ArrayList named gameObjects which is when the projectiles are drawn on screen. the for loop is a linear running time algorithm. so it runs fast.


#2warnexus

Posted 30 March 2013 - 07:07 PM

Hmm, I'm not a fan of that method. You'll probably check for collisions twice for each object pair then when you don't need to.

 

Typically you place objects which can collide into a list and only check collisions against objects which are further along in the list, then call a callback method for both objects to resolve the collision or do damage etc.

 

You may also want to place objects in collision groups (e.g. bullets can't collide with each other, etc.) which can be implemented as separate lists or by having a bitfield which stores which objects are able to collide with each other.

 

Remember to only do expensive collision with objects where one or both are actually moving as well.

the collision detection methods I posted up only happens when the projectiles are in the ArrayList named gameObjects. the for loop is a linear running time algorithm. so it runs fast.


#1warnexus

Posted 30 March 2013 - 07:04 PM

Hmm, I'm not a fan of that method. You'll probably check for collisions twice for each object pair then when you don't need to.

 

Typically you place objects which can collide into a list and only check collisions against objects which are further along in the list, then call a callback method for both objects to resolve the collision or do damage etc.

 

You may also want to place objects in collision groups (e.g. bullets can't collide with each other, etc.) which can be implemented as separate lists or by having a bitfield which stores which objects are able to collide with each other.

 

Remember to only do expensive collision with objects where one or both are actually moving as well.

the collision detection methods I posted up only happens when the projectiles are in the ArrayList named gameObjects.


PARTNERS