   Checking all collisions
  I was wondering how I would be able to cycle through all SDL rectangles to check if the player collides with them. Anyone got an idea of how to do this?   
  Store all rectangles in a container for example a vector. Iterate through the container and perform some form of function that checks and returns a boolean. Maybe a bit crude but I think you'll get the idea.for(std::vector<SDL_Rect>::Iterator i = 0; i < rects.Size(); i++){    if(CollisionFunction(rects.at(i), player))    {   DoSomething()...    }};  Thanks for help but I have no idea how to use vectors. Can you give me a tut?   ;Quote:Original post by YelnatsThanks for help but I have no idea how to use vectors. Can you give me a tut?A quick google got me this link, it's fairly old however I did give it a brief look over and it is still relevant.The handy thing about the standard library containers is the interface with them is fairly similar, it makes using the right container for the right job easy. If you haven't yet you might want to look up data structures which will cover the differences.   ;  Just a quick overview explanation here... I suggest you use a resource like ExcessNeo linked or http://www.cplusplus.com/reference/stl/vector/ (sorry, I can't recall the tag to make that a link) to really learn and understand what is being used.What you see in that block of code is actually a couple really cool things.  First you have Vector, specifically the Standard Template Library (STL) version of a Vector.  What the STL does is provide a whole bunch of really useful containers.  A Vector is in the simplest sense just a list.  The really great thing about templates are that they are type-neutral.  That is to say that the STL vector on its own does not specify whether you put an int, char, or some form of object within it.  vector<SDL_Rect> creates a vector containing objects of the SDL_Rect (SDL Rectangle object) type... AKA a list of SDL_Rect objects.  The next thing (which is probably my favorite) is the ::iterator part.  What that means is what is being created is actually an iterator for a list of SDL_Rectangle objects, that is to say a special object (with overloaded increment operators and whatnot) that lets you safely and easily access elements within the list of STL_Rects.  It is sort of like for(int i = 0; i < maximumnumberofawesome; i++) except that i.size() there means you don't need to manually count or otherwise keep track of the size of the vector (list).In order to use that code, keep in mind, you still need to have an actual vector<SDL_Rect> object with a bunch of SDL_Rects inserted into it, but that is easy enough to figure out from reference material.   ;  I am only getting as far as this: std::vector<Wallz> v(6);. There are going to be 6 walls, but I don't get what to do after wards. I am using my own custom class now called Wallz.   ;  I realize that making games is something of a learning experience and can lead to great personal discoveries, but I suggest getting to know the language better before you try your hand at a visual game (2d or 3d).Learn the Standard Template Library and use that to make some simple text based games just to get the hang of it.But to help with the vector, to iterate through all your Wallz use a for loop with an iterator.for(Vector<Wallz>::iterator it = v.begin(); it != v.end(); it++){   //an iterator can be dereferenced to get the instance of the class   //stored in the current iterator, so if wall has a Width and Height   // they can be accessed as followed   (*it).Width;   (*it).Height;  //(*it) dereferences to the class instance.   /*code for collision against this wall here*/};Quote:Original post by YelnatsThanks for help but I have no idea how to use vectors. Can you give me a tut?# "Accelerated C++" Andrew Koenig and Barabara Moo# "The C++ Standard Library" Nicolai Josuttis# "Effective C++" Scott Meyers# "More Effective C++" Scott Meyers# "Effective STL" Scott Meyers# "Exceptional C++" Herb Sutter# "More Exceptional C++" Herb SutterRead them mostly in the order listed.The first book, Accelerated C++, will cover your tutorial of vectors.  The second book will give you a comprehensive in-depth analysis of them and the rest of the standard library; it can serve as a reference for another five or ten years since it still mostly applies with the C++1x standard. The remaining books will help you use them correctly and avoid many stupid mistakes.Along the way, you will also learn a significant portion of the C++ language.You cannot write computer games until you have learned to program.  You can attempt a learn-as-you-go approach, but it is not an efficient route.  Spend a few months actually learning the language and it can replace a year or more of stumbling around.   ;  To be honest, i managed to pick up c++ with C++ for beginners (hope it doesn't show to often).However, create a few console applications before jumping into games.YOU MUST UNDERSTAND COMPUTER LOGIC, this is the key, if this is your first language take it slow, i suggest sticking to console programs for at least 40hrs of programming time till you get the hand of syntax and basic libraries.vectors are set up like this:std::vector<int> wall;orstd::vector<TypeofVariable> VariableName;accessed like:VariableName[elementnumber] = i ;//(i is a variable of type TypeofVariable)can also access member of VariableName by:VariableName.whatevere.g.VariableName.pushback(i); //expands vector by 1 and adds varibale i to the new "row" created.Hope that gets you going.JamesCobras   ;  Thank you all for your replies. I will look into those books, and will (hopefully) get better with C++. Thanks again.   