Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Handling Collision?


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 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 23 December 2012 - 08:17 PM

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.


I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


Sponsor:

#2 BeerNutts   Crossbones+   -  Reputation: 2998

Like
2Likes
Like

Posted 23 December 2012 - 08:37 PM

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.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#3 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 23 December 2012 - 08:41 PM

That's smart. What I'll do is have a set of Collision and Physics functions that I'll use!

Thanks, I didn't even think of that.


I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#4 BeerNutts   Crossbones+   -  Reputation: 2998

Like
0Likes
Like

Posted 24 December 2012 - 10:55 AM

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[i]) {
    // 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.


My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#5 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 24 December 2012 - 11:36 AM

Thanks, I believe I'll stick with having global functions however. Maybe I'll try using inheritance in my next game.


I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!





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