Need feedback on collision code

Started by
3 comments, last by Nicholas Kong 10 years, 11 months ago

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.

Advertisement

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.

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.

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.

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!

This topic is closed to new replies.

Advertisement