Programming Pong in Java! (Full Tutorial)

preview_player
Показать описание
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!

Look at the source code over on github!

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!
Рекомендации по теме
Комментарии
Автор

Thank you for supplying the source code in the description. Reading it completed helped me understand it :)

jacobclement
Автор

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.

Mr_Victor_
Автор

At 50:43 in line 50, when I removed "start();" the PONG game shows up blank and the console is endlessly putting out errors. why

Spam-lofu
Автор

@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?

joshuaholden
Автор

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

cameronadams
Автор

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

brandonwillis
Автор

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

javawocky
Автор

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.

spytastic
Автор

22:33 You could have just added height to 0 in the up and subtracted height from pong.height in the down. this would rescrict the paddle more and that way u wouldnt notice the jerk

liorbd
Автор

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

pr
Автор

thanks this is a great tutorial, i was just wondering how do you add images to the menu screen for example?

jamesparkinson
Автор

Your tutorial is awesome, but we are watching a tutorial to be explained how to do something.. Not showed.. So please explain what you do, thank you.

tanyasullivan
Автор

Where is the last video which he is referring to watch ?

chrischauhan
Автор

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

basalduat
Автор

Can anyone explain for me the role of "Rerender " class in this project ?

tuanvu
Автор

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.

alexjones
Автор

A tip: zoom in on the text editing area so People can see what you are writing better.

legogeniusst
Автор

My Player 1 Paddle is not moving,

how could i make it operational..

mostofaomarfattharusho
Автор

I want to learn java swing but I saw that most people use javafx nowadays to create stuff. What is used more nowadays and which is better?

marker
Автор

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

ederm