[LibGDX] Basic Pong clone - just a few questions

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

Pong physics depends on how you want to do it. You can have something like the center being a more elastic than the edges (When you hit in the center, the total delta of the pong ball doesn’t go down, or perhaps even increases slightly) and less so at the edges (If you hit at an edge the ball slows down or stays at the same speed.) Or you can do it the other way around! A lot of it is dependent on how you want to do it.

When it comes to debugging the lagging issues having the source code available is more helpful than the .jar.

I noticed that some Java applications haven’t been exiting correctly on my system (Which is what the killing the JVM would have to do with). A couple of the LD entries did it to me.

I think I may implement that just to tie up loose ends before moving onto a more complicated project to learn new things. Thanks for clearing that up for me!

Source code.

That’s all the code I wrote, it’s an incredibly basic game so all of my code is just in that main class. I’ve put everything in the dispose() method that implements the disposable interface, which is only the ShapeRenderer object. Aside from that it’s my understanding that LibGDX should clean everything else up unless there’s something I’m missing.