Java pong game 🏓

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ก.พ. 2025
  • Java pong game tutorial for beginners
    #Java #pong #game
    Coding boot camps hate him! See how he can teach you to code with this one simple trick...
    Bro Code is the self-proclaimed #1 tutorial series on coding in various programming languages and other how-to videos in the known universe.

ความคิดเห็น • 398

  • @BroCodez
    @BroCodez  4 ปีที่แล้ว +333

    //***********************************
    ***************************
    public class PongGame {
    public static void main(String[] args) {

    GameFrame frame = new GameFrame();

    }
    }
    //***********************************
    import java.awt.*;
    import javax.swing.*;
    public class GameFrame extends JFrame{
    GamePanel panel;

    GameFrame(){
    panel = new GamePanel();
    this.add(panel);
    this.setTitle("Pong Game");
    this.setResizable(false);
    this.setBackground(Color.black);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.pack();
    this.setVisible(true);
    this.setLocationRelativeTo(null);
    }
    }
    //***********************************
    ***************************
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class GamePanel extends JPanel implements Runnable{
    static final int GAME_WIDTH = 1000;
    static final int GAME_HEIGHT = (int)(GAME_WIDTH * (0.5555));
    static final Dimension SCREEN_SIZE = new Dimension(GAME_WIDTH,GAME_HEIGHT);
    static final int BALL_DIAMETER = 20;
    static final int PADDLE_WIDTH = 25;
    static final int PADDLE_HEIGHT = 100;
    Thread gameThread;
    Image image;
    Graphics graphics;
    Random random;
    Paddle paddle1;
    Paddle paddle2;
    Ball ball;
    Score score;

    GamePanel(){
    newPaddles();
    newBall();
    score = new Score(GAME_WIDTH,GAME_HEIGHT);
    this.setFocusable(true);
    this.addKeyListener(new AL());
    this.setPreferredSize(SCREEN_SIZE);

    gameThread = new Thread(this);
    gameThread.start();
    }

    public void newBall() {
    random = new Random();
    ball = new Ball((GAME_WIDTH/2)-(BALL_DIAMETER/2),random.nextInt(GAME_HEIGHT-BALL_DIAMETER),BALL_DIAMETER,BALL_DIAMETER);
    }
    public void newPaddles() {
    paddle1 = new Paddle(0,(GAME_HEIGHT/2)-(PADDLE_HEIGHT/2),PADDLE_WIDTH,PADDLE_HEIGHT,1);
    paddle2 = new Paddle(GAME_WIDTH-PADDLE_WIDTH,(GAME_HEIGHT/2)-(PADDLE_HEIGHT/2),PADDLE_WIDTH,PADDLE_HEIGHT,2);
    }
    public void paint(Graphics g) {
    image = createImage(getWidth(),getHeight());
    graphics = image.getGraphics();
    draw(graphics);
    g.drawImage(image,0,0,this);
    }
    public void draw(Graphics g) {
    paddle1.draw(g);
    paddle2.draw(g);
    ball.draw(g);
    score.draw(g);
    Toolkit.getDefaultToolkit().sync(); // I forgot to add this line of code in the video, it helps with the animation
    }
    public void move() {
    paddle1.move();
    paddle2.move();
    ball.move();
    }
    public void checkCollision() {

    //bounce ball off top & bottom window edges
    if(ball.y = GAME_HEIGHT-BALL_DIAMETER) {
    ball.setYDirection(-ball.yVelocity);
    }
    //bounce ball off paddles
    if(ball.intersects(paddle1)) {
    ball.xVelocity = Math.abs(ball.xVelocity);
    ball.xVelocity++; //optional for more difficulty
    if(ball.yVelocity>0)
    ball.yVelocity++; //optional for more difficulty
    else
    ball.yVelocity--;
    ball.setXDirection(ball.xVelocity);
    ball.setYDirection(ball.yVelocity);
    }
    if(ball.intersects(paddle2)) {
    ball.xVelocity = Math.abs(ball.xVelocity);
    ball.xVelocity++; //optional for more difficulty
    if(ball.yVelocity>0)
    ball.yVelocity++; //optional for more difficulty
    else
    ball.yVelocity--;
    ball.setXDirection(-ball.xVelocity);
    ball.setYDirection(ball.yVelocity);
    }
    //stops paddles at window edges
    if(paddle1.y= (GAME_HEIGHT-PADDLE_HEIGHT))
    paddle1.y = GAME_HEIGHT-PADDLE_HEIGHT;
    if(paddle2.y= (GAME_HEIGHT-PADDLE_HEIGHT))
    paddle2.y = GAME_HEIGHT-PADDLE_HEIGHT;
    //give a player 1 point and creates new paddles & ball
    if(ball.x = GAME_WIDTH-BALL_DIAMETER) {
    score.player1++;
    newPaddles();
    newBall();
    System.out.println("Player 1: "+score.player1);
    }
    }
    public void run() {
    //game loop
    long lastTime = System.nanoTime();
    double amountOfTicks =60.0;
    double ns = 1000000000 / amountOfTicks;
    double delta = 0;
    while(true) {
    long now = System.nanoTime();
    delta += (now -lastTime)/ns;
    lastTime = now;
    if(delta >=1) {
    move();
    checkCollision();
    repaint();
    delta--;
    }
    }
    }
    public class AL extends KeyAdapter{
    public void keyPressed(KeyEvent e) {
    paddle1.keyPressed(e);
    paddle2.keyPressed(e);
    }
    public void keyReleased(KeyEvent e) {
    paddle1.keyReleased(e);
    paddle2.keyReleased(e);
    }
    }
    }
    //***********************************
    ***************************
    import java.awt.*;
    import java.awt.event.*;
    public class Paddle extends Rectangle{
    int id;
    int yVelocity;
    int speed = 10;

    Paddle(int x, int y, int PADDLE_WIDTH, int PADDLE_HEIGHT, int id){
    super(x,y,PADDLE_WIDTH,PADDLE_HEIGHT);
    this.id=id;
    }

    public void keyPressed(KeyEvent e) {
    switch(id) {
    case 1:
    if(e.getKeyCode()==KeyEvent.VK_W) {
    setYDirection(-speed);
    }
    if(e.getKeyCode()==KeyEvent.VK_S) {
    setYDirection(speed);
    }
    break;
    case 2:
    if(e.getKeyCode()==KeyEvent.VK_UP) {
    setYDirection(-speed);
    }
    if(e.getKeyCode()==KeyEvent.VK_DOWN) {
    setYDirection(speed);
    }
    break;
    }
    }
    public void keyReleased(KeyEvent e) {
    switch(id) {
    case 1:
    if(e.getKeyCode()==KeyEvent.VK_W) {
    setYDirection(0);
    }
    if(e.getKeyCode()==KeyEvent.VK_S) {
    setYDirection(0);
    }
    break;
    case 2:
    if(e.getKeyCode()==KeyEvent.VK_UP) {
    setYDirection(0);
    }
    if(e.getKeyCode()==KeyEvent.VK_DOWN) {
    setYDirection(0);
    }
    break;
    }
    }
    public void setYDirection(int yDirection) {
    yVelocity = yDirection;
    }
    public void move() {
    y= y + yVelocity;
    }
    public void draw(Graphics g) {
    if(id==1)
    g.setColor(Color.blue);
    else
    g.setColor(Color.red);
    g.fillRect(x, y, width, height);
    }
    }
    //***********************************
    ***************************
    import java.awt.*;
    import java.util.*;
    public class Ball extends Rectangle{
    Random random;
    int xVelocity;
    int yVelocity;
    int initialSpeed = 2;

    Ball(int x, int y, int width, int height){
    super(x,y,width,height);
    random = new Random();
    int randomXDirection = random.nextInt(2);
    if(randomXDirection == 0)
    randomXDirection--;
    setXDirection(randomXDirection*initialSpeed);

    int randomYDirection = random.nextInt(2);
    if(randomYDirection == 0)
    randomYDirection--;
    setYDirection(randomYDirection*initialSpeed);

    }

    public void setXDirection(int randomXDirection) {
    xVelocity = randomXDirection;
    }
    public void setYDirection(int randomYDirection) {
    yVelocity = randomYDirection;
    }
    public void move() {
    x += xVelocity;
    y += yVelocity;
    }
    public void draw(Graphics g) {
    g.setColor(Color.white);
    g.fillOval(x, y, height, width);
    }
    }
    //***********************************
    ***************************
    import java.awt.*;
    public class Score extends Rectangle{
    static int GAME_WIDTH;
    static int GAME_HEIGHT;
    int player1;
    int player2;

    Score(int GAME_WIDTH, int GAME_HEIGHT){
    Score.GAME_WIDTH = GAME_WIDTH;
    Score.GAME_HEIGHT = GAME_HEIGHT;
    }
    public void draw(Graphics g) {
    g.setColor(Color.white);
    g.setFont(new Font("Consolas",Font.PLAIN,60));

    g.drawLine(GAME_WIDTH/2, 0, GAME_WIDTH/2, GAME_HEIGHT);

    g.drawString(String.valueOf(player1/10)+String.valueOf(player1%10), (GAME_WIDTH/2)-85, 50);
    g.drawString(String.valueOf(player2/10)+String.valueOf(player2%10), (GAME_WIDTH/2)+20, 50);
    }
    }
    //***********************************
    ***************************

    • @ItamiPlaysGuitar
      @ItamiPlaysGuitar 4 ปีที่แล้ว +21

      bro, you don't really have to publish the source code, all we need is the idea and you are explaining it already. btw thanks for the video. god bless you

    • @cate01a
      @cate01a 4 ปีที่แล้ว +25

      @@ItamiPlaysGuitar I really like having the source code; it's especially helpful for debugging, to see simple errors where I misspelled something.
      Also, if I wanted to merely find out how he made the ball move at an angle, I could quickly scan the Ball class, which is super nice

    • @elvastaudinger4991
      @elvastaudinger4991 4 ปีที่แล้ว +4

      i think you people deserve being paid a lot. this job could shorten lifetime.

    • @cate01a
      @cate01a 4 ปีที่แล้ว +3

      @@elvastaudinger4991 how could coding shorten lifetime?

    • @exploringatpar
      @exploringatpar 4 ปีที่แล้ว +6

      i followed everything but my paddles are not moving :((( great video tho!!! 💛

  • @ultimatelegoman1279
    @ultimatelegoman1279 3 ปีที่แล้ว +116

    This channel is SOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO underrated

  • @nikj1178
    @nikj1178 3 ปีที่แล้ว +90

    Finally finished all 100 videos. Thank you for making this, it really helped me understand some of the slightly more advanced concepts. I'll be returning to the vids whenever I'm stuck!

  • @Dygit
    @Dygit 4 ปีที่แล้ว +44

    I think your channel will boom soon

    • @JohnBuddy
      @JohnBuddy ปีที่แล้ว +1

      Absulotely right! 1 mil soon!

  • @vietlequoc1171
    @vietlequoc1171 3 ปีที่แล้ว +10

    Thank you for your video , just 1 hour but I spent very much time to understand apparently what you did in your code, especially in game loop , workflow of a basic game. I think my java skill is better than I before. Have a great day ,hope you will release many wonderful video in the future.

  • @moxeingames1714
    @moxeingames1714 3 ปีที่แล้ว +10

    I saw this video at the beginning of learning Java and with this video I was able to create an interesting and simple game, and it had an important impact on my programming way, I owe you and thank you so much

  • @davidbartholomew7081
    @davidbartholomew7081 3 ปีที่แล้ว +4

    followed the whole way through and I found it very fun! The best part is being able to dissect the code after and understanding every bit in detail. Thank you for the video!

    • @capricorn-fb8tl
      @capricorn-fb8tl 2 ปีที่แล้ว

      excuse me meri game ka interface hi nhi show ho rha hy same follow kia hy vedio ko can you guide me kya problem hy?

    • @capricorn-fb8tl
      @capricorn-fb8tl 2 ปีที่แล้ว

      or 1 error hy class panel py

  • @mindofpaul9543
    @mindofpaul9543 2 ปีที่แล้ว +9

    I appreciate you taking the time to explain everything you are doing and why. It really helps me learn instead of me just following along to get a working game.

  • @bsh3973
    @bsh3973 2 ปีที่แล้ว +3

    i love this channel, whith so many overwhelming information you can focus the essential things without wasting time on futile things. And this is a great and important skill today. After a month of your videos, i can easly write core java code and write a project from scratch. Thanks dude, love you

  • @Pation655
    @Pation655 2 ปีที่แล้ว +17

    1:02:07
    optional details, instead of just drawing a straight line you can use 2d graphics for a dotted or dashed line
    as an example, I put:
    public void draw(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g.setColor(Color.white);
    g.setFont(new Font("Consolas",Font.PLAIN,60));

    Stroke dashed = new BasicStroke(4, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{25}, 30);
    g2d.setStroke(dashed);
    g2d.drawLine(GAME_WIDTH/2, 0, GAME_WIDTH/2, GAME_HEIGHT);

    g.drawString(String.valueOf(player1/10)+String.valueOf(player1%10), (GAME_WIDTH/2)-85, 50);
    g.drawString(String.valueOf(player2/10)+String.valueOf(player2%10), (GAME_WIDTH/2)+20, 50);
    }
    you helped me get into coding mate thanks a million!

  • @anomalous_guy
    @anomalous_guy 3 ปีที่แล้ว +2

    Well, I have watched all Java programing language videos in a list (if I didn't miss a single video). Thanks bro, your contents are so high quality and there's no other programing language tutorial youtubers currently known that very underated like this. Your charisma gives me spirit to learn.
    I don't have expectation very much to be expert developer yet, because reality is unknown. Therefore I also want to get developer job but I don't know nothing how it works yet, but I'll figure out how to get the job.
    Learn programing languages because I'm curious and solving problem that solved in smart way is very satisfying. So because of this, my life impossible to be bored because there are so much to do, like mediation to fresh a mind, learn new skills, playing video games etc that I overwhelmed and sometimes have no time to do those things.

  • @AdrianTregoning
    @AdrianTregoning 2 ปีที่แล้ว +3

    It's taken a while but I worked through all 100 videos and man it has stepped up my meagre knowledge by leaps and bounds. Thank you for your massive effort in creating all of these - much appreciated. If you're ever in Cape Town please let me take you for a beer! Cheers Bro.

  • @krishnaraj3989
    @krishnaraj3989 2 ปีที่แล้ว +1

    This was a realllly good video! You are underrated man, this helped me a lot in grasping the important concepts of Java, Thanks a ton to you always! You are a great teacher too!

  • @astrounivv
    @astrounivv 4 ปีที่แล้ว +5

    Loved the tutorial supper easy to fallow and works perfectly.
    Thank you keep up I'm a fan.

  • @TattedFaceJoey
    @TattedFaceJoey ปีที่แล้ว +2

    I loved this so much. Can't wait to do more! I haven't done Java in about 8 years or so, since my first year of college/uni. I found Java really difficult as it was my first coding language. (I really love coding now, favourite is Python). This has given me a love for Java and all the wonderful things it can do.

  • @keksmampfer420
    @keksmampfer420 4 หลายเดือนก่อน

    hey! Thank you for this video. I'm learning to code in college and this is very helpful!

  • @crackrokmccaib
    @crackrokmccaib 2 ปีที่แล้ว +9

    At 22:40 you could have just change (5/9) to (5.0/9.0) and it works just fine.

  • @adedamolayusuf7018
    @adedamolayusuf7018 3 ปีที่แล้ว +1

    Hi, just a new bro love how you posted all of these in-depth parts of python and explaining so well.

  • @Nusremmus
    @Nusremmus 2 ปีที่แล้ว

    Might be the best tutorial on game basics I have ever seen. AWESOME!!!!

    • @raya6800
      @raya6800 2 ปีที่แล้ว

      i didnt know how to use it i mean the red and blue rectangles dont move

  • @monwil3296
    @monwil3296 4 ปีที่แล้ว +12

    One hour worth so much,confidence builder 👌👌👌. 💯❤️

  • @TheCamelBug
    @TheCamelBug 3 ปีที่แล้ว

    Wow, thank you so much bro for the video. I coded along and created my own version. Keep them coming!

  • @Domo22xD
    @Domo22xD 3 ปีที่แล้ว +15

    So far you explain best game tutorials. You follow some order of creating things that makes it easier to follow. On point. Great for beginners in java after they learn basics and figure out how OOP works. Hope to see more game tutorials.

  • @alexandrulolea4631
    @alexandrulolea4631 ปีที่แล้ว

    Haven't watched the video yet, but I'm sure it's going to be great! Thank you and keep up the good work!

  • @Robman2314
    @Robman2314 4 ปีที่แล้ว +4

    This video is amazing! Easy to understand and follow along!

  • @mr.fakeman4718
    @mr.fakeman4718 4 ปีที่แล้ว +6

    1:06:18 That background music tho. xd
    Btw I never watched this awesome Java videos so far.
    Thank you!

  • @DamiaoFernandes-u4c
    @DamiaoFernandes-u4c ปีที่แล้ว +1

    Brother só quero agradecer por esse tutorial incrível , sou iniciante na programação java já fiz alguns programinha e até jogos , mais não tão complexo como este aqui. Eu quero muito aprender a criar jogos em java quero muito inventar o meu próprio jogo , aliás eu já fiz mais é simples. Obrigado ganhou mias um inscrito e + LIke, valeu

  • @JacobMutuku-m9z
    @JacobMutuku-m9z 4 หลายเดือนก่อน

    video worth watching, I like it.
    with a perfect play of the game at the end.

  • @Coco-coco15
    @Coco-coco15 2 ปีที่แล้ว

    Thank you for all you're doing. BRO CODE FOR LIFE!!!!

  • @sergeyb6071
    @sergeyb6071 4 ปีที่แล้ว +14

    Bro you're on fire, I see all these great videos you've been posting. I got to catch up.

    • @dansharp8380
      @dansharp8380 3 ปีที่แล้ว

      where is the code for game frame?

  • @kennethrobbinsmusic
    @kennethrobbinsmusic 2 ปีที่แล้ว

    Loved this video Bro!

  • @Ryekene
    @Ryekene 3 ปีที่แล้ว +2

    This video made my day!!!! Thank you btw

  • @stephaniepanah1387
    @stephaniepanah1387 2 ปีที่แล้ว +3

    So, I wanted to stop the game when a top score was reached. I am sure that there are better ways to do this, but this works.
    In the GamePanel class, I added:

    static final int MAX_SCORE = 21;
    static boolean gameRun = true;
    and I changed: while(true) to while(gameRun)
    and then: (I am only including one player's score here)
    if(ball.x

    • @krishmishra437
      @krishmishra437 11 หลายเดือนก่อน

      if i want to add a pause by pressing space bar how can it be possible

  • @channingpinkerton5284
    @channingpinkerton5284 3 ปีที่แล้ว +1

    Thank you for taking the time to do this

  • @pranavkulkarni7551
    @pranavkulkarni7551 2 ปีที่แล้ว

    I liked this video a lot. Easy Understanding:)

  • @leonidas14775
    @leonidas14775 4 หลายเดือนก่อน

    Tip: if you're using Eclipse like he is, press ctrl+shift+o after typing (extends BaseClass) to automatically import the base class and get rid of the red underline.

  • @BingoGo2Space
    @BingoGo2Space ปีที่แล้ว

    Love your videos. I wish I can meet you one day Legend. You are a great man.

  • @sewek1513
    @sewek1513 3 ปีที่แล้ว

    That one was difficult but also fun. And I actually like playing it :P Thank you!

  • @akshaymondal1372
    @akshaymondal1372 2 ปีที่แล้ว

    I dont have any words to explain how I glad I am .
    God bless you 🙇

  • @TricksChronicals
    @TricksChronicals 3 ปีที่แล้ว +2

    Hey this video is great can you please put a copy of this code down below please

  • @cryswerton-silva
    @cryswerton-silva 3 ปีที่แล้ว

    Thanks bro, your tutorials are awesome!

  • @noah77
    @noah77 4 ปีที่แล้ว +7

    You are... amazing!!

  • @Eevee213
    @Eevee213 หลายเดือนก่อน

    I don’t know if you’re gonna read this or anyone is gonna read this, but when I add the move function to make it smoother as you said in the video the paddles just jumped up and down with nothing in between. 😢 I think I’m just gonna make this game without it for now if I don’t get an answer, but thanks for the video. It’s really good.❤

  • @meetshah4432
    @meetshah4432 4 ปีที่แล้ว +2

    Just a small suggestion, do write @Override on the methods which you override, it will become much easier to comprehend stuff for beginners

  • @adityavikramkirtania6539
    @adityavikramkirtania6539 ปีที่แล้ว

    I loved this video really learnt a lot from this tutorial

  • @dotanon
    @dotanon 2 ปีที่แล้ว +2

    To anyone who is noticing some input delay, I responded to a comment so I figure I'll copy it up here:
    _________________________________________________________________________________________________________________
    The problem is that key events have a delay between the first time they fire and the second, after which they keep going immediately. Like you know when you type and hold down a key? First you get a W or whatever, then a delay, then suddenly you get Ws coming out super fast.
    So what you need to do is, keep booleans to store states for each key. This is easiest using an array where you store a boolean in the index at its keycode. So you make a boolean array called keys, and when W is pushed, you set keys [e.getKeyCode ()] to true. When it's released, you set it to false. So you're only handling the STATE of your keys in the listener, not any of the logic. This separates your movement from the limitations of key events.
    Then in the move method for your paddles you want to actually handle movement based on which keys are pressed. So W's keyCode is 87 and S's keyCode is 83. So in your move logic, you're gonna do something like this:
    if (keys [87] == true){
    y -= yVelocity;
    }
    And so on.
    This happens in pretty much every language and this is the usual fix :) It may sound confusing but it'll make the input smooth as butter.
    The main caveat is you have a big array which is mostly empty (I set mine to 100 because I couldn't be bothered to set them manually) but you could also just make booleans for each key
    e.g. boolean up = false;
    boolean down = false;
    boolean w = false;
    boolean s = false;
    update those in your listener
    In keyPressed: if (e.getKeyCode () == VK_UP){ up = true}
    In keyReleased: if (e.getKeyCode () == VK_UP){ up = false}
    and handle the state in your move function
    if (up == true) { yVelocity = -1}
    Doing this makes sure that there's no funky stuff with your input, your game logic will no longer be updating with the wonky keyboard event timing.

  • @Auqherus
    @Auqherus 2 ปีที่แล้ว

    Great video, as always! :D

  • @Philthyyy
    @Philthyyy 3 ปีที่แล้ว

    Great video! Commenting to help the algorithm.

  • @merrickmcfarling1795
    @merrickmcfarling1795 3 ปีที่แล้ว

    I love this channel so much

  • @lamedev1342
    @lamedev1342 4 ปีที่แล้ว +1

    Smart man separating his code 👌 clean and neat 👌

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว

      thanks Aditya
      It's much easier for me to read and teach when it's separated

    • @belahalili2550
      @belahalili2550 3 ปีที่แล้ว

      In what program, are u writing the code?

    • @davidcai9574
      @davidcai9574 2 ปีที่แล้ว

      @@belahalili2550 eclipse

  • @k15hcm11
    @k15hcm11 3 ปีที่แล้ว +1

    Thanks for sharing

  • @gamingwitharyav5611
    @gamingwitharyav5611 3 ปีที่แล้ว +1

    extremely underrated channel

  • @apprajitvaibhav7354
    @apprajitvaibhav7354 3 ปีที่แล้ว

    You made my day
    Thanks so much for your time and Work
    So inspired by your channel content
    Keep Rocking
    Love from India

  • @mo_guled
    @mo_guled 3 ปีที่แล้ว +1

    Thanks for the video bro!!!

  • @markusgavra5791
    @markusgavra5791 3 ปีที่แล้ว

    You helped me so much by your Java Tutorial and you help me just get a better understanding of everything thank you so much for you I’m done

  • @mirzaruzain5378
    @mirzaruzain5378 ปีที่แล้ว

    Thanks my bro hope your family healthy and happy

  • @mirwaiskarimi4215
    @mirwaiskarimi4215 3 ปีที่แล้ว +1

    You Are Awesome 👌 Bro

  • @diamonddunyasi4945
    @diamonddunyasi4945 2 ปีที่แล้ว

    Hey Bro you are a crazy man but you are in our hearts. Thanks for your best teaching. Best teaching cause no mistake anywhere. Thank you...

  • @prarabdhabharadwaj4113
    @prarabdhabharadwaj4113 4 ปีที่แล้ว +2

    Bro please don't stop making videos

  • @israelibarracampos8307
    @israelibarracampos8307 8 หลายเดือนก่อน

    Thanks, a really good video, but I have a question, sometimes the ball doesn't move in x or at all, how do I fix it?

  • @anukulchandra9072
    @anukulchandra9072 2 ปีที่แล้ว +1

    Bro i really trust you and your codes!! But one thing i don't understand how is uour paddles moving, while mine doesn't! I have checked my code 5 time no error or missing lines😐 why my paddles don't move bro? 😑

  • @petersonnormil6799
    @petersonnormil6799 4 ปีที่แล้ว +3

    I just finished it today, Thank you so much for making this video! Where should I begin to start adding sound effects/music?

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +3

      Here's the documentation on the javax.sound.sampled package. I currently do not have a video on it:
      docs.oracle.com/javase/7/docs/api/javax/sound/sampled/package-summary.html

    • @techommar7468
      @techommar7468 3 ปีที่แล้ว +1

      @@BroCodez can you please make some videos on it.... No other channel does it as crisp as you do....

    • @tasneemayham974
      @tasneemayham974 2 ปีที่แล้ว

      @@BroCodez Yes, bro please!!!
      Adding music buttons and pause buttons.

  • @ludovicbocquet9783
    @ludovicbocquet9783 ปีที่แล้ว

    Really nice video, thank you !

  • @gilantonyborba8163
    @gilantonyborba8163 ปีที่แล้ว

    bro! you are just outstanding!!!

  • @Avyakth_M
    @Avyakth_M 3 ปีที่แล้ว +1

    Thanks a lot, do even more projects like this and share with us. 😁😅

  • @Alexander007A
    @Alexander007A 4 ปีที่แล้ว +1

    Hello bro.....u r very interesting for me I learn many things from u..I have a lot of doubt ♥️ but change me ...u r the best may ALLAH bless you ♥️♥️♥️ lot love for you 💖❤️

  • @SportAddict_23
    @SportAddict_23 ปีที่แล้ว

    Great video Bro Code

  • @odysseaskorelides7897
    @odysseaskorelides7897 4 ปีที่แล้ว

    You are just awesome Bro...Thenx a Ton

  • @abhinavmishra7617
    @abhinavmishra7617 4 ปีที่แล้ว +2

    great tutorial....the game loop was something that i didn't understand ... where can i learn more about it?

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +2

      I found this one on StackExchange. I'm not that experienced with game dev so I looked at resources online: gamedev.stackexchange.com/questions/52841/the-most-efficient-and-accurate-game-loop/52843

    • @nandlalsharma6356
      @nandlalsharma6356 4 ปีที่แล้ว

      @@BroCodez Sir please tell me that .. the paddel moves with arrow key or not

    • @foreversleepy4379
      @foreversleepy4379 4 ปีที่แล้ว +1

      You need to understand threads before you can understand game loops in Java. I'll leave that for you to figure out. In regards to game loops, you can either use a timer object that comes with Java, or write you own game loop manually. There are many ways to implement game loops yourself but all of them will need to be executed in a separate Java thread.
      Within Java GUI apps, a thread called the "event dispatch thread" is created in the background, which is basically an infinite loop that processes and executes GUI events, mouse events, keyboard events, etc. Since the events are constantly being processed, we use a separate thread for all the game logic, like updating the game state and drawing updated graphics to the screen. Seeing as we are using 2 different threads, we can process user input, update and draw at the same time with minimal delay.
      If you go with the timer object approach, the first timer you create will spawn its own thread and will be used for timing when you call the start method on it, but the action event method/handler is executed in the event dispatch thread. So basically, game updates and game rendering takes place in the event dispatch thread, while delay happens in the timer's thread to not slow down or interrupt event processing within the event dispatch thread. (From my understanding)
      If your game is doing a lot of processing within its update or draw methods, then it's best to write your own game loop and create your own game thread. Ditch timers altogether. You don't want your process intensive game loop slowing down the event dispatch thread, therefore, slowing down the handling of keyboard and mouse input events.

  • @spectre3214
    @spectre3214 4 หลายเดือนก่อน

    Thanks bro you saved me!

  • @sidra3210
    @sidra3210 4 ปีที่แล้ว +4

    I don't understand the code in run()method.what are ns, delta,etc and what they are doing?

  • @aravindswamy9498
    @aravindswamy9498 4 ปีที่แล้ว +4

    Iam not able to move that paddles
    What might be the problem

  • @orennkimg6851
    @orennkimg6851 4 ปีที่แล้ว +8

    AMAZING , THANK YOU!

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว

      thanks for watching orenn

  • @andyarthur8857
    @andyarthur8857 3 ปีที่แล้ว +3

    All finished and my paddle 🏓 does not move bro.Tell me someone how to check and configure paddle not move problem.

  • @elionayzuridasilveira4140
    @elionayzuridasilveira4140 4 หลายเดือนก่อน

    I loved so much this tutorial

  • @lollol-tt7xc
    @lollol-tt7xc 3 ปีที่แล้ว

    Great video!
    What do you think about making a mine sweeper game it fits the java practice programs and I really would like to see you making it

  • @socaljusticewarrior558
    @socaljusticewarrior558 3 ปีที่แล้ว

    That was cool. I just wish you had played a longer game of pong

  • @jackadam01
    @jackadam01 9 หลายเดือนก่อน

    Thanks for sharing this video

  • @eliasgonzalez6653
    @eliasgonzalez6653 4 ปีที่แล้ว +2

    I am doing as explained in the keypressed paddle's part and for up and down keys its not working

  • @mehrdadaria8711
    @mehrdadaria8711 ปีที่แล้ว

    First, let me thank you for your awesome videos.
    I just have one problem here. Two players cannot move their paddles simultaneously. Is that addressed?

  • @cruellnat
    @cruellnat 4 ปีที่แล้ว +5

    Hello, thank you for this. It was really nice to follow along. I am interested as in why you didn't use the javaFX instead. :)

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +5

      I haven't made videos on FX yet

    • @cruellnat
      @cruellnat 4 ปีที่แล้ว +2

      @@BroCodez Hahaha, ok... :D I am looking forward to them then!

  • @DarkSpydaIV
    @DarkSpydaIV 2 ปีที่แล้ว

    I did it; I finished the video and completed the program :D

  • @unalysuf
    @unalysuf 2 ปีที่แล้ว

    Thank you so much for your effort

  • @sadikalabonna6981
    @sadikalabonna6981 ปีที่แล้ว

    Thank you so much😊
    From Bangladesh ❤

  • @waleedrafique9479
    @waleedrafique9479 ปีที่แล้ว +2

    My paddles are not moving after pressing up and down key 36:17

  • @Byboby-io1wz
    @Byboby-io1wz ปีที่แล้ว

    you are the most awesome bro to ever exist!!!!!!!!!!!!!!!!!!!

  • @sumiyajaythepro
    @sumiyajaythepro ปีที่แล้ว

    hey bro, i need help, can you give me the code on how to put a score limit to declare the winner

  • @AbdulRahman-uc3bk
    @AbdulRahman-uc3bk 2 ปีที่แล้ว

    Bro .. how can you make the player 1 or player 2 win .... Can u show me the code for that

  • @Dineshgawas64
    @Dineshgawas64 3 ปีที่แล้ว

    Actually i was trying to make tennis game by referring your code that's helping me a lottttt.. but please tell me how can i use players in place of padels?

  • @mishraraut.1036
    @mishraraut.1036 2 ปีที่แล้ว

    Hey bro ! waiting for your new videos 🌺

  • @thibauddubreuil5208
    @thibauddubreuil5208 2 ปีที่แล้ว +1

    Hey ! Thank you very much for this tutorial ! I have an issue with the ball sometimes not moving at all when initializing, it get stuck to the vertical line in the center of the screen, any idea of what the problem could be? Thank you again for all your work :) !

  • @victors8718
    @victors8718 3 ปีที่แล้ว

    You are great bro, thx!

  • @kenkei.mwaniki
    @kenkei.mwaniki 7 หลายเดือนก่อน

    Awesome
    Now to try and replicate with with JavaFX
    I'll keep you posted

  • @gennius9726
    @gennius9726 3 ปีที่แล้ว

    thanks a lot man apreciate it :))

  • @klemn0291
    @klemn0291 5 หลายเดือนก่อน

    Excellent video. Is anyone else getting a bug where the ball almost gets stuck on the paddle if you hit it at an angle like with the top of the paddle. The ball vibrates back and forth on the paddle?

  • @woollyknitteddragon5946
    @woollyknitteddragon5946 3 ปีที่แล้ว +2

    This was really useful and thank you for making this. The only issue I've had is that the ball will sometimes not move (or only move straight up and down meaning I need to restart the game) but I'm assuming I've missed something in the code to do with the random directions so i'll go through and compare.

    • @fenixspider5776
      @fenixspider5776 3 ปีที่แล้ว

      you fixed that?

    • @ПожилаяРЭПтилия-ц5б
      @ПожилаяРЭПтилия-ц5б 2 ปีที่แล้ว

      @@fenixspider5776 same problem, have you found a solution?

    • @yasya_maybe631
      @yasya_maybe631 2 ปีที่แล้ว

      @@ПожилаяРЭПтилия-ц5б ,@FenixSpider, @woollyknitteddragon I think I've found a solution. You may have made the same mistake as me. I try to follow the best practices and all the code related to if statements was enclosed in brackets {}. But you shouldn't do this in the Ball class constructor. Only one line of code pertains to if statements - randomYDirection--;
      setXDirection(randomXDirection*initialSpeed); and setYDirection(randomYDirection*initialSpeed); must be outside the if statement
      it helps me to fix this problem

  • @abhishek-gu6qt
    @abhishek-gu6qt ปีที่แล้ว

    I think you are a favorite student of your physics teacher .!

  • @Morpheye
    @Morpheye 3 ปีที่แล้ว

    Absolutely wonderful! I can experiment with this from here.

  • @samnoob7481
    @samnoob7481 ปีที่แล้ว

    Thank you so much bro❤

  • @manojseenivasan8854
    @manojseenivasan8854 3 ปีที่แล้ว +8

    How did you able to move the paddles before declaring the paddle1.move() ,paddle2.move() in move function

    • @Brandywackyman188
      @Brandywackyman188 3 ปีที่แล้ว +1

      I have a problem where they just teleport to the top or bottom

    • @idioticgamingchaps1087
      @idioticgamingchaps1087 3 ปีที่แล้ว

      @@Brandywackyman188 same, does anyone know how to fix that?

    • @yakovkontaruk5163
      @yakovkontaruk5163 3 ปีที่แล้ว

      @@Brandywackyman188 Same :(

    • @GrizzGaming38
      @GrizzGaming38 2 ปีที่แล้ว

      @@Brandywackyman188 same problem, we’re you ever able to figure out the problem?

  • @Arthur-g5n8q
    @Arthur-g5n8q หลายเดือนก่อน

    Bro you are the best