How to Program Pong in Java

preview_player
Показать описание

Demonstration of how to program the game Pong in Java.
Рекомендации по теме
Комментарии
Автор

wow, that was amazing;
I learned so much from that, and I understood very easy!
please do more other games, you explain very well!
thank you very much!

muhammadahmadi
Автор

This was actually very fun, helpful and well-explained.. Thank you so much!

smallblueflower
Автор

One of the best Java demos on YouTube!! Thank you.
One very important suggestion . . . enlarge the font to 24 pts and use a white background. A black background with colored text is very hard to read. Think of the viewer. Most of us need glasses and can only afford small cheap computer screens.
You are very talented. I hope to see more of your Java demos.

basalduat
Автор

I learned alot! Very nice code to fool around with :) I only wished this was made with JFrame and had a main method.. This Applet stuff goes against everything I have learned about gameprogramming since my book doesn't even mention "Applet"

paipai
Автор

Really well documented guide! Just started coding and this taught me a lot! Thank you very much :)

aleksandarlukic
Автор

16:14, I am here but I cannot everytime I start the applet it goes to the top and stays locked there (with an occasional blink) I have done it from the beginning to check everything - had mixed a false/true statement, but it's still unchanged

serggc
Автор

Hi, Great video and excellent demonstration. I wanted to know a coupla things which some people may be wondering.
1) - How would I create a menu which the user can click options such as: play, 2 player, instructions, and quit.
2) - How to make the game restart with a spacebar rather than having to re-open the window each time,
3) - A scoring system every time the ball is bounced, or score by rounds or some form of score,
4) - How to make the game two player where the second user can use other keys on the keyboard,
5) - Allow the AI to let at least one ball concede.
Massive thanks for this vid, and I know this sounds like a lot, but I just wanted to see if anyone could help.
Thanks!

tayo
Автор

Brilliant tutorial! Easy to follow, really a great project after learning the fundamentals to help me feel like I'm progressing. Thanks for making this, I've subscribed to your channel

owenodonnell
Автор

Great job, could not have explained it better. Thanks a ton !!

pranoymehra
Автор

Thank you for the walkthrough. Not as bad as I originally thought. A few alterations I added to my code:
1) When game ends, it prompts the user to press ENTER to start a new game
2) Applet pops up in center of the screen by default
3) The speeds are a lot faster for the paddles
4) The AI can actually lose :)

motorheadbanger
Автор

Nice video bro. I am having some problem - When I run the program after writing the code for off-screen buffer, it throws me exception saying " Cannot invoke because this.gfx is null"
on the line where we set gfx's color ( gfx.setColor(Color.BLACK)) in paint method. Although the game runs perfectly fine, I am worried about the exception. Also I get an warning message sometimes warning me about low memory(which says if I don't close the program, it could cause harm to my computer's data). Since Applet is deprecated now(Also I don't know how to use them), I used JFrame instead and have done the necessary initialisations. Rest of the code is almost same. Please help me out. (Will paste the code in the comments if you want them)

hrishikeshacharyya
Автор

need help i am getting a NullPointException from the p1.move() method call in run() method of tennis class
I am on a mac and the key event inputs work fine
due to the aforementioned error the paddle isn't moving

Jinom_
Автор

I don't understand how img gets updated. You initialize it to pull from gfx once, and then gfx gets updated. When does img get updated?

alanhonlunli
Автор

Little late to the party but hope you see this. First off awesome tutorial on this. Works like a charm. One thing I found though is an error in the checkPaddleCollision. With it set to x<=50 if the ball passes the paddle but you quickly move the paddle up so that the ball is behind the paddle, it will still bounce back since the x value of the ball is greater than 0 (game over) and less than 50(the paddle). I thought setting the condition to just be 50 would work but using some print outs I find that every run through has a different number for the collision of the ball with the paddle. Do you know why that is?

michaelphilipps
Автор

Unfortunately the "Applet" function has been removed from java and it is now bad practice to use it. If you type this in the Tennis class it will open a window with the same dimensions using up to date syntax :)
JFrame obj = new JFrame();
obj.setBounds(10, 10, 700, 500);
obj.setVisible(true);
obj.setTitle("Pong");
obj.setResizable(false);

AliFX
Автор

If the KeyListener methods aren't being fired when a key is pressed/released, add this to your init() method:

setFocusable(true);
requestFocusInWindow();

matthewchansavage
Автор

How did you import those Applet methods instantaneously at 0:40?

masterofkaarsvet
Автор

Java applets have deprecated now. What is its alternative?

meghna
Автор

Thanks for the awesome tutorial! I learned a lot. Keep making awesome videos! Subscribed!

RationalLlama
Автор

hey guys, i need your help, so did copy all his code to try understand the basics, which i did, but he didn't show us the public main (String...) code, so i can export the project as a working java app, can you please help me with this, and sorry for my english

achraf