Hi, thanks for stopping by. I had posted to this forum previously after making a really dumb, basic asteroids game without understanding much. So after learning quite a bit more about LibGDX itself instead of snippets of tutorials for how to achieve specific things, I have returned! Since I’m new to game programming and development, I thought it best if I started at the very basics. After reading up on the LibGDX github, I’ve created a 2 player Pong clone.
Pong clone
SOURCE CODE
It works, but I feel like it was pretty lazily made. I got a little excited and wanted to see if I could knock this project out in a few hours, so I feel as though I’ve cut some corners. You can find the whole code here, it’s pretty basic. Anyways, I just wanted to post my code to see if there is any criticism to how I can improve.
Things that I’ve noticed:
- The first problem I have with it, is that the ball’s vertical trajectory (e.g., when it moves in a diagonal fashion) is subject to pure chance and probability. It is in no way related to what part of the paddle collides with the ball. I’m honestly not sure what the true gameplay mechanic is in the actual game Pong. If I wanted to improve this, my course of action would be to make three rectangles to serve as collision boxes and depending on where the ball hits (top 1/3 - move the ball up, middle 1/3 - send it straight across, or bottom 1/3 send it downwards). See lines 129-137 and 182-199 for the code that handles this probability.
- The second problem is, I don’t feel as though I’m handling system resources correctly. I’ve tried to add everything that I could to the dispose() method that I can, which for now is just the ShapeRenderer, and I think that when I stop and run the game over and over it starts to lag my system and I have to kill the JVM. I’m not sure if this is a result of my code and bad resource handling and it’s creating memory leaks or not. Thoughts?
Again, thanks for reading the long post.
edit: You can download the runnable JAR here