but I feel as though calling everything from main() is the best way to stop the code from becoming jumbled. |
That's not really a healthy way to look at things.
In this case it's fine because main is relatively simple, but I wouldn't recommend keeping that mindset.
It not only is acceptable to call functions from within other functions, but it is also extremely necessary as projects grow larger.
Ultimately, the goal is to keep functions simple. Have them do one job and one job only. If the job is complex, you break it into smaller parts by making more functions to do each individual part. You might have a function that does a large job by doing nothing other than calling a series of smaller functions to do each of its smaller parts -- and those functions in turn might break it down into even smaller parts.
So yeah, don't be afraid of calling functions, or of having too many functions. It's much more common for newbies to have too few functions than too many.
The output of the map is quite flickery when moving the player around. I understand that this is due to the fact that the map is re-drawn every time the player moves, but I was wondering if it was possible to reduce the flickering or remove it altogether |
This is mostly due to the fact that the console flushes on newlines.
Whenever it "flushes", it means that whatever you output becomes visible. In effect, this means that someone looking at the screen can see it being drawn, as it is drawn line at a time.
To solve this, you will have to prevent it from flushing, do all your drawing, then flush to make the final changes visible. That way, instead of it being drawn line at a time, the entire screen is drawn at once. This will eliminate flicker as it will appear to update instantly.
The problem is, the console is not really designed to do this easily, and the C standard library does not offer any functions to do this. So to accomplish this, you'll either have to use platform specific APIs (like WinAPI console functions if you're on windows), or you'll have to use a 3rd party lib like NCurses.
OR, instead... you can just ditch the console and use a graphical lib like SDL -- which would probably be easier anyway. It's
way easier to make simple games with something like SDL than it is to try to do it with the console. Also, SDL is C, so you don't need C++ for it.
Also, I hear that system("cls") is something that should be avoided, so please do not recommend it. |
It's a security hole for sure, and it wouldn't completely solve the flickering problem anyway. So yeah I wouldn't recommend it.
Other than that, any tips, suggestions, constructive criticism or general feedback is very welcome. Thank you. |
I'm sure this has been mentioned before, but you should not keep track of player position by examining the contents of the map. The map should essentially just keep track of walls and static objects, and any moving objects like a player or enemies or whatever should be tracked separately (with just X,Y coordinates). That way to move him you already know where he is and where he's going without having to scan the entire map.
This will complicate [console] drawing, though, because you'll have to inject the player into the map before drawing... but with a graphic lib it's a non-issue because you can draw the map and the player separately. So yeah -- get a graphic lib.