🔥Pong Game with C++ and Raylib - Beginner Tutorial

  Рет қаралды 41,505

Programming With Nick

Programming With Nick

Күн бұрын

Pong Game with C++ and Raylib
In this tutorial I am going to show you how to make Pong, a simple but very addictive game where the player controls the right paddle and the computer the left one. We are going to build this game using C++ and the raylib library. At first we are going to build a simple black and white version, just like the original pong of 1973, but at the end of the video we are going to add colors to it, to make it look better.
Although Pong is a very simple game, it covers a lot of the aspects of computer game programming, like movement, control, collision detection, scoring, artificial intelligence and so on. If you learn how to program Pong you will be able to program a lot of other games as well.
Starter Template: github.com/educ8s/Raylib-CPP-...
Code: github.com/educ8s/Cpp-Pong-Ga...
⏳ Timestamps
0:00 Intro
2:40 Create a blank screen & the Game Loop
8:14 Draw the paddles & the ball
14:21 Move the ball around
18:53 Check for collisions with the edges
21:51 Move the player paddle
26:53 Move the CPU paddle with AI
32:11 Check for collisions
34:27 Add scoring
38:47 Add colors

Пікірлер: 76
@programmingwithnick
@programmingwithnick Жыл бұрын
I hope you took away lots from this video. Let me know below! PS. Check out my Android Game called Quiz of Knowledge. I am sure you are going to like it. bit.ly/QuizOfKnowledge
@kausarfatima1318
@kausarfatima1318 Жыл бұрын
Is it in C++?
@Zivvv187
@Zivvv187 10 ай бұрын
Wow! I just wanted to say THANK YOU for making these Raylib tutorials. You are excellent at describing WHY we write the code (the most crucial aspect of learning), both while you code but also before we start to code when you break down what we are gonna do. Sometimes I loose interest in a tutorial when the person is not explaining and or has a pedagogical way of explaining. But I've been glued to your Raylib videos! Please don't stop doing Raylib tutorials, you are the best I've seen on KZbin regarding c++ game programming (and I really mean it)!!
@programmingwithnick
@programmingwithnick 10 ай бұрын
Thank you very much for your kind words! It means a lot. Messages like yours, keep me motivated!
@D3ss3rtTV
@D3ss3rtTV 24 күн бұрын
If I would've found your channel earlier, I would be a game dev by now, thanks for all the hard work you put into these videos.
@syedshow811
@syedshow811 3 ай бұрын
your contents are far better than the contents in paid Udemy courses!
@programmingwithnick
@programmingwithnick 3 ай бұрын
Thank you very much for the feedback. I wan to create the best possible free content available. It seems I am on the right track.
@sobottrachhuth75
@sobottrachhuth75 11 ай бұрын
I really like the way you break everything down, it really helps with understanding what's going on. I hope you will continue to make more contents. Thank you so much!
@charlesg.smithjr.3677
@charlesg.smithjr.3677 8 ай бұрын
I followed your step by step tutorial on how to set up raylib in Visual Studio 2022. You made it super easy to follow along with you awesome job.
@dp2120
@dp2120 3 ай бұрын
This was incredible. Thank you so much!
@TheSelfUnemployed
@TheSelfUnemployed 28 күн бұрын
Incredible tutorial! I just started programming and chose c++ as my first language. Ive done many tutorials even another pong video but it was convoluted and didnt explain what the code did or how to break it down into small problems. Thank you so much for this knowledge! On to Snake now!
@chalkypj
@chalkypj Жыл бұрын
Thank you for such a fantastic tutorial. I have taught myself python and found you via your pong pygame video. I spent time a couple of years ago trying to teach myself C++. This tutorial has now whetted my appetite to try and continue this journey. I look forward to what you post in the future.
@programmingwithnick
@programmingwithnick Жыл бұрын
Glad to hear that you found the tutorial helpful and that it has inspired you to continue learning programming! Learning by building games can definitely be a fun and rewarding way to learn a new programming language. By the way, I'm currently working on a new video tutorial for creating a Snake game in C++, which I think you might find interesting. Stay tuned for that, and let me know if you have any questions or need any help along the way!
@ManulF-rm8em
@ManulF-rm8em 4 ай бұрын
Great Tutorial. It helped me A LOT!
@AaliJahBaig
@AaliJahBaig 11 ай бұрын
Amazing video dude! thank you so much for making this.
@MortySmith-ji2fx
@MortySmith-ji2fx 7 ай бұрын
Awesome tutorial!!! THANKS A LOT!!!
@lomvil
@lomvil 6 сағат бұрын
It's awesome video, thank you!
@nokia_n-gage
@nokia_n-gage 7 ай бұрын
Thank you for a super tutorial!
@davidefarona
@davidefarona Ай бұрын
Thanks this is gold, keep it up plz
@akaa3144
@akaa3144 4 ай бұрын
Hey man, I wanted to thank you for this tutorial, I've been learning a lot with it! I'm definitely looking at you snake tutorial next! As well, this type of tutorial motivates me more, in becoming a c++ dev!
@programmingwithnick
@programmingwithnick 4 ай бұрын
You can do it. Watch the snake game tutorial, next the Tetris game tutorial, and next the Space Invaders tutorial and you will able to build simple 2d games on your own.
@akaa3144
@akaa3144 4 ай бұрын
@@programmingwithnick Will do, thank you!
@Tims_Projects
@Tims_Projects Жыл бұрын
Loved it. 👍
@meminhofuny
@meminhofuny 8 ай бұрын
awesome video, God bless you for your channel
@blazexy5657
@blazexy5657 9 ай бұрын
Man this is really helpful can you do more tutorial in C++ like making enemies and also doing 3D game dev stuff
@SashaIraq
@SashaIraq Жыл бұрын
Super! Thanks You for the lesson.
@programmingwithnick
@programmingwithnick Жыл бұрын
I am glad you like it!
@diegoaredes2721
@diegoaredes2721 4 ай бұрын
Awesome video
@Bbdu75yg
@Bbdu75yg Жыл бұрын
Beautiful ❤
@aaabbbccc899
@aaabbbccc899 4 ай бұрын
THANKS, i made my first game!
@arfihussain6172
@arfihussain6172 Жыл бұрын
Awesome tutorial 👍
@programmingwithnick
@programmingwithnick Жыл бұрын
Thank you! Cheers!
@staymotivated628
@staymotivated628 Жыл бұрын
Legendary tutorial
@programmingwithnick
@programmingwithnick Жыл бұрын
;-) Thanks for your support!
@MinerBruh
@MinerBruh Жыл бұрын
Hey Nick I'm really excited for the next tutorial as this one is very well explained and I understood it easily. Keep up the good work (Επίσης είμαι και εγώ Έλληνας :))
@programmingwithnick
@programmingwithnick Жыл бұрын
Hey, thanks for the comment! I am really excited for the next video as well! It will be my best so far! Γεια σου πατρίδα, αν φτιάξεις κάτι καλό να μου το στείλεις να το δω!
@MinerBruh
@MinerBruh Жыл бұрын
@@programmingwithnick I will for sure!
@OktatOnline
@OktatOnline Жыл бұрын
Let me just point out that in the beginning you show 1 big thing broken down into 9 smaller things to showcase the divide & concquer method. Let me also say that the video is made up of 9 parts of actual coding. :D Satisfying.
@programmingwithnick
@programmingwithnick Жыл бұрын
Yes, that was not a coincidence ;-)
@jefftamatthew
@jefftamatthew 2 ай бұрын
Hi Nick, loved your tutorial videos. I want to ask, is there a way to make all of these game projects without needing to delete the main.cpp source code and rewrite it all and instead make a new file and write the code there? Thank you in advanced!
@AlaaAreesPhoenix
@AlaaAreesPhoenix Жыл бұрын
Thanks very much this is one of the best tutorials for beginners about both raylib and oop abilities in c++ , thank you a lot sir💙 But just a small question , do you need any extra extentions to run this on vs code? (Execpt the c++ extension of course) And using codeblocks will do the same work right?
@programmingwithnick
@programmingwithnick Жыл бұрын
Glad it was helpful!
@MoviestarsEnglish
@MoviestarsEnglish Жыл бұрын
Wow, Excellent tutorial! I loved it! You have a new subscriber! Would it very difficult to do the same Pong Game in Unreal Engine 5?
@programmingwithnick
@programmingwithnick Жыл бұрын
Thanks for the sub! I have no experience with Unreal Engine so I can't help you with that. Sorry!
@MoviestarsEnglish
@MoviestarsEnglish Жыл бұрын
Hi Nick, no problem! Thank you so much for your excellent videos. Have a nice day!
@evertgoran
@evertgoran Жыл бұрын
Thank you for a great tutorial! One question though, and my question might be off but, delta time was not used for the movement of the ball nor the movement of the paddles. Is this because you know that your computer will be able to run the pong game at 60 FPS at all times? If you were to make the game available for anyone, would you then use delta time for the movement?
@programmingwithnick
@programmingwithnick Жыл бұрын
Yes, since this is a super simple game, very computer can run it fast enough. This makes things easy. If I remove the fps limit, my computer can run the game at 5000 fps. Check the latest video on my channel for more info.
@pointshootgo
@pointshootgo 20 күн бұрын
for some reason whenever i run the program the ball keeps hitting an invis wall at x being 781 i have no clue what the reason could be because to me it looks like i did everything like the video showed
@manuelgarciagarcia2501
@manuelgarciagarcia2501 Жыл бұрын
Fantastico tutorial,es tan bueno que hasta yo que no se ingles he podido seguirlo sin problemas.Sigue haciendo mas video de raylib que son muy buenos. No se si te molesta que publique en español pero me es mas comodo que usar el traductor de google,pero si hay algun problema puedo usar el traductor.
@programmingwithnick
@programmingwithnick Жыл бұрын
¡Muchas gracias por tus palabras! Me alegra saber que pudiste seguir el tutorial a pesar de no hablar inglés. Continuaré haciendo más videos sobre raylib y trataré de hacerlos lo más claros y fáciles de entender posible. ¡Gracias por seguirme!
@manuelgarciagarcia2501
@manuelgarciagarcia2501 Жыл бұрын
@@programmingwithnick Podrias en proximos videos,hacer un juego con dos niveles y ver como se puede pasar de un nivel a otro.Y tambien me gustaria saber como pausar el juego
@RomanWaves
@RomanWaves 3 ай бұрын
Thanks a lot :) one question ... there is a weird edge case for the collision, where the ball gets stuck in the paddle and is thrown back and forth. It happens when you catch the ball with the edge of the paddle. Is there a way around this ? Looked in documentation and web but wasnt able to find a solution
@dahoppin1008
@dahoppin1008 Ай бұрын
Did you manage to fix it?
@HoangHarry
@HoangHarry Жыл бұрын
may i ask, if i compile the project using your makefile, will i have to ship the game with all the assets and .dll files?
@programmingwithnick
@programmingwithnick Жыл бұрын
No you just have to ship the executable!
@R2Sam
@R2Sam Жыл бұрын
Any plans on doing some sort of networking with raylib, always wanted to but never knew where to start
@programmingwithnick
@programmingwithnick Жыл бұрын
Thanks for the idea, I will look into it.
@dipcrew7337
@dipcrew7337 Жыл бұрын
εισαι ωραιος
@programmingwithnick
@programmingwithnick Жыл бұрын
Thanks, cheers!
@ledschmidt1441
@ledschmidt1441 3 ай бұрын
This is terrific!!! I'm 90% into it and just have the players paddle moving inside the screen, however I seem to have TWO player paddles as one does move up and down, and another is stationary in the middle position???? Can't find the code issue causing this? Thanks!!
@junaidsultanxyz
@junaidsultanxyz 2 ай бұрын
class Player { public: float x , y; float speed; float height, width; KeyboardKey key_up, key_down; Rectangle rec = {x, y, width, height}; void draw() { DrawRectangle(x, y, width, height, mainTheme[3]); } void update() { if (IsKeyDown(key_up)) { if (y > 10) // moving only if its within the field { y -= speed; } } if (IsKeyDown(key_down)) { if (y + height < display_height - 10) { y += speed; } } } }; class Computer : public Player{ public: void update(float ball_y, float ball_x) { if ((ball_y < y + height/2 && ball_x > display_width/2) || (ball_x > display_width/4.5 && ball_x < display_width/2.6)) // extra condition for more interactive bot { if (y > 10) // moving only if its within the field { y -= speed; } } if ((ball_y > y + height/2 && ball_x > display_width/2)|| (ball_x > 20 && ball_x < display_width/5)) { if (y + height < display_height - 10) { y += speed; } } } };
@junaidsultanxyz
@junaidsultanxyz 2 ай бұрын
i hope this helps, its a better version of the one in vid
@junaidsultanxyz
@junaidsultanxyz 2 ай бұрын
i just set it so that it can only move within the bounds
@rubialugattimoreira1978
@rubialugattimoreira1978 Жыл бұрын
👍❤️👏👏
@sarkkk2134
@sarkkk2134 3 ай бұрын
how should we set-up raylib library before using it in this project ?
@programmingwithnick
@programmingwithnick 3 ай бұрын
Check this video: kzbin.info/www/bejne/hpKklImhas-Impo
@sarkkk2134
@sarkkk2134 3 ай бұрын
@@programmingwithnick ok thanks
@sarkkk2134
@sarkkk2134 3 ай бұрын
@@programmingwithnick hello I just completed creating the whole game, now I decided to create something more and male a menu screen which has start and exit buttons, so i came across raygui i wanted to ask how should I link raygui in the starter raylib template folder structure taken from git
@ZainAhmad-jl4vt
@ZainAhmad-jl4vt 8 ай бұрын
I did make Pong with olc PixelGameEngine
@DanielGonzalez-xq7sb
@DanielGonzalez-xq7sb Жыл бұрын
The big question, how can I win a score to cpu_player ? Because cpu_player never loose
@programmingwithnick
@programmingwithnick Жыл бұрын
You can decrease the cpu speed variable, increase the ball.speed variable or alter the AI algrotithm to move only when the ball is its part of the screen for example. There are many ways to achieve it.
@ankanray962
@ankanray962 6 ай бұрын
Why is ball.Update called before ball.draw?
@treyabolicum
@treyabolicum Ай бұрын
because code gets executed from top to bottom, logically it makes more sense to update the position before drawing the ball on the screen again, right? :)
@rutgerkanarek1883
@rutgerkanarek1883 Жыл бұрын
💪 𝔭𝔯𝔬𝔪𝔬𝔰𝔪
@dimasbajuri
@dimasbajuri Жыл бұрын
Your tutorial was excellent! I loved how you broke down the steps and provided clear explanations. btw, you have an instagram?
@programmingwithnick
@programmingwithnick Жыл бұрын
Thank you very much for your comment and the nice words. I am glad that you liked the video and the structure. I don't use social media, they distract me from the work, and believe me producing videos like this require a huge amount of time. If you want to see updates from me on the projects I am building check my community tab here on KZbin.
C++ Snake game using raylib - Beginner Tutorial 🐍 (OOP)
1:13:43
Programming With Nick
Рет қаралды 39 М.
Should I have used Unity instead of Raylib for my Indie game?
10:11
Lingon Studios
Рет қаралды 29 М.
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 58 МЛН
La revancha 😱
00:55
Juan De Dios Pantoja 2
Рет қаралды 31 МЛН
Заметили?
00:11
Double Bubble
Рет қаралды 3,5 МЛН
Making a Game With C++ and SDL2
8:14
PolyMars
Рет қаралды 1,6 МЛН
What is the Raylib library good for ?
10:50
ThatOSDev
Рет қаралды 1 М.
Creating Tetris in C++ with raylib - Beginner Tutorial (OOP)
2:12:09
Programming With Nick
Рет қаралды 75 М.
Making a Game With C++ and SDL2
5:34
Goodgis
Рет қаралды 582 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 280 М.
How C++ took a turn for the worse
5:03
Code Persist
Рет қаралды 253 М.
One year of my C++ SFML journey
5:39
Snapi
Рет қаралды 389 М.
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 58 МЛН