Thanks for your help, though I have a few questions.
If you're talking Map/Object collision, then the Map could have some kind of external interface that takes a bounding circle/rect (for the Object moving), and a movement vector. Something like:
1 2 3 4 5 6 7 8 9
|
class Map
{
//...
// returns true if moved completely, or false if hit a wall
// Move is input/output... input is the vector along which the object wants to move
// Output is the furthest it can move before hitting a wall (ie, how much it will ACTUALLY
// move)
bool tryMove( const sf::FloatRect& bounds, sf::Vector2f& move );
};
|
|
A bit of a random question, but why does the function take references to the bounds and the movement vector (assuming that part isn't just pseudo-code, I just see things like that a lot)? I don't see how you would be manipulating the bounds of the rectangle (if that's even possible), so you shouldn't need access to that. The movement vector I suppose you would just be modifying it to output a safe movement for the player. I might be missing a basic use of references though, as it's been awhile since I learned about them.
Object/Map collision needs to know details of the Map, so it makes sense for it to be part of the Map class. |
That's great to know, but I still don't get how you decide whether the function would go in the map class or the object class. Sure, it needs to know the details of the map, but it still needs details about the object. How does one decide things like this in general? Take another feature of the game, gravity for example. From what I've learned about OOP, you try to encapsulate things that this theoretical class would have. In real life, the actual world is what has gravity, not the objects on it, but the objects are the thing being affected by the gravity. Just like this map/object collision function, how do you know which class the gravity function would be best suited for? Would it be appropriate to pass the gravity function the object which you want it to apply the gravity to, and have it in the map class? Or should it just be in the object class because it pertains to objects?
You could apply some polymorphism here. IE, Player/Enemy/Item classes could all be derived from Object, and could override their own 'handleCollision' function which behaves different for each class. |
I take it you mean that the base class would have multiple overloaded versions of "handleCollision" for each class to override so all of them know how to react to each type of collision? Or is there a better way?
Is the vertex array just the edge of the walls? Or does it form all the polygons to render the floor? |
It stores the coordinates of the 4 corners of each block.
In that other thread you said that Map shouldn't know anything about Object; does that mean Map shouldn't use an object of the Object class in any way? You also said there should be a Game class that ties everything together, but why would you need to make another class to do that rather than using main? I've always heard people say things like this, but I don't understand the benefit of using a class over main. Sorry if I have a lot of questions, but these are things I've always wondered about and never found an explanation for. This is actually the first time I've ever posted on a forum for programming help, so the questions just kind of built up.