While I am still busy with rewriting everything with the new lib and some RL stuff I will most likely try to explain how I did some stuff with my game, maybe it gets someone some insight, maybe I can get some feedback on how I can do it better.
I will most likely do the lib-specific stuff in pseudo-code and the rest C/C++ style.
So here comes the first one, Tiled maps :
To keep it simple lets say we have the map stored in arrays
int map; // map tiles
int obj; // object tiles
int pass; // shows if the player can walk on the tile
That leaves us with a 50x 50 map.
And lets say we have an array of the images we want to draw:
As we want the player to be centered in the middle of the map all the time (at least in this example) we have to draw everything corresponding to that and we need to know how big the tiles are.
tile_size=32; //size of the tiles in pixel
The next thing we want to do is to ensure, we only draw what´s actually on the screen AND inside the map.
The first part of our draw_map() function would look like this then:
So, if the player_position - half_the_screensize/tile_size < 0 you draw from 0 (so its not outside of the map). if the player_position + half_the_screensize/tile_size > 49 you draw to 49 (so its not outside of the map).
Now we put all the drawing code into a small, but neat for-loop:
// drawing code
Everything that is just inside that for-loops will only get drawn if it IS actually on the map AND on the screen.
Now we add the basic of drawings:
int tile_number=map[t][i]; // that way its easier to call
if(tile number>0) // so if the tile is actually filled
draw(tiles[tile_number],i*tile_size-offset_x,t*tile_size-offset_y); // draws the tile(read out of the maparray) and draws it to its position
With just that little bit of actual code, we draw everything that needs to be on the screen and ONLY what should be on the screen.
If this stuff gets some good feedback I might have to consider another way of formating this, because in the preview it looks horrible >.<
Anyway, have a nice day guys ;)
P.S.:screw spellcheck and mistakes in the code. If something seems a bit too off, it´s either a mistake or I srsly should stop writing code :D