Jump to content
  • Advertisement
Sign in to follow this  
superman3275

Handling Collision?

This topic is 2180 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've successfully produced a re-usable tool that can load maps from files and display them. (I'm very happy with it because it's reusable, I can use it for future products also! It's only changing the "tile-Type" enumeration in the file and it works!).

 

Now I'm working on player collision. Do you believe I should simply allow my Collision class to have a pointer to my player (My player holds it's own position) so it can check collision (It will also have a pointer to the map) and let Collision handle everything (Passing any collisions that happen to Physics of course).

 

Or do you believe I should have my Player class simply being in charge of moving the player (Which entails handling it's SpriteSheet, etc.) and have it update a playerPosition member variable in Collision?

 

For clarification, Collision, Player, and Physics are all classes.

Share this post


Link to post
Share on other sites
Advertisement
I don't think the collision class should always have a copy of your player class. Won't your collision class handle collisions between any objects that could collide? Are you concerned with your bullets hitting enemies, or enemies hitting other enemies, or enemies hitting objects within the world? I think simply passing 2 generic Physical Information Objects to the collision class would be better.

Actually, do you need Collision to be an object? It sounds like it's an activity, not an object, and it could be just typical functions.

Share this post


Link to post
Share on other sites

I was thinking about this and wanted to throw out another option.  You can also provide a function from a super class that all Physical Objects have and it could be used to check if it collides with some other Physical Object.  Kind of like this:

class TPhysicalObject { public:   TPhysicalObject(Size, Shape, etc.);     virtual bool IsColliding(TPhysicalObject& otherObject);   // Some other functions... };   class TPlayer : public TPhysicalObject {   // Define your Player object here ... };   // In code, you can check if the Player Has collided with other objects for (int i = 0; i < EnemyBulletList.size(); i++) {   if (MainPlayer.IsColliding(EnemyBulletList) {     // Do whatever if player collides with enemy bullet   } }   // Do the same thing with enemy objects and our bullets, etc

 

I'm not saying one way is better than the other, but it's another option, but it's certainly better than having a Collision Object itself.

 

Good luck.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!