Pong in Java

Hello guys,

My name is Ivan, I am kinda new in Java but I tried to make a simple good old pong game just to see if I have the “skill” for making even the simplest of games.

Download the jar on this link.(Oldest Version look below for newer!)

Any advice for the game, future reference, comments would be appreciated ;D

|---------SCREENSHOTs OF THE GAME---------|

-MyPong Boost Update Version

-MyPong AI Update

-MyPong First Look

|---------CONTROLS---------|

-W/S Player 1 Movement
-UP/DOWN Arrow Player 2 Movement
-U - UNPAUSE
-P - PAUSE

|---------GAMEPLAY VIDEO (OUTDATED)---------|

6E3uNzKpClU

!------------AI UPDATE------------!

- Download

!------------BOOST UPDATE------------!

- Download

|---------BOOST UPDATE CONTROLS---------|

-W/S Player 1 Movement
-B - Boost
-P - PAUSE & UNPAUSE

Welcome on the forums! :point:

  • You double-posted your entry on the forum. This is a bit frowned upon :slight_smile:
  • Please don’t create topics in ‘featured games’ as mods will handpick game topics and move them to that board.
  • I moved your 2nd topic to the ‘work in progress / toy projects’ board, which was more suited.

Could you please add a screenshot of your game to the first message in the topic, so we can get a feel for the game you published?

Thanks ;D

I realized that I was in the wrong section after I posted my topic, I tried to delete it but I didn’t have the permission of course :stuck_out_tongue:

Thanks for the advice, I added a screenshot and edited my post a lil.

This is my first post so yeah sorry if I caused any inconvenience. :slight_smile:

Y’know somethin’? You completed a game. That puts you ahead of my years of fiddling with stuff but never quite creating something that was, well, y’know, playable. Even if pong is just pong, it’s definitely an excellent first project!

I can’t get it to play. The jar opens fine and opens with the game paused. But the “H” for help does not seem to work for me, and I cant figure out how to start the game.

Well you always have to start small, if you get caught up on to a big project you’ll just get stuck and it’s not like a single programmer can do all the work that it takes for creating a game.

And sorry I should have mentioned that u should use U for UNPAUSE and P for PAUSE.

The help menu is not yet completed but yet again this game is far from finished.

This game doesn’t have an AI right now so you can only play it with two players Player 1 with W/S and Player 2 with UP/DOWN Arrow.

!------AI UPDATE------!

Download Here

I made the AI today and I just can’t beat him…I guess I need to fix that too.

Also I made some bug fixes on how sometimes u appear to hit the ball with the paddle but you still lose .-.

I doesn’t seem to matter where in the paddle you hit the ball, it will always come off the bat in the same way. The AI is already moving to the right position before the ball even gets to you because it looks like it has already calculated where it is going. With out variation of how the ball comes off the paddle there isn’t really much for the AI to think about. It could probably calculate the next 1000 positions it needs to go to before I get the first bounce in.

I guess I should calculate the direction of where the paddle is going plus where the ball lands on the paddle to get the right bounce.
Actually the AI is pretty simple as well he just follows the movement of the ball’s height coordinate with a given speed, I am gonna have to work on this too. :stuck_out_tongue:
Thank you for the critic, I’ll have more time to work on it as soon as I finish my first semester next week ;D

Having the ball bounce in the same direction regardless of the point of contact (on a specific face) is actually physically correct behavior, as long as the face is perfectly flat. You can change the outbound angle by moving the paddle during the collision. This means that the ball actually has to intersect the paddle for a tiny (non-zero) period of time. Things get surprisingly complex fast, which is why everybody cheats by working the relative position to the paddle into some blatantly wrong algorithm that ‘feels fun’ - it is a game after all…

You can lookup some YouTube videos of the First pong ever, it was mostly analog logic, the ball didn’t even have a straight trajectory, you could move the paddle along 2 axis, it would bounce off the net in the middel - way better than any pong clone since.

XNRx5hc4gYc

-I73oK9q-jk

It is physically correct, at first it enters at 45 degrees and it exits at the same angle on the other end, as time passes the angle differs but not by much.

In other words if I don’t want to do the math, I can always make a fake algorithm that would probably be more fun.
And as always those non-logical fictional movements are a lot more fun xD
I guess I forgot to think a little out of the box about these things.

Thanks for the advice Riven will google some others pong examples, I appreciate it since I am kinda new around here :3

There are two things you can do for the bounce angle: make the angle dependent on the position the ball hits the bat (and then make the bat sprite slightly rounded to make this truly realistic) or make the output angle dependent on the current motion of the bat. The second option works better if the motion of the bat is variable (e.g. has a simple acceleration/deceleration).

<--------------------------UPDATE-------------------------->

-AI improved
-All in all the gameplay is balanced
-Paddle reverse hit available if you hit the ball back from where it came from
-Ball speed depends on reverse hits
-“Boost” added, you can use it while holding your paddle steady and holding down the button B
-When you use boost the ball goes straight at a “current speed” and then it bounces in an random trajectory.
-3 reverse hits = +1 boost, each player has 3 boost when the game starts
-args1 took the advice for the round look on the paddles, you were right it looks better and feels better, thanks :3
-I made the pause on one button only, because some people were confused(P to pause and then P to unpause).
-When the game starts it automatically starts with a boost, and when you continue playing(play again) the ball chooses a trajectory randomly.

All in all the whole game is running around the reverse(perfect) hits right now.

<--------NEW CONTROLS--------->
-W/S for movement
-P to Pause and Unpause
-B for Boost(while holding the paddle steady)
-ENTER to Play Again!

!-And finally to download this version press here.

And once again thanks to everyone who took the time to comment and give advice, it gave me lots of ideas, inspiration and motivation!