Peer review of some sort.

Started by
2 comments, last by Crusable77 11 years, 1 month ago

Hello, I just finished my first game, a pong clone and It would be awesome if someone( or more) could review my code and design choice. There are some known issues such as the collision, when the ball hits the top or bottom of the players paddle it will disappear or rattle around and get spit out. If this happens to the enemy then the ball will get stuck inside. Also, the AI is very bad, as far I I have seen, the AI will never lose. Lastly, there is no sound or text, however there is a working score system, you just don't know the score unless you count. I will probably fix these in the next day or so. The reason I would like the peer review is because if I am making big mistakes, or using bad programming practices they can be fixed asap. I have included a link to the project with working exe's (they work on my PC, windows 7 laptop) however if you are not comfortable downloading the files, pm me and I will just put them in chat. Thank you in advance for any help.

Link: https://docs.google.com/file/d/0BzAXLewFU0RnTzJFaG5CNkFVRTA/edit?usp=sharing

Advertisement

I had a quick squiz and these are parts that imo need fixing:

  1. Your game class has static values for some reason when they could in fact be given in the constructor (Screen width, height, bpp and max fps).
    1. You could then also load those values from an ini file or something to stop having any kind of magic numbers
  2. You aren't dealing with the fact that your game might run at an fps lower or higher than 60. Have a look at delta time in regards to games or physics simulations or if you want something more advanced google Fix your timestep.
  3. You are manually calling move and draw on your entities, what if you wanted multiple balls in the game? Have a generic update and draw method which entities can implement and just loop through them calling those two methods.
  4. All entities have a score, I don't know why. Should be in your game class or in a paddle class.
  5. You are using a string to decide between a ball and paddle in your base entity class. I don't think that's the best way, you could have something like Entity->MoveableEntity->ChaseObjectEntity. (I start making things complicated here...)
    1. You could also then have a Controllable->PlayerController and AIController. That way you could have an ai controller attached to a paddle class so two AI's could vs eachother or have EasyAI and HardAI controllers.
    2. Plus a Collidable class where collidables are inside the collision class and all get looped through and checked for collisions, the ball would reverse it's velocity on collision. Collidables would need an OnCollision function.
  6. You need to make sure you keep to the same naming convention (KeyState and Collid vs mPlayer etc)

Well...I got a little carried away and this seems a little overkill for this game but it would make it more generic and give you the ability to add more things easier! Something I did like was the simplicity of your code it all does what it needs which is fine, remember that!

Engineering Manager at Deloitte Australia

Something that'd make life easier for sharing code like this would be GitHub; it'd also mean you wouldn't need anyone to worry about mentally filtering out object files or generated executables. But that's completely off topic.

It's nice to see somewhat consistent formatting. Definitely a great start.

Only thing I can really see is the use of the 'TYPE' enumeration in 'entity.h'. You've tied the entity class quite heavily to it but you've kept the enumeration outside of the class. I'd recommend putting the definition of the enumeration as a public member of the class. It means if you copied the class you'd not accidently forget about including it.

EDIT: Also, Bjarne Stroustrup recommends making base classes take care of themselves. You've provided an interface for tracking member changes but you've also made all the members 'protected' giving derived classes access anyway. Make them private and force access through through functions; at least that way you can enforce value ranges, etc in an easier fashion.

The enum Type in entity class is a mistake, for some reason I decided not to do that and I forgot to remove it apparently. Thanks for the feedback.

This topic is closed to new replies.

Advertisement