Sign in to follow this  
Nicholas Kong

Need feedback on collision code

Recommended Posts

Nicholas Kong    1535

I have wrote collision detection for my arcade shooter game.

 

In the game, there is one ship and a row of the same type of monsters. Ship shoots laser and monsters shoot its lightning skill.

 

Here is how my collision detection work:

 

Laser and Monster lightning skill do not collide.

Ship's Laser and Monster lightning skill are the only objects that checks collision.

 

Ship's Laser checks any object that is of a Monster Type Class.

Monster lightning skill checks any object that is of a Ship Type Class.

 

The only issue I have is if I want to add a different monster skill then it will need to required the same duplicated collision code from the lightning skill I already have in order to check collision on the ship. The duplication can be far worse if I extend the number of the monster skills in the game to be more than two.

 

 

 

Share this post


Link to post
Share on other sites
Ludus    1020

The only issue I have is if I want to add a different monster skill then it will need to required the same duplicated collision code from the lightning skill I already have in order to check collision on the ship. The duplication can be far worse if I extend the number of the monster skills in the game to be more than two.

 

Create a base "monster skill" class or "monster projectile" class that will contain the collision code. The "lightning skill" and other "skills" will be derived from this base class, thus reusing the same collision code.

Share this post


Link to post
Share on other sites
reloadead    1795

It depends a bit on how your attacks behave.

 

If your monsters' lightning skills are handled in the same way your other attack is handled, you can simply create a function and call that. (for example, I imagine a lightning attack to be a line. If your next skill is going to be some sort of laser, you can still use a line for that, the behavior doesn't change, only the visuals)

 

If the attacks are missile based, you will probably need to check a box-box like collision, but you can also create a function for that and re-use the function.

 

I don't know what language you're using, but you can make a generic attack type that has the collision checks and derive your specific attacks from that.

Share this post


Link to post
Share on other sites
Nicholas Kong    1535

It depends a bit on how your attacks behave.

 

If your monsters' lightning skills are handled in the same way your other attack is handled, you can simply create a function and call that. (for example, I imagine a lightning attack to be a line. If your next skill is going to be some sort of laser, you can still use a line for that, the behavior doesn't change, only the visuals)

 

If the attacks are missile based, you will probably need to check a box-box like collision, but you can also create a function for that and re-use the function.

 

I don't know what language you're using, but you can make a generic attack type that has the collision checks and derive your specific attacks from that.

I am using Java.

Share this post


Link to post
Share on other sites
Nicholas Kong    1535

The only issue I have is if I want to add a different monster skill then it will need to required the same duplicated collision code from the lightning skill I already have in order to check collision on the ship. The duplication can be far worse if I extend the number of the monster skills in the game to be more than two.

 

Create a base "monster skill" class or "monster projectile" class that will contain the collision code. The "lightning skill" and other "skills" will be derived from this base class, thus reusing the same collision code.

Good point! 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this