I'm making a game and I have different files that do different tasks. For example,
graphics initializes the graphics and also does some tasks that have to do with graphics, like applying an image or drawing a square.
In the main function, I have a
vector that holds the objects are to be drawn. Then I call the function and draw them.
void drawFruits( const std::vector <Fruit>& fruits )
{
if( fruits.size() > 0 )
{
for( std::vector <Fruit>::const_iterator iter = fruits.begin(); iter < fruits.end(); ++iter )
applySurface( iter->x, iter->y, iter->ReturnImage(), screen );
}
}
The above code is in
main.cpp, where
int main is.
If I had the same function in
graphics.cpp, it would need one more parameter, which is the surface that I want to draw on, since I pass to a different file. It would look like this:
void drawFruits( const std::vector <Fruit>& fruits, const SDL_Surface* const screen )
{
/*blah blah blah*/
}
The question is, which is better to be used?