SDL 2.0 and SDL_Rect structure

Hello,
I'm in the middle of trying to make a simple game. I wanted to make a structure, which would contain every SDL_Rect object that needs to be displayed somewhere.
The problem is, I'm not sure if I can even do such thing.

What I have below is declared as a global variable:
1
2
3
4
5
SDL_Rect mapRect;
SDL_Rect windowRect = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
SDL_Rect frogRect;
SDL_Rect car1Rect;
SDL_Rect car2Rect;


I don't want to use this as globals, because it messes things up - that's why I wanted to make a structure, which I could pass through functions from main().

For example:
1
2
3
4
5
6
7
struct my_Rect{
SDL_Rect mapRect;
SDL_Rect windowRect = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT}; //this should be initialised somewhere else, I know - but let's leave it as another problem
SDL_Rect frogRect;
SDL_Rect car1Rect;
SDL_Rect car2Rect;
};


and then in main()...
1
2
3
4
5
int main(int argc, char* args[])
{
struct my_Rect Rectangles;
...
}


My question is - is it a good way to do this while using struct? I cannot use vectors/classes. Just simple struct.

And - how should I get to the values of certain SDL_Rect?

Thanks for any any help!!! :)
Why not just pass an array?

Separately, are you writing C code?
Last edited on
I don't know why I thought about structures - arrays seems easier, thanks. I'll try to implement it.
I'm writing in C and C++, but mostly just using SDL functions
Topic archived. No new replies allowed.