# Platformer in SDL - Collisions

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

## Recommended Posts

Alright I only recently started learning SDL and I'm trying to make a platform game since I thought it would be a good start (after Pong that is...).
Anyway I've done gravity and the player movement so far and working on collisions so that the player has something to work with.

Currently I only have 1 block that the player can interact with and I have no idea how to make the player be able to interact with every block.

Player Collision Code:
 //Check collisions if (check_collision(box, tblock1.box, 4)) //tblock1 is a single block object that the player can walk on { if (Left == true) { box.x-=pSpeed; } if (Right == true) { box.x+=pSpeed; } } 
I have created the class for the blocks the player can walk on but I don't know how to refer to every object of that class so that I can check every collision. All I have done in the code above is made it so it checks for the object tblock1 which is from the Block class.

Basically how do I make the players collision function check for every object created by the Block class? Thanks.

##### Share on other sites
This actually doesn't have anything to do with SDL specifically; it's more of a general programming (or maybe math/physics) problem.

As such, you might PM a mod and see if you can get the thread moved to a more appropriate forum (you might be able to get more help that way).

##### Share on other sites
You want to use a container to store an arbitrary number of blocks. A simple example for the moment might be std::vector<>, or you might want to look into a data structure that can take advantage of the spatial nature of the data. An arbitrary sized 2 dimensional array would be an example if your platforms are "tile" based.

##### Share on other sites

You want to use a container to store an arbitrary number of blocks. A simple example for the moment might be std::vector<>, or you might want to look into a data structure that can take advantage of the spatial nature of the data. An arbitrary sized 2 dimensional array would be an example if your platforms are "tile" based.
[/quote]
Thanks, looking into it now.

This actually doesn't have anything to do with SDL specifically; it's more of a general programming (or maybe math/physics) problem.

As such, you might PM a mod and see if you can get the thread moved to a more appropriate forum (you might be able to get more help that way).
[/quote]
Since I pretty much have a solution now I won't think this is necessary. In the future I'll take my future questions to the right board, just I was a little confused on which board I should of posted in so I went ahead with the SDL board rather than general programming (Since I'm using SDL).

1. 1
Rutin
19
2. 2
3. 3
4. 4
5. 5
frob
12

• 15
• 13
• 9
• 12
• 10
• ### Forum Statistics

• Total Topics
631442
• Total Posts
3000105
×