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

Author Topic: New to SFML - Is there anything wrong with this code?  (Read 1038 times)

0 Members and 1 Guest are viewing this topic.

jh1997sa

  • Newbie
  • *
  • Posts: 2
    • View Profile
New to SFML - Is there anything wrong with this code?
« on: February 21, 2013, 08:25:06 pm »
Hey,

I'm very new to C++ and SFML. I've been programming in Java for a few months now but I only started C++ (and SFML) yesterday.

Anyway, I'm creating the hello world of game development, Pong.

If someone could just go through this code and check if there's anything significant which I could improve, it would be much appreciated!

GitHub link: https://github.com/jh1997sa/Game-Development

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: New to SFML - Is there anything wrong with this code?
« Reply #1 on: February 21, 2013, 10:55:49 pm »
For one of your first application/games with C++ and SFML, your code is extremely good! :)
Clean interfaces and nicely organized code, if only everyone would start off that way... ;)

Here are a few suggestions, how you can make your code even so slightly better:
  • Use SFML 2 - see here for more information.
  • Pack your code from main.cpp also into a class, e.g. Application or Game, and only create an instance of the new class in the main function. (Similar on how'd go about in Java, just with main part outside of any class.)
  • The one-line if statement bodies in Paddle::input could need some indentation, so the flow gets clearer.

Other than that I can't really critics more, then again the codebase is rather small so eventual design issues, might only become clear in the future.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

jh1997sa

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: New to SFML - Is there anything wrong with this code?
« Reply #2 on: February 22, 2013, 12:03:29 am »
Well I've made a few simple games with Java so I guess that helps.

Oh and I'm the guy who was on the IRC channel earlier trying to get SFML 2 to work. Anyway I've got it working now so I'll rewrite it using SFML 2 and, well, finish the game.

Thanks for your reply!

 

anything