SFML community forums
General => SFML projects => Topic started by: klefmung on June 09, 2018, 04:26:01 pm
-
Hey guys, I am mostly self taught and have been improving my code by having it scrutinized on the internet. I've been doing a coding bootcamp for a few weeks now though, so I haven't had a chance to do any C++ or SFML for a while. Only ruby. This is my attempt to refresh my memory. This is the first one I needed any kind of physics for, so lets see what you think:
https://github.com/letsdothis64/Pong
-
It's quite okay. I couldn't test it because my screen is too small and changing the resolution constant breaks (?) the game.
There is some minor stuff like:
- Game.h include guard being CREDIT_CARD_H (technically not an error but still)
- Including Graphics.hpp even when you just want one or two classes (like Vector2 in settings.h is all you needed, etc.) or forward declarations would be enough
- There's no need to keep font reference in Score
- score could be initialized in the body of the class instead
- unitVector could be just a free static function, not a member of Ball
- You could have used a fixed time step but it's probably 60 updates per second like this already so it's kind of 'fixed' by how gameLogic is called once per frame
- More const use for local variables, getters methods, etc. and using f with float consts, etc.
- Technically including cmath puts stuff into std, not necessarily into global namespace
- hpp for headers of C++ (dubious, since h works and lots of projects use it, but I prefer to make it explicit between C and C++)