I am making a game. I have an abstract class called GameObject, and two child classes called Player, and Block. Each extended class from GameObject has an ID (Enumeration). I also have a vector of GameObjects. For collision, in my player class. I go through every GameObject in my list to check collision for every object. Like so :
for(unsigned i = 0; i < handler->getGameObjects().size(); i++){
GameObject& tempObject = handler->getGameObject(i);
if(tempObject.getId() == ObjectID::BLOCK) { // collision with block
if(this->getBoundsBottom().intersects(tempObject.getBoundsAll()){
// what happens if the player's bottom collides with the block.
std::printf("%s", "Bottom \n");
} else {
std::printf("%s", "Not bottom \n");
}
}
}
this is happening in the Player's inherited method update(), (Every frame).
How ever this gives me this result in the console:
Bottom
Not bottom
Bottom
Not bottom
Bottom
Not bottom
Bottom
Not bottom
.... and so on.
HOWEVER if I do this exact same process outside of the for loop and use "handler->getGameObject(0).getBoundsAll()" instead of "tempObject" (0 is the index of the block I am trying to collide with), everything seems to work good.
What is this problem?
But that's different from your previous result.
It was: yes no yes no yes no ...
Now it's: no yes no no yes no no yes ...
So it's not exactly the same problem.
@Repeater: Would it even compile with that missing closing paren?
@hassanAman: Was that missing closing paren on this line a typo? Is it really in your code? if(this->getBoundsBottom().intersects(tempObject.getBoundsAll()){ <-- needs another ) before {
@Repeater: Would it even compile with that missing closing paren?
We can't see the whole code. We know that what we've been shown will not compile. So we know that whatever the OP is compiling, it's not what we've been shown...
Note to other helpers: The project is well-organized and not very big, so it's not too much of a chore to take a look at it. Each file is quite small.
At the download site, after clicking on the first big square (that says "view" when you hover over it) the next page has a red Download link to get a zip file.
The code in question is in Player.cpp, lines 20 to 28.
@hassanAman, What do you expect that it should print?