Jump to content

  • Log In with Google      Sign In   
  • Create Account


Need feedback on collision code


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 warnexus   Prime Members   -  Reputation: 1398

Like
1Likes
Like

Posted 05 May 2013 - 12:56 PM

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.

 

 

 



Sponsor:

#2 Ludus   Members   -  Reputation: 970

Like
1Likes
Like

Posted 05 May 2013 - 02:07 PM

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.



#3 Rld_   Members   -  Reputation: 1379

Like
0Likes
Like

Posted 05 May 2013 - 02:09 PM

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.



#4 warnexus   Prime Members   -  Reputation: 1398

Like
0Likes
Like

Posted 05 May 2013 - 03:13 PM

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.



#5 warnexus   Prime Members   -  Reputation: 1398

Like
0Likes
Like

Posted 05 May 2013 - 03:29 PM

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! 






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS