Programming Pong in Java! (Full Tutorial)

In this video, we make pong in java, with menus, bots, and all!
Be sure to leave a like, and subscribe for more!

Download my version of Pong!
http://www.mediafire.com/download/572fidw7ymo07v2/Pong.jar

Look at the source code over on github!
https://github.com/Jaryt23/PongTutorial

Hey everyone, I wanted to give a huge thanks for all of the support and feedback on the last coding video, sorry for such the huge delay in uploading this next one!

Comments

Brandon Willis says:

I have never programmed a game before, and you really fly through everything. I just have to like keep going and then I assume it’ll just click when I look back, right? haha

SvenMcSvenington says:

Hey how would you create a time delay for the for the ball to spawn?… I simply want the ball to wait 5 seconds after a goal before it spawns again and I have not been able to figure it out.

Streamlines says:

I think that this would have been much better if you just had the finished code on the screen and explain what everything does instead of watching you write everything down in eclipse. You’re thinking about how you want to do this and go about it live, but we’re not receiving any insight into your thoughts, so in the end, following this video is no better than just copy pasting everything from your github post.

spytastic !!! says:

Great video i watched this after i could not figure out my mistake in Simon and my suggestion is do the impossible game. You know it the one game where you’re a rectangle and you have to jump over other rectangles.

Daniel Ivanovich says:

Can’t read it – font is too small

jon victor says:

hey this is simply just a suggestion but for your next java tutorials or just simple java programming videos that simply do not correlate with your tutorials, it would be nice if you increased the font size of your text making it easier to see. And if you do decide to do this thank you.

Олег Амос says:

this code very bad!

Joshua Holden says:

@Jaryt Bustard around the time of 01:08:00 when you move the code in the constructor to spawn I get an error message from my compiler telling me there is an Overridable method call in the constructor. Because of this the spawn method never gets called and my ball stopped moving. Did you not get this error?

DINDRE VLOGZ says:

you are so fast. cant you tell what you are doing

javawocky says:

When you were trying to score I was thinking that a unit test would be good – or some kind of bot v bot slapdown.

Error inscript says:

What software is this you used?

karun mathews says:

At 1 : 19 Why did you create the object at the start of the class? Is it ok if we just create it in the main function?

Brandon Wilde says:

If you could do an angry birds type game, that would be awesome. I am really just stuck on how to create the slingshot apparatus. It might be a little bit of a bigger project but I am trying to make a similar style game and it would help a ton!
Thanks

Phillip Miranda says:

God damn, Youre amazing dude

DAVID ESTEBAN BORRAZ MARTINEZ says:

Amigo! hey gracias! Esta excelente!! Espero sepas español jaja. saludos y muchas gracias, puff me salvaste el pellejo en la uni!

Eric Andresen says:

Hello, awesome tutorial.
But i found one thing i dont understand and maybe it is a bug.When you declare winner and using a bot as openent you use the argument – if(bot) { “The Bot Wins!” }, isent that argument always true eaven if not the bot wins if you are playing against a bot? :)

vsp 007 says:

Your tutorial is amazing…

Timothy Basaldua says:

Please! Please! Enlarge the font size as much as possible.
Thanks.

reuel rivera says:

awesome! thanks 😀

iCroissant says:

Please teach us to make some kind of simple side-scroller, that would be really cool.

Philip Rodriguez says:

Nice tutorial. Would like to see more like these :)

sSoul_17 says:

Can someone just give me the text for a quick copy and paste. Apparently this is like the hardest game to try and find for download on the Internet.

LUNG Production says:

my teacher want this game has more choice. Ex : choose paddle , choose ball, choose background . Please help me for my homework :”< . Thankyou very much

The1888pop says:

Awesome! Great tutorial 😀 +sub

Jason Kao says:

Is the purpose of the ActionListener to make the game run with the timer?

Eder s says:

You could have made the font bigger, I struggle reading what you are typing, really good example of a game though

Jared Murphy says:

Is there a way I can use a JPG Image instead of the rendered ball?

Alex Jones says:

thank you for making this video man. its nice to see your approach and ive learned alot so far. however, im stuck just passed the one hour mark where you correct the randomness of the ball movement. the ball is moving smoothly but it no longer recognizes collision with the paddle. ive been going over my code for hours and nothing is sticking out to where my mistakes are obvious to me. i did make some minor changes from your code such as wording and variables in the main class ‘Pong’ (eg. jframe.setSize(width + 15,height +35) along with color variants and i also changed
//paddle size master public int x, y, width = 35, height = 150;
in paddle class
i dont know if this would affect the ball class but just to be thorough ill throw that out there. heres what my ball class is looking like

package paddleJockey;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;

public class Ball
{

public int x, y, width = 25, height = 25;

public int motionX, motionY;

public Random random;

private Paddlejockey paddlejockey;

public Ball(Paddlejockey paddlejockey)
{
this.paddlejockey = paddlejockey;

this.random = new Random();
this.x = paddlejockey.width / 2 – this.width / 2;
this.y = paddlejockey.height / 2 – this.height / 2;

this.motionY = -2 + random.nextInt(4);

if (motionY == 0)
{
motionY = 1;
}
if (random.nextBoolean())
{
motionX = 1;
}
else
{
motionX = -1;
}

}
public void update(Paddle paddle1, Paddle paddle2)
{
int speed = 5;

this.x += motionX = speed;
this.y += motionY = speed;

if (this.y + height > paddlejockey.height || this.y < 0) { if (this.motionY < 0) { this.motionY = random.nextInt(4); } else { this.motionY = -random.nextInt(4); } } if (checkCollision(paddle1) == 1) { this.motionX = random.nextInt(4); this.motionY = -2 + random.nextInt(4); if (motionY == 0) { motionY = 1; } } else if (checkCollision(paddle2) == 1) { this.motionX = 1; this.motionY = -2 + random.nextInt(4); if (motionY == 0) { motionY = 1; } } if(checkCollision(paddle1) == 2) { paddle2.score++; } else if(checkCollision(paddle2) == 2) { paddle1.score++; } } public int checkCollision(Paddle paddle) { if (this.x < paddle.x + paddle.width && this.x + width > paddle.x && this.y < paddle.y + paddle.height && this.y + height > paddle.y)
{
return 1;
}
else if ((paddle.x > x + width && paddle.paddleNumber == 1) || (paddle.x < x && paddle.paddleNumber == 2)) { return 2; } return 0; //nothing } public void render(Graphics g) { g.setColor(Color.WHITE); g.fillOval(x, y, width, height); } } its probably something so mundane ill end up with my head in my hands for a while. java is my first language and i have only a few tutorials under my belt so far. thanks again for this video and for adding a bit of diversity to the eclipse game tutorials available. ill be sure to come back to your channel to learn more.

Adeyemi Ibijemilusi says:

A side scrolling game would be appreciated.

Марио Христов says:

Hello great tutorial but i have a problem I can’t open the jar file from other computer it gives the error”couldn’t find or load main class”. Please help Jaryt Bustard.

Cameron Adams says:

hey man, nice work. i like your speed and efficiently on the keyboard. what shortcut do you to select a whole line? (without using shift + arrows, like select a whole line INSTANTLY)
thanks :)
PS you should do a short tutorial on your keyboard techniques for efficiency, that would be fantastic

Write a comment

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours