Java pong game 🏓

  Рет қаралды 282,671

Bro Code

Bro Code

3 жыл бұрын

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.

Пікірлер: 380
@BroCodez
@BroCodez 3 жыл бұрын
//*********************************** *************************** 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 жыл бұрын
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 жыл бұрын
@@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 жыл бұрын
i think you people deserve being paid a lot. this job could shorten lifetime.
@cate01a
@cate01a 3 жыл бұрын
@@elvastaudinger4991 how could coding shorten lifetime?
@ericatalahiban5466
@ericatalahiban5466 3 жыл бұрын
i followed everything but my paddles are not moving :((( great video tho!!! 💛
@ultimatelegoman1279
@ultimatelegoman1279 3 жыл бұрын
This channel is SOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO underrated
@originalhunter8034
@originalhunter8034 2 жыл бұрын
Dak ghax qisek zobbi
@eliasmelesse4998
@eliasmelesse4998 2 жыл бұрын
Yeeeeeeeeeeeeeeesssssssssssssssss
@tanmaydevikar6306
@tanmaydevikar6306 Жыл бұрын
while 0=0: print("You are right")
@xsanity1931
@xsanity1931 Жыл бұрын
True
@nikj1178
@nikj1178 2 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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
@moxeingames1714
@moxeingames1714 3 жыл бұрын
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
@AdrianTregoning
@AdrianTregoning 2 жыл бұрын
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.
@TattedFaceJoey
@TattedFaceJoey 11 ай бұрын
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.
@Robman2314
@Robman2314 3 жыл бұрын
This video is amazing! Easy to understand and follow along!
@anomalous_guy
@anomalous_guy 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.
@rosastrology2961
@rosastrology2961 3 жыл бұрын
Loved the tutorial supper easy to fallow and works perfectly. Thank you keep up I'm a fan.
@krishnaraj3989
@krishnaraj3989 Жыл бұрын
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!
@monwil3296
@monwil3296 3 жыл бұрын
One hour worth so much,confidence builder 👌👌👌. 💯❤️
@Domo22xD
@Domo22xD 2 жыл бұрын
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.
@Dygit
@Dygit 3 жыл бұрын
I think your channel will boom soon
@JohnBuddy
@JohnBuddy Жыл бұрын
Absulotely right! 1 mil soon!
@davidbartholomew7081
@davidbartholomew7081 2 жыл бұрын
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
@adedamolayusuf7018
@adedamolayusuf7018 2 жыл бұрын
Hi, just a new bro love how you posted all of these in-depth parts of python and explaining so well.
@TheCamelBug
@TheCamelBug 2 жыл бұрын
Wow, thank you so much bro for the video. I coded along and created my own version. Keep them coming!
@thibauddubreuil5208
@thibauddubreuil5208 Жыл бұрын
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 :) !
@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
@noah77
@noah77 3 жыл бұрын
You are... amazing!!
@Coco-coco15
@Coco-coco15 2 жыл бұрын
Thank you for all you're doing. BRO CODE FOR LIFE!!!!
@cryswerton-silva
@cryswerton-silva 2 жыл бұрын
Thanks bro, your tutorials are awesome!
@Pation655
@Pation655 2 жыл бұрын
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!
@petersonnormil6799
@petersonnormil6799 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 жыл бұрын
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 жыл бұрын
@@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.
@k15hcm11
@k15hcm11 3 жыл бұрын
Thanks for sharing
@channingpinkerton5284
@channingpinkerton5284 3 жыл бұрын
Thank you for taking the time to do this
@alexandrulolea4631
@alexandrulolea4631 10 ай бұрын
Haven't watched the video yet, but I'm sure it's going to be great! Thank you and keep up the good work!
@justinabraham5642
@justinabraham5642 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 жыл бұрын
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.
@Ryekene
@Ryekene 3 жыл бұрын
This video made my day!!!! Thank you btw
@meetshah4432
@meetshah4432 3 жыл бұрын
Just a small suggestion, do write @Override on the methods which you override, it will become much easier to comprehend stuff for beginners
@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
@sergeyb6071
@sergeyb6071 3 жыл бұрын
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?
@x-factor1386
@x-factor1386 3 жыл бұрын
Thanks a lot, do even more projects like this and share with us. 😁😅
@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
@user-ku9li4hq7v
@user-ku9li4hq7v 8 ай бұрын
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
@mehrdadaria8711
@mehrdadaria8711 11 ай бұрын
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 жыл бұрын
Thanks for the video bro!!!
@kennethrobbins5830
@kennethrobbins5830 2 жыл бұрын
Loved this video Bro!
@israelibarracampos8307
@israelibarracampos8307 3 күн бұрын
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?
@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)
@Morpheye
@Morpheye 2 жыл бұрын
Absolutely wonderful! I can experiment with this from here.
@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?
@odysseaskorelides7897
@odysseaskorelides7897 3 жыл бұрын
You are just awesome Bro...Thenx a Ton
@Auqherus
@Auqherus Жыл бұрын
Great video, as always! :D
@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...
@pranavkulkarni7551
@pranavkulkarni7551 Жыл бұрын
I liked this video a lot. Easy Understanding:)
@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
@sewek1513
@sewek1513 2 жыл бұрын
That one was difficult but also fun. And I actually like playing it :P Thank you!
@socaljusticewarrior558
@socaljusticewarrior558 2 жыл бұрын
That was cool. I just wish you had played a longer game of pong
@merrickmcfarling1795
@merrickmcfarling1795 3 жыл бұрын
I love this channel so much
@crackrokmccaib
@crackrokmccaib 2 жыл бұрын
At 22:40 you could have just change (5/9) to (5.0/9.0) and it works just fine.
@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
@mr.fakeman4718
@mr.fakeman4718 3 жыл бұрын
1:06:18 That background music tho. xd Btw I never watched this awesome Java videos so far. Thank you!
@Philthyyy
@Philthyyy 2 жыл бұрын
Great video! Commenting to help the algorithm.
@orennkimg6851
@orennkimg6851 3 жыл бұрын
AMAZING , THANK YOU!
@BroCodez
@BroCodez 3 жыл бұрын
thanks for watching orenn
@BingoGo2Space
@BingoGo2Space 6 ай бұрын
Love your videos. I wish I can meet you one day Legend. You are a great man.
@woollyknitteddragon5946
@woollyknitteddragon5946 3 жыл бұрын
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
@victors8718
@victors8718 2 жыл бұрын
You are great bro, thx!
@samnoob7481
@samnoob7481 4 ай бұрын
Thank you so much bro❤
@mohammedzakariasamyfarid1907
@mohammedzakariasamyfarid1907 2 жыл бұрын
I have a question please ! How i can practice JAVA , and how did you practice it ?
@akshaymondal1372
@akshaymondal1372 Жыл бұрын
I dont have any words to explain how I glad I am . God bless you 🙇
@SALOOMS
@SALOOMS 3 жыл бұрын
thanks dude ❤ you are amazing (best subscribe for u)
@cruellnat
@cruellnat 3 жыл бұрын
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 3 жыл бұрын
I haven't made videos on FX yet
@cruellnat
@cruellnat 3 жыл бұрын
@@BroCodez Hahaha, ok... :D I am looking forward to them then!
@ludovicbocquet9783
@ludovicbocquet9783 8 ай бұрын
Really nice video, thank you !
@unalysuf
@unalysuf Жыл бұрын
Thank you so much for your effort
@adityavikramkirtania6539
@adityavikramkirtania6539 4 ай бұрын
I loved this video really learnt a lot from this tutorial
@gilantonyborba8163
@gilantonyborba8163 Жыл бұрын
bro! you are just outstanding!!!
@mirzaruzain5378
@mirzaruzain5378 11 ай бұрын
Thanks my bro hope your family healthy and happy
@gennius9726
@gennius9726 2 жыл бұрын
thanks a lot man apreciate it :))
@ahmedyacinetalbi968
@ahmedyacinetalbi968 3 жыл бұрын
man u r the best thnk u soo much ❤
@marybenish9716
@marybenish9716 3 жыл бұрын
So cool!!
@devinlefkowitz9875
@devinlefkowitz9875 Жыл бұрын
Love it!
@sadikalabonna6981
@sadikalabonna6981 10 ай бұрын
Thank you so much😊 From Bangladesh ❤
@dhruvbhatt3099
@dhruvbhatt3099 11 ай бұрын
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?
@michaokonski6223
@michaokonski6223 10 ай бұрын
Great video Bro Code
@werq27
@werq27 8 ай бұрын
Thx, Bro!
@prarabdhabharadwaj4113
@prarabdhabharadwaj4113 3 жыл бұрын
Bro please don't stop making videos
@TimeWrapChronicales
@TimeWrapChronicales 3 жыл бұрын
Hey this video is great can you please put a copy of this code down below please
@jackadam01
@jackadam01 28 күн бұрын
Thanks for sharing this video
@mirwaiskarimi4215
@mirwaiskarimi4215 2 жыл бұрын
You Are Awesome 👌 Bro
@user-mw6jz5gb9u
@user-mw6jz5gb9u 6 ай бұрын
hey bro, i need help, can you give me the code on how to put a score limit to declare the winner
@nero8074
@nero8074 3 жыл бұрын
This is excellent!
@sidra3210
@sidra3210 3 жыл бұрын
I don't understand the code in run()method.what are ns, delta,etc and what they are doing?
@mayannagravante9879
@mayannagravante9879 3 жыл бұрын
Thank u so much 😊
@abhinavmishra7617
@abhinavmishra7617 3 жыл бұрын
great tutorial....the game loop was something that i didn't understand ... where can i learn more about it?
@BroCodez
@BroCodez 3 жыл бұрын
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 3 жыл бұрын
@@BroCodez Sir please tell me that .. the paddel moves with arrow key or not
@foreversleepy4379
@foreversleepy4379 3 жыл бұрын
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.
@gamingwitharyav5611
@gamingwitharyav5611 2 жыл бұрын
extremely underrated channel
@eliasgonzalez6653
@eliasgonzalez6653 3 жыл бұрын
I am doing as explained in the keypressed paddle's part and for up and down keys its not working
@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.
@stephaniepanah1387
@stephaniepanah1387 Жыл бұрын
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 2 ай бұрын
if i want to add a pause by pressing space bar how can it be possible
@manojseenivasan8854
@manojseenivasan8854 3 жыл бұрын
How did you able to move the paddles before declaring the paddle1.move() ,paddle2.move() in move function
@Brandywackyman188
@Brandywackyman188 2 жыл бұрын
I have a problem where they just teleport to the top or bottom
@idioticgamingchaps1087
@idioticgamingchaps1087 2 жыл бұрын
@@Brandywackyman188 same, does anyone know how to fix that?
@yakovkontaruk5163
@yakovkontaruk5163 2 жыл бұрын
@@Brandywackyman188 Same :(
@GrizzGaming38
@GrizzGaming38 Жыл бұрын
@@Brandywackyman188 same problem, we’re you ever able to figure out the problem?
@Byboby-io1wz
@Byboby-io1wz 5 ай бұрын
you are the most awesome bro to ever exist!!!!!!!!!!!!!!!!!!!
@shahedrazavi100
@shahedrazavi100 3 жыл бұрын
Man, you are a hero.
@oumartoure6087
@oumartoure6087 3 жыл бұрын
Great video. Thank you very much . I would like to create an AI player from this code. How can I implement it? Thank you
@ayuyu5066
@ayuyu5066 2 жыл бұрын
AWESOMEEEE LOVED IT
@ManojDas-dt8nl
@ManojDas-dt8nl Жыл бұрын
Thank You So Much Sir 🙏
@dracula8432
@dracula8432 2 жыл бұрын
is there anyway that i can make the ball blink after it touches the left and right boundaries
@elielberra2867
@elielberra2867 2 жыл бұрын
Hey Bro! Thanks a lot for all the effor put into this videos, they are amazing!! I was wondering if you could give me a hand with this part of the code, since I've been reading the doc but I can't get to understand what it is that you are doing: public void paint(Graphics g) { image = createImage(getWidth(), getHeight()); graphics = image.getGraphics(); draw(graphics); g.drawImage(image, 0, 0, this); } why are you passing graphics as a parameter to draw? whiy are you drawing the image inside the method drawImage when you have already drawn the graphics before? If you could please explain the general logic of what it its that this piece of code is doing it would be great. Thanks!!! :)
@nikolatesla399
@nikolatesla399 Жыл бұрын
Now we have chatgpt ....
What are data structures and algorithms? 📈
2:21
Bro Code
Рет қаралды 175 М.
How to train simple AIs to balance a double pendulum
24:59
Pezzza's Work
Рет қаралды 41 М.
UFC 302 : Махачев VS Порье
02:54
Setanta Sports UFC
Рет қаралды 1,3 МЛН
1❤️
00:20
すしらーめん《りく》
Рет қаралды 33 МЛН
CAN YOU HELP ME? (ROAD TO 100 MLN!) #shorts
00:26
PANDA BOI
Рет қаралды 36 МЛН
Шокирующая Речь Выпускника 😳📽️@CarrolltonTexas
00:43
Глеб Рандалайнен
Рет қаралды 11 МЛН
Java snake game 🐍
43:30
Bro Code
Рет қаралды 1,4 МЛН
Java tic tac toe game ⭕
30:00
Bro Code
Рет қаралды 278 М.
The Blazor Competitor is Here!
15:08
Nick Chapsas
Рет қаралды 5 М.
A New Beginning - Episode #01 - Java Game Development Tutorial
27:39
Kaarin Gaming
Рет қаралды 254 М.
Optionals In Java - Simple Tutorial
15:53
Coding with John
Рет қаралды 195 М.
Java quiz game ⌛
1:07:22
Bro Code
Рет қаралды 115 М.
Getting The Game Loop Right
8:27
Vittorio Romeo
Рет қаралды 27 М.
Java calculator app 🖩
34:36
Bro Code
Рет қаралды 398 М.
The Traveling Salesman Problem: When Good Enough Beats Perfect
30:27
Learn Java in 14 Minutes (seriously)
14:00
Alex Lee
Рет қаралды 4,6 МЛН
wireless switch without wires part 6
0:49
DailyTech
Рет қаралды 954 М.
iPhone 12 socket cleaning #fixit
0:30
Tamar DB (mt)
Рет қаралды 18 МЛН
cool watercooled mobile phone radiator #tech #cooler #ytfeed
0:14
Stark Edition
Рет қаралды 7 МЛН
Где раздвижные смартфоны ?
0:49
Не шарю!
Рет қаралды 424 М.
POCO F6 PRO - ЛУЧШИЙ POCO НА ДАННЫЙ МОМЕНТ!
18:51
Топ-3 суперкрутых ПК из CompShop
1:00
CompShop Shorts
Рет қаралды 460 М.
С Какой Высоты Разобьётся NOKIA3310 ?!😳
0:43