Coding Challenge #67: Pong!


In this challenge, I attempt (emphasis on the word “attempt”) to program the classic video game Pong in Processing (Java). This also marks the return of the timer to help me keep track of time! Now I remember why I got rid of the timer in the first place, oops.


Links discussed in this video:
🔗Pong Game:
🔗Paddle angles drawing:
🔗Polar Coordinates Video:

Video editing by Mathieu Blanchette.

🎥Coding Challenges:
🎥Intro to Programming:

🔗 p5.js:
🔗 Processing:

📄 Code of Conduct:
🌐Help us caption and translate:
🚩Suggest Topics:
👾Share your contribution:


Xem thêm bài viết khác:


  1. 51:58 I don't think he fixed the bug where the ball gets stuck behind the paddle. I tried it out and the ball got stuck at a steeper angle. He only tried one angle, and didn't test it again.

  2. What I love about these videos is that Daniel is not afraid to make a mistake on the video. He actually laughs about it, learns from it, then figures out the workaround on his feet. Brilliant dude. His videos really encourage me to not be afraid to explore and make a mistake, and when I do (which is a lot right now…:), I'm learning to calm down, not give up, and find the answer (most of the time on Google, lol) His videos are so refreshing, and so much fun, and I've learned so much from him.

  3. I'm writing the code for pong along with Daniel, and pause each segment. I try to write the code myself and check if both our minds are alike. Until 22:30 everything was fine. Ah, I'm loving it. The spaghetti is real.

  4. Screaming for minutes that you don't use the paddle parameter which specifies whether it's a left or right paddle in the collision function. Anyway nice video as always

  5. Tks, I customized the code and put AI

  6. void checkPaddle( Paddle p, int dir)
    // should multiply with the both sides of the relations therefore it works for both right movin (1) and left moving( -1) Pucks
    if ( dir*xspeed > 0 && dir*(x+dir*r) > dir*(p.x – dir*p.w/2) )
    if (y < p.y+p.h/2 && y > p.y-p.h/2)
    x = x – dir*r;
    xspeed *= -1;

  7. What a great guy, thank you for this fantastic tutorial/guidance on how to program pong. Thank you once again!

  8. i tried making a speedY & speedX for the ball then made a copy of mouseY that will update to be mouseY every two seconds

    then if the ball touched the paddle and the copy of mouseY was higher than the copy then the ball would go down speedY would be a positive

    number (y=y+speedY) if lower than the copy the ball would go up speedY would be negative

    if the ball touched the edges speedY would =speedY * -1 if touching any paddle speedX= speedX * -1 .

    i like the way Dan did it though as it seems to be smoother i also learned about the the released key function

    👊👊 the more you know
    if you would like to see the version of pong i made then you can copy paste this on processing .
    still has some bugs though
    kind of like the bugs in the video that i forgot to patch up.

    float x; float speedx=-4 ;

    float y; float speedy=0 ;

    float yo; float py ;

    float chance ; float timer ;

    float sc ; float sc2 ;

    float diff = 470 ;

    float d1; float d2=255; float d3; float di ;

    void setup (){


    size (900,600);


    x=width/2 ;



    void opon (){

    background(0) ;


    stroke (14,219,4,200);

    line (width/2,0,width/2,height);


    rect (x,y,20,20);

    x=x+speedx ;

    y=y+speedy ;

    if (y<0||y>height-20){speedy=speedy*-1;} //bouce off t b

    if (x>width){x=width/2 ;y=height/2;speedy=0;sc2++;}

    if (x<0){x=width/2 ;y=height/2;speedy=0;sc++;}// reset

    if (x<0){sc=sc+1;} // score

    if (x>width){sc2=sc2+1;} // score


    if (x<60 && mouseY>py&&y<mouseY+30 && y>mouseY-20 &&x>40){speedy=4; speedx=speedx*-1;} // down bounce

    if (x<60 && mouseY<py&&y<mouseY+30 && y>mouseY-20 &&x>40){speedy=-4; speedx=speedx*-1;} // up bounce

    if (x<60 && mouseY-py==0 && y > mouseY-30 && y < mouseY+45 ){speedx=speedx*-1;} // bounce straight


    if (x>width-60 &&y<yo+60 && y>yo &&x>40){speedx=speedx*-1;} // bounce op //



    if( timer >2 ){timer=0 ; py= mouseY;}

    rect (40,mouseY-20,20,60);


    rect (width-60,yo,20,60);

    chance = random (500);

    if (chance > diff){yo=y-25;}else{yo=yo+random(-5,10); };

    fill (0,200,0);

    // text((x-60)/10,100,100);

    text(sc ,width-50,height-50); text(sc2,50,height-50);



    void draw (){

    textSize (15);


    rect (90,30,25,30); rect (90+50,30,25,30); rect (90+100,30,25,30); rect (90+150,30,30,30);


    text (1,100,50); if( mousePressed&& mouseX>90 && mouseX<90+25 && mouseY<120){ diff=480 ;d1=255;d2=0;d3=0;di=0;}


    text (2,150,50); if(mousePressed&& mouseX>140 && mouseX<140+25 && mouseY<120){diff=470 ;d1=0;d2=255;d3=0;di=0;}


    text (3,200,50); if(mousePressed&& mouseX>190 && mouseX<190+25 && mouseY<120){diff=425 ;d1=0;d2=0;d3=255;di=0;}


    text (100,240,50); if(mousePressed&& mouseX>240 && mouseX<265 && mouseY<120){diff=0 ;d1=0;d2=0;d3=0;di=255;}


  9. you could have used inheritance here…the left and the right paddle could be the child classes and a paddle class be the parent this way you could have done it easier….

  10. I don't know a anything about processing but I have programmed the Arduino so I wanted to ask if instead of making the separate keyRealeased function couldn't you just put a while loop instead of an if statement so that when the key is pressed the paddle will keep on moving up or down. I'm talking about 18:07

  11. Excellent video. I have a question I can use processing to do a simulation of electromagnetism, like a simulation or something?

  12. I'm brand new to coding… this was great fun and I can see your thought process going through this… I'm from a maths background and I wanted to see the fun side of coding… this was it!

  13. i’m trying to follow this, got to around 24:10, and for some reason it is now goving me “unexpected token” errors for everything that starts with left., right., and puck.

    do you have any ideas as to why that is?

  14. HI everyone! I also did pong on my youtube channel! I did it in Java with Eclipse, however. Go check it out to help me out! Just click on me lol or click the link:
    Thank you. 🙂

  15. Hey! I'm currently making pong myself, however I have ran into an issue and was wondering if you could help. So basically, whenever I press more than one key at once (lets just say one player presses w to go up and the other player presses j to go down), it only allows one to move at a time.

  16. At 43:10, laughed really hard because I thought the ding was from the "ding.mp3" that you were doing at first! That timing couldn't have been better! Thought you were testing to make sure that sound works!

  17. Great video. There a few other youtube versions of 'pong' mostly in the browser with js. Your version is great because you are so passionate. Keep it up!

  18. Just as x and y can be zero resulting in a ball that doesn't move, so an angle of 90 or 270 will result in a puck that just bounces up and down and doesn't approach the bats. Should use vectors too 👍

  19. Hi, I'm a total beginner in Processing and I really need help. Could someone please explain me what "ychange" actually means? I've got a headache trying to do this game, the man is too fast😅😂It literally took me a few days because it was too much and now I'm trying to understand what this whole code means so if you're willing to, then please, help me to answer that question😅😊

    (Btw this video is truly helpful and funny at the same time (Now I'm curious to know the man's IQ lol)! Thank you for sharing it with the rest of the world! 🙂 )


Please enter your comment!
Please enter your name here