Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: critique my pong code?  (Read 3119 times)

0 Members and 1 Guest are viewing this topic.

klefmung

  • Newbie
  • *
  • Posts: 12
    • View Profile
critique my pong code?
« 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

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: critique my pong code?
« Reply #1 on: June 12, 2018, 05:50:16 pm »
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++)
« Last Edit: June 12, 2018, 05:52:12 pm by FRex »
Back to C++ gamedev with SFML in May 2023