Java pong game 🏓

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ก.ค. 2020
  • 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.
  • วิทยาศาสตร์และเทคโนโลยี

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

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

    //***********************************
    ***************************
    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 3 ปีที่แล้ว +20

      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 3 ปีที่แล้ว +23

      @@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 3 ปีที่แล้ว +3

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

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

      @@elvastaudinger4991 how could coding shorten lifetime?

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

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

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

    This channel is SOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO underrated

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

    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!

  • @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.

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

    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.

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

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

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

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

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

  • @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.

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

  • @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.

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

    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

  • @Domo22xD
    @Domo22xD 2 ปีที่แล้ว +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.

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

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

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

    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.

  • @krishnaraj3989
    @krishnaraj3989 ปีที่แล้ว +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!

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

    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!

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

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

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

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

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

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

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

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

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

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

    Thanks for sharing

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

    Thank you for taking the time to do this

  • @thibauddubreuil5208
    @thibauddubreuil5208 ปีที่แล้ว +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 :) !

  • @x-factor1386
    @x-factor1386 3 ปีที่แล้ว +1

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

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

    Thanks bro, your tutorials are awesome!

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

    Absolutely wonderful! I can experiment with this from here.

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

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

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

    You are... amazing!!

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

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

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

    I liked this video a lot. Easy Understanding:)

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

    You are just awesome Bro...Thenx a Ton

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

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

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

    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

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

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

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

    Dear Bro, thanks!
    Is it true that in GamePanel class checkCollision() method if we multiply ball.xVelocity by -1 for both cases the program runs faster? :D 53:02
    Also then you don't need to add the negative for paddle2 so it's simpler
    ball.setXDirection(ball.xVelocity); at 55:42

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

    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

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

    Thank you for the video, I bet I will be able to do better thanks to your programm)

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

    I loved this video really learnt a lot from this tutorial

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

    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?

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

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

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

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

  • @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 2 ปีที่แล้ว

      where is the code for game frame?

  • @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...

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

    I think your channel will boom soon

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

      Absulotely right! 1 mil soon!

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

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

    Thanks for the video bro!!!

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

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

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

    Great video! Commenting to help the algorithm.

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

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

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

    Hi, so when you create a class it brings up a screen that gives a few options to configure or customize the class to your specifications. But I'm using version JDK 18 so it only brings up a drop down menu with very little options to configure or customize it. How do I change it to give me the pop up screen to adjusting settings for the class.

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

    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?

  • @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!

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

    Thanks my bro hope your family healthy and happy

  • @user-ku9li4hq7v
    @user-ku9li4hq7v 9 หลายเดือนก่อน

    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

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

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

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

    Thank you for making such great tutorials!
    I had one question, I'm unsure it's lag from my computer or the capacity of the script but when both paddles are pressed at the same time one will get stuck. Is there a way to allow both players to move their paddles at the same time smoothly?

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

      You may have missed at 40:08 where Bro corrects himself and establishes the "move()" into the paddles. This allows the paddles to move smoothley. I was having the same issue you were having, but once I got to this point and used paddle1.move(); and paddle2.move(); it made the movement much better, and allowed movement of both paddles at the same time. Hopefully this helped.

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

    I have a question please ! How i can practice JAVA , and how did you practice it ?

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

    Thank you so much for your effort

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

    that's explain a lot ! :D for me - begginer ;) i am trying to add to game some "menu bar" any tips? for now if or menu works or game ;D not togheter

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

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

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

    Really nice video, thank you !

  • @user-mw6jz5gb9u
    @user-mw6jz5gb9u 7 หลายเดือนก่อน

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

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

    Thank you so much bro❤

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

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

  • @abpatils69
    @abpatils69 9 หลายเดือนก่อน +1

    How to get that output screen of the pingpong game because i didn't get that screen.... any settings is there ?? Only I get the console with the score

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

    Thank you so much😊
    From Bangladesh ❤

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

    why we set the the gameFrame background to black but not the JPanel , and how does the JPanel changes to black color ?

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

    AMAZING , THANK YOU!

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

      thanks for watching orenn

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

    It's doubt : Is it possible to set key listener for both paddles simultaneously like w,a for first paddle and up,down key for second paddle?

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

    Thanks for sharing this video

  • @pavanimogalla2855
    @pavanimogalla2855 3 หลายเดือนก่อน +1

    Can you say the installation of eclipse , by running the code it is showing like error occurred during the installation of boot layer

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

    is there anyway that i can make the ball blink after it touches the left and right boundaries

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

    bro! you are just outstanding!!!

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

    And this can be easily tricked if you place paddles in direction of last bounce... any solutions with randoming direction?

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

    I've similar project to do but ball has to obey gravity rules but i could not implement this according to time. Such as 1/2gt^2 rule. How can i rule the t here. Please help :)

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

    thanks a lot man apreciate it :))

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

    thanks dude ❤ you are amazing (best subscribe for u)

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

    plz @Bro Code how can i controlle the paddle1 or 2 from the keyboard

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

    Great video. Thank you very much . I would like to create an AI player from this code. How can I implement it? Thank you

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

    I love this channel so much

  • @petersonnormil6799
    @petersonnormil6799 3 ปีที่แล้ว +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  3 ปีที่แล้ว +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 ปีที่แล้ว

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

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

    Loved this video Bro!

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

    Great video, as always! :D

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

    You are great bro, thx!

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

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

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

    man u r the best thnk u soo much ❤

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

    Thx, Bro!

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

    Thank u so much 😊

  • @Alexander007A
    @Alexander007A 3 ปีที่แล้ว +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 💖❤️

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

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

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

    Smart man separating his code 👌 clean and neat 👌

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

      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

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

    Bro please don't stop making videos

  • @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 2 ปีที่แล้ว

      you fixed that?

    • @user-uq6ss2lz8t
      @user-uq6ss2lz8t 2 ปีที่แล้ว

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

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

      @@user-uq6ss2lz8t ,@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

  • @ManojDas-dt8nl
    @ManojDas-dt8nl ปีที่แล้ว

    Thank You So Much Sir 🙏

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

    This guy is just a hope🥰

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

    mine is giving me erros after following every step. am using eclipse 2022-03. does that affect

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

    I can’t get past the first few steps because I keep getting an error message saying “Java.Awt is not accessible” I can’t import any packages. Can you please help me fix this? I’m really trying to learn how to code it is my DREAM to work as a software coder and I can’t learn if I don’t know how to fix an error. Please help

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

    this is very nice most of it works but the KeyAdapter doesnt work, i make sure i spelled it right and everything it says "KeyAdapter cannot be resolved to a type". any solutions?