This is a very boring title for what is a small, but huge change in the game. I finally added a function that looks up the directory of the .exe (which is the program for those who don’t know). SDL2 makes this super easy. It’s literally just:
std::string tdcDirectory = SDL_GetBasePath();
Then you just specify sub folders and data. eg:
LoadTexture(tdcDirectory+”\\playerCharacter.bmp”, (other params));
as opposed to:
LoadTexture(“C:\\Users\\Timothy\\My Documents\\Programming\\SDL2 projects\\Squares Game\\playerCharacter.bmp”, (other params));
Now of course there’s no error checking in this mock code, but to the non programmers this just looks like saving a bunch of space and typing (or copy-pasting), but there’s a significant problem with the original example. If I hard-code the file, then I would need to make that exact same folder structure to run the game on any other computer. Since that’s ridiculous, it basically means that I can’t run the game on any other computer. When I call the base path of the .exe at runtime, then I can run it on any windows computer. I can also add a little bit of code that checks which operating system I am running, using SDL2, and either use “\\”, for windows, or “/”, for Linux and Mac.
I really can’t wait to take this game with me and show it to people at Brock, and really anyone I know. I’ve loaded it all on my USB key and it’s ready to go.
Somewhat hilariously, after deleting the sound folder, because I’m not using it right now, the game takes up 4.27MB’s. That’s tiny.