Hi again,
Over the past few months I've tried re-writing my program, several times in fact. Each time I run into a similar problem with scopes and modules that aren't able to interact. In my latest attempt, I made player into a class. I'm also using a graphics module to keep the ugly parts out of my main file. The problem is accessing the graphics class located in graphics.h/graphics.cpp - When I render my objects I'm in a for loop which seems to only access Tile but not Graphics.
Example:
for (Tile& it : tileList) {
it.square.x = it.x;
it.square.y = it.y;
g.draw(g.wallgfx, g.Backbuffer, it.square); // square is an SDL Rect object for drawing on
};
g.draw(g.wallgfx, g.Backbuffer, &singleObjectName.square);
Of course it's not going to work. When I'm in the for loop I can't call the "g for graphics" object. The stand-alone line at the bottom works fine but I'm not going to make a specific object with its own name, for every detail in the game world! I could move the draw() function into tile.h or thing.h which Tile is derived from, but then (staying strictly with the engine concept) I have to call the backbuffer from graphics.h which is included in main.cpp but not available in tile.h
I know that I cannot #include graphics.h into both main.cpp and tile.h - I tried that a month or two ago!
This is disappointing because I spent a lot of time reading text books and tutorials, plus I asked many questions here. I'm 26 and I still don't understand how to 'modularise' a program in c++. I read Jazon Yamamoto's book but I haven't been able to replicate any of his complex code for my own use - his example code is a properly-written engine but it's too abstract for me to grasp. I could go back to including everything into my main file but that's exactly what I want to avoid. If PY-SDL2 is any good, then I might give that a try.
edit: added tags to post. Also note my use of QUOTE not CODE which allows for traffic light indication of good vs. bad code :)