C++ Tutorial 21 - Simple Pong Game (Part 3)

  Рет қаралды 102,866

NVitanovic

NVitanovic

Күн бұрын

Пікірлер
@reziik6904
@reziik6904 8 жыл бұрын
Love your tutorials! It would be really cool if you continued the series in something like unreal engine and continue making simple games but with basic graphics so we have better idea of how to go about making a real game :) Thanks!
@DogeCharger
@DogeCharger 4 жыл бұрын
Thanks for this tutorial! By the way, if anyone wants to get rid of the flickering, the main cause of it is using the "cls" command in draw. It's pretty tedious this way since it forces the screen blank and causes significant I/O delay. Using this solution eliminates the flickering almost entirely! void clearScreen() // Use Direct implementation of "cls" to clear screen without flickering! { HANDLE hOut; COORD Position; hOut = GetStdHandle(STD_OUTPUT_HANDLE); Position.X = 0; Position.Y = 0; SetConsoleCursorPosition(hOut, Position); }
@cheekybiscuit5742
@cheekybiscuit5742 2 жыл бұрын
where do i place this code in the script, thanks ?
@tomewa2451
@tomewa2451 2 жыл бұрын
Yes. Where do I place it?
@doron910
@doron910 3 жыл бұрын
Yo Thank you!!! I'm a beginner Why should you have the player and the ball objects as dynamic "heap" memory" actually? An explantion would be really interesting.
@CoolDude60874
@CoolDude60874 9 жыл бұрын
Thank you again! You are like teacher,that helps alot when you show how that works :) Keep it up!
@qwerty11111122
@qwerty11111122 9 жыл бұрын
Ah, thank you so much! It's nice to to see a pong game tutorial online where I can learn the graphics separately from the OOP.
@RainbowSheep_was_taken
@RainbowSheep_was_taken 5 жыл бұрын
charmap was the best thing that I've ever learned before thank you very much
@robmarvinzcajayon2639
@robmarvinzcajayon2639 8 жыл бұрын
tried to run the program but there's an error - "cGameManger has no member named draw"
@shedexqwerasd1299
@shedexqwerasd1299 9 жыл бұрын
Nice tutorial, well done! But there is one thing i didnt understand, why do u use pointers on the ball and the players ?
@NVitanovic
@NVitanovic 9 жыл бұрын
+Shedex QWERASD So I can initialize them when the constructor of the GameManager class is called, and also in order for us to be able to use the ScoreUp function. It could have been done without them, but practice is always good, this is a 21st tutorial so I use some concepts that you have learned before in order for you to practice.
@shedexqwerasd1299
@shedexqwerasd1299 9 жыл бұрын
+NVitanovic okay, thank you :D
@yifei_yin
@yifei_yin 8 жыл бұрын
I like the way you making video, it is extremely helpful! Looking forward your next video!
@eslamabdelnaeem8047
@eslamabdelnaeem8047 5 жыл бұрын
I have just ended my c++ and oop course , should I start to creat a game like this as a training course. Or should I learn some thing else?
@yogihendrawan3991
@yogihendrawan3991 4 жыл бұрын
Thank you again :) I really really enjoy it to make and play the game
@ratchetclan3
@ratchetclan3 9 жыл бұрын
Why did the ball go straight at 25:25 instead of reflecting at an angle?
@NVitanovic
@NVitanovic 9 жыл бұрын
+Ryan Conway (Surreali) Because the bounce direction is randomly chosen. The logic for the bouncing should be more complicated, but I've tried to simplify it more in order for the game to be simple enough and to fit the tutorial in 3 videos.
@АндрейКороховой-т4о
@АндрейКороховой-т4о 3 жыл бұрын
Thank you very much for the lesson, I was glad to learn something new, because programming in Ukraine is poorly taught. And the term paper somehow needs to be done))) Thanks again, good luck in life and further steps ...
@Outreal1
@Outreal1 Жыл бұрын
Great tutorial on C++ pong! FYI looks like your source code link has been hijacked by spammers, it keeps redirecting me to dodgy sites. Can you paste the code on here?
@oleksandrsavchenko1961
@oleksandrsavchenko1961 8 жыл бұрын
Hi, NVitanovic! Thanks for your tutorials. I use Visual Studio 2012. And in line 80 when I try to type "cPaddle(int posX, int posY) : cPaddle()" Visual Studio show me an Error:"cPaddle" is not a nonstatic data member or base class of class "cPaddle". Do you not what it could be?
@oleksandrsavchenko1961
@oleksandrsavchenko1961 8 жыл бұрын
When I set comment before : cPaddle(). Error go away And my left paddle doesn't move. But when I hit keys 'i' or 'k' ball start running.
@bilbobaggins7858
@bilbobaggins7858 7 жыл бұрын
Is there a way to clear the console screen without causing the flicker?
@lunapictures7989
@lunapictures7989 7 жыл бұрын
Yeah, there are even simpler methods using just iostream and windows.h (if you still need it I can record a fast tutorial)
@Stek40Channel
@Stek40Channel 7 жыл бұрын
It would be awesome id you do it :D
@lunapictures7989
@lunapictures7989 7 жыл бұрын
Aaaand I did it. Just rendering, uploading and it will be on my channel. And I'm really sorry that it's not the best tutorial but I have really no expirience in doing them. But I think that everything important is there.
@heheminroev
@heheminroev 7 жыл бұрын
it is a really great tutorial just wanted to ask about the flicker aswell. can see you would upload a fix but can't see it yet;(
@lunapictures7989
@lunapictures7989 7 жыл бұрын
Brian madsen For my tutorial I've sent a working code. So after adding this to your project it should work. The only thing I could maybe add to make it even better is making the cursor not visible. I'll do an update if a have a time. ;) Have a nice day
@manriqueiriarte8268
@manriqueiriarte8268 7 жыл бұрын
what if you don't have access to conio,.h and can't use _kbhit ?
@ItsMyWorld2
@ItsMyWorld2 4 жыл бұрын
'_kbhit()' lies in 'conio.h'. If you do not insert 'conio.h' '_kbhit()' will not work.
@citizendot1800
@citizendot1800 3 жыл бұрын
Use ncurses library
@tokugeeky2931
@tokugeeky2931 2 жыл бұрын
Thank you, this is so helpful
@style_13
@style_13 12 күн бұрын
how do u slow the ball speed? also stop the flickering? :))
@jimchan2114
@jimchan2114 8 жыл бұрын
Amazing! Just Simple and fun!
@billc119
@billc119 6 жыл бұрын
charmap!! I didn't know that, and it makes the game much nicer
@jctagaming9774
@jctagaming9774 4 жыл бұрын
hey thanks allot i rilly liked the videos it helped allot rilly but is there any way to stop the flickering on the game it wold rilly help me thanks..
@aakashshah1822
@aakashshah1822 3 жыл бұрын
did you get any solution?
@jctagaming9774
@jctagaming9774 3 жыл бұрын
@@aakashshah1822 no 😓
@cpt_badass5223
@cpt_badass5223 8 жыл бұрын
hi i love your tutorials i have just one question how do i stop the game from flashing as the walls the ball and the paddles keep flashing how do i stop this so that they don't flash anymore
@shinab2377
@shinab2377 3 жыл бұрын
If you draw the walls in the main function , it should stop blinking. But the paddles would be blinking.
@elvinosas
@elvinosas 8 жыл бұрын
Are you going to make opengl with c++ tutorials in the future?
@JoeExpress
@JoeExpress 8 жыл бұрын
Super!!!Great job!!!I like your tutorials NVitanovic!Continue!!Like like like
@עמיתעמר-מ1ל
@עמיתעמר-מ1ל 8 жыл бұрын
love ur vids keep the hard work
@vectordhruv8908
@vectordhruv8908 3 жыл бұрын
Really amazing 🔥🔥
@vlads-succes3845
@vlads-succes3845 8 жыл бұрын
Hi, first of all i want to dowload c++. Can you do this in your next tutorial? I really need this NVitanovic. YOU DO A GOOD JOB HERE!!! Hope you'll do that👍🏼👍🏼👊🏼
@gjciener5360
@gjciener5360 4 жыл бұрын
In the input function in the game manager it says that _kbhit() and _getch() are undeclared identifiers. how do I solve this?
@ssss-ph6zl
@ssss-ph6zl Жыл бұрын
i need the source code it does not open fro the discription
@sasa-dc1gb
@sasa-dc1gb 4 жыл бұрын
conio.h doesn't support my compiler :(( any suggestions for the alternative?
@rubyPWNS1
@rubyPWNS1 8 жыл бұрын
I really liked your style of teaching C++. It's was very simple but still well enough. I wish you continued, or maybe did the same for Java.
@SCARRIOR
@SCARRIOR 8 жыл бұрын
Java is inferior to C++
@exitplanetduster
@exitplanetduster 3 жыл бұрын
That is an impressive result for a text based game. Is there a way to avoid that flickering?
@alexanderweber5635
@alexanderweber5635 3 жыл бұрын
También estoy buscando solución a eso. Por lo que tengo entendido, debo darle un tamaño fijo a la pantalla para poder sobreescribir el texto en lugar de borrarlo y volverlo a escribir.
@yusufharuna6290
@yusufharuna6290 7 жыл бұрын
Thanks you very much for this vedio series.
@booomlegshot
@booomlegshot 7 жыл бұрын
on the For loop that draws the ball, player1 and player2 my cout
@booomlegshot
@booomlegshot 7 жыл бұрын
lol never mind i missed a == only had =
@thePadlockesTech
@thePadlockesTech 3 жыл бұрын
This was good. But, how do you determine a way to change the direction into something other than random when it hits the paddles? The original Pong uses physics (basically) so if the ball is coming upright and the paddle hits it from a certain angle it responds by going upleft instead of a random direction.
@atlantic_love
@atlantic_love 2 жыл бұрын
It's all about the angles.
@johnniefujita
@johnniefujita 5 жыл бұрын
less verbose (player1x == j && (player1y == i || player1y + 1 == i || player1y + 2 == i || player1y + 3 == i)? or do you preffer the full conditional else if sequence? i think this way gives the beginner a more spacial feeling of the window
@dragospredi8664
@dragospredi8664 8 жыл бұрын
@NVitanovic Very nice tutorials. If you could continue and maybe make such simple games with OpenGL or SDL libraries so it would be an actual game it would be great, and I believe that many people that watch your tutorials agree :)
@hananeikh
@hananeikh 6 жыл бұрын
i agree 100%
@LetsMineSomeBlocks
@LetsMineSomeBlocks 9 жыл бұрын
is there a way to make this into a program so it is on your desktop and you can click it to open it?
@ttqgrowtopia7897
@ttqgrowtopia7897 6 жыл бұрын
if you didn't get the answer, when you compile it, it creates the .exe file( the program) that you can open and the program will run, did it help?
@emilovici8688
@emilovici8688 8 жыл бұрын
How can I make the pads move simultaneously?( I mean, when I press two keys at once: 1 for first's player pad and the other pad for player 2)
@NVitanovic
@NVitanovic 8 жыл бұрын
It's not possible in this kind of implementation to do so. This is done in the console so the console accepts one key at a time. You can use though a library that will allow you to do similar things. Start with SFML it's a library for 2D games and it contains advanced input.
@ItsMyWorld2
@ItsMyWorld2 4 жыл бұрын
sir can u tell me how to stop blinking the program🥺🥺
@aakashshah1822
@aakashshah1822 3 жыл бұрын
i have same problem did you get any solution?
@ItsMyWorld2
@ItsMyWorld2 3 жыл бұрын
@@aakashshah1822 no
@JohnSmith-kw4xu
@JohnSmith-kw4xu 8 жыл бұрын
Also, why did you set the variables ballx, bally, player1x, etc. if you could just use the values directly? e.g. ball->getX instead of ballx.
@atlantic_love
@atlantic_love 4 жыл бұрын
Because he didn't know how to design classes.
@robigo9912
@robigo9912 7 жыл бұрын
Hi there! Could you pls explain how to implement that sleep function into the code? The game flickers very much and it's not really playable. Thx in advance!
@Reaper7mk
@Reaper7mk 7 жыл бұрын
just put sleep(50) in the main loop at the end of each iteration. So it would look like: while(!Quit) { Draw(); Input(); Logic(); Sleep(50); }
@aakashshah1822
@aakashshah1822 3 жыл бұрын
@@Reaper7mk it just slowdown ball and frame can you please provide any proper solution? thanks in advance
@Entropy3ko
@Entropy3ko 8 жыл бұрын
Great stuff! Upload more! :)
@corbax2189
@corbax2189 4 жыл бұрын
i love your videos and great tutorial like all others. i just wanted to say that i noticed a small bug. when the ball touches right paddle it can disappear and i need to restart the game. can you or someone else explain why is that happening. all and all great video
@thePadlockesTech
@thePadlockesTech 3 жыл бұрын
The ball disappears after it touches the right paddle? There's a chance the code might be slightly off in the logic function.
@PhasePD
@PhasePD 7 жыл бұрын
dude i have looked thru the playlist with your c++ tutorials, you dont have pipes, why?
@SkiNNyPoNNy
@SkiNNyPoNNy 6 жыл бұрын
whats pipes
@lecomp
@lecomp 4 жыл бұрын
I am doing this code on my Ubuntu. At the end of this video, I had problems during the compilation as described below: undefined reference to 'initscr' undefined reference to 'stdscr' undefined reference to 'wgetch' Here is the part of the code error: if (initscr()) { char current = getch(); if (current == up1) if (player1y > 0) player1->moveUp(); if (current == up2) if (player2y > 0) player2->moveUp(); if (current == down1) if (player1y + 4 < height) player1-> moveDown(); if (current == down2) if (player2y + 4 < height) player2-> moveDown(); if (ball->getDirection() == STOP) ball->randomDirection(); if (current == 'q') quit = true; } Here are the libraries: #include #include #include #include #include
@michaelcastillo884
@michaelcastillo884 7 жыл бұрын
when i put #include and compiled it it said that there was no such file or directory- any solution ?
@usamamuzaffar9174
@usamamuzaffar9174 6 жыл бұрын
in dev c++?
@arunmohanc6031
@arunmohanc6031 5 жыл бұрын
I have also that kind of problem and what did you did
@abdelrhmanelsaid4589
@abdelrhmanelsaid4589 7 жыл бұрын
AWESOME Thank alot bro :) Guys console screen so hard to make games :) need high logic ^^
@Zly_u
@Zly_u 9 жыл бұрын
Can I make this game not in console? I want to make game like this but with graphics. Can I do it in VS?
@NVitanovic
@NVitanovic 9 жыл бұрын
+Zlyudchik Yes you can, and if you want share the code with the others.
@Zly_u
@Zly_u 9 жыл бұрын
ok thanks!
@omgfmaftw
@omgfmaftw 8 жыл бұрын
+Zlyudchik hey dude did you manage to make one? if so how did you build a GUI for it?
@Zly_u
@Zly_u 8 жыл бұрын
+fmaftw no, not yet, I not active learning C :/
@mattiafontana2264
@mattiafontana2264 8 жыл бұрын
+Zlyudchik , you can do that whit C/C++ and OpenGL libraries. If that is too hard, i advice to use the SFML lib.
@Anwari70
@Anwari70 3 жыл бұрын
Source code isnt opening?
@brattergaming9276
@brattergaming9276 4 жыл бұрын
I get an error that says "player1 : undeclared identifier" and same with player2
@JohnSmith-kw4xu
@JohnSmith-kw4xu 8 жыл бұрын
WriteConsoleOutput() will remove the blinking and improve rendering times.
@hendrik2765
@hendrik2765 8 жыл бұрын
can you pls say where i am a c++ noob ;D
@trungnguyennhat7152
@trungnguyennhat7152 5 жыл бұрын
Cam on Ban rat nhieu! I'm come from Viet Nam!
@El_kammex
@El_kammex 3 жыл бұрын
Why we don't need a sleep() function in this game and its work perfect?
@danield4n13l
@danield4n13l 6 жыл бұрын
lol made this, and if the direction is upleft when colliding with top, it does nothing... same when downleft when colliding with bottom can you guyz help me?
@tylerhoyt9950
@tylerhoyt9950 8 жыл бұрын
How do i use sleep to not make my screen flicker
@NVitanovic
@NVitanovic 8 жыл бұрын
If you set the sleep value too high it will flicker less but the input won't be that responsive. It all goes down to guessing the value for your PC.
@Fixy15
@Fixy15 2 жыл бұрын
Source code is not working for me :/
@creative1978
@creative1978 8 жыл бұрын
Great job!!!!!!
@siddhantbhardwaj2649
@siddhantbhardwaj2649 8 жыл бұрын
Bro, Where do i add the sleep function if i dont want my game to flicker?
@tylerhoyt9950
@tylerhoyt9950 8 жыл бұрын
RIght after Logic in the run function
@lilqueen279
@lilqueen279 8 жыл бұрын
HELLO THERE.WHAT IS THE OBJECTIVE OF THIS GAME? AND THE MINOR OBJECTIVE. THANKYOU
@randominternetuser5123
@randominternetuser5123 5 жыл бұрын
i know this comment is 2 years old, but seriously? you dont know pong? smh -_-
@coffeecatrailway
@coffeecatrailway 7 жыл бұрын
only one player can move at a time. How can I fix it?
@hoangminhnguyen2840
@hoangminhnguyen2840 3 жыл бұрын
thank you
@sameershah6174
@sameershah6174 4 жыл бұрын
What should i do to stop blinking in the game
@sameershah6174
@sameershah6174 4 жыл бұрын
@NVitanovic
@MrEmpirz
@MrEmpirz 4 жыл бұрын
thank you bro
@FaizanIzen
@FaizanIzen 7 жыл бұрын
Thanks a lot brother
@cyndymyndy8516
@cyndymyndy8516 7 жыл бұрын
your tutorial is awesome but could you plzzz tell why does the screen blinks at last and how to fix it
@VirTuneCS
@VirTuneCS 7 жыл бұрын
It's because System("cls") clears the screen then you are redrawing it again, causing the blinking
@cyndymyndy8516
@cyndymyndy8516 7 жыл бұрын
but how to fix it???
@varusmaster
@varusmaster 7 жыл бұрын
you are the best
@SebastianClarence
@SebastianClarence 9 жыл бұрын
do I use empty project
@lijack456
@lijack456 7 жыл бұрын
please design a new tutorial~ its really helpful,thanks you
@voxcake
@voxcake 8 жыл бұрын
Thanks you very much! :D
@herooyyy
@herooyyy 8 жыл бұрын
My console close right after I run it. How do I fix that?
@thegodofmusic2904
@thegodofmusic2904 8 жыл бұрын
+DroonDZN You probably still have the return 0; statement at the top of the main function like this: int main () { return 0; // Other random code. } Simply place the statement at the bottom of the function or comment it out and the console should run fine.
@judewoolls6272
@judewoolls6272 8 жыл бұрын
Please help my two paddles are both on the same side anyone got suggestions
@BTechPrasad
@BTechPrasad 5 жыл бұрын
thanks a lot
@hoangminhnguyen2840
@hoangminhnguyen2840 3 жыл бұрын
can you give me code
@jjeon9850
@jjeon9850 7 жыл бұрын
Where is the value of player2x inputted?
@mohamedsalah7286
@mohamedsalah7286 5 жыл бұрын
how can i stop this blink
@ballacknugraha7236
@ballacknugraha7236 7 жыл бұрын
absolutally asik this game browh :D:D:D, thank you sir, terimakasih
@SebastianClarence
@SebastianClarence 9 жыл бұрын
mine said rand is not declared in this scope
@m.o.s6275
@m.o.s6275 6 жыл бұрын
my code block say same thing but i include stdio.h and stdlib.h and it work for me i have no idea how i fix it, but it work and now i try to fix c.???
@Nick-jb4xi
@Nick-jb4xi 6 жыл бұрын
If I play long enough, eventually my ball refuses to leave the center. I can still move the paddles though. Has anyone else had this problem?
@atlantic_love
@atlantic_love 2 жыл бұрын
I haven't looked at all of his code in the videos for this game, but I'm thinking he generated direction of the ball from the center using a random number. There is an algorithm I found late last night to help me solve the exercise I'm working out of a Stroustrup's C++ book. Before I found that algorithm on Stack Exchange I was loosely getting a random number (using rand() ) in the range I was looking for, but for whatever reason I started getting random numbers outside the range I was looking for. Here is the algorithm I found that keeps random numbers within desired range using rand(). int getRandomInt(int max, int min = 1) { return (rand() % (max + 1 - min)) + min; }
@ilias-achahbar
@ilias-achahbar 8 жыл бұрын
So why does the game actually flicker?
@aakashshah1822
@aakashshah1822 3 жыл бұрын
did you get any solution?
@cassu6
@cassu6 6 жыл бұрын
for some reason my paddles dissappear after the first "goal"
@arduino1871
@arduino1871 2 жыл бұрын
7:19
@lazizjonnasriev6123
@lazizjonnasriev6123 5 жыл бұрын
Why we need time.h header in this program
@ЛилиСтефанова-д6х
@ЛилиСтефанова-д6х 3 жыл бұрын
To call the srand function
@asadelahi9688
@asadelahi9688 8 жыл бұрын
+NVitanovic plz upload the video how to make chess game plz +NVitanovic
@Nick-jb4xi
@Nick-jb4xi 6 жыл бұрын
lol, that would be like 10 videos probably
@negativaura
@negativaura 8 жыл бұрын
wow programming is hard and i thought this was simple games to make and u wrote about 300 lines of coding wow.
@atlantic_love
@atlantic_love 4 жыл бұрын
In a couple of places early on, he had a lot of redundancy, and unnecessary methods. No way PONG should require anywhere near 300 lines of code.
@nikiforovpteacher
@nikiforovpteacher 3 жыл бұрын
This code does not compile in VS2019. 10 mistakes.
@abdelrhmanahmed1378
@abdelrhmanahmed1378 4 жыл бұрын
you can also just put if (x == width-3) , think about it and thank me later
@asadelahi9688
@asadelahi9688 8 жыл бұрын
sir plz upload the videos how to make chees game thanks
@louisymalay3053
@louisymalay3053 7 жыл бұрын
Cool....
@naveenkr.904
@naveenkr.904 3 жыл бұрын
game is blinking a lot
@spyrex3988
@spyrex3988 4 жыл бұрын
This was so cool thank you so fukin much bro
@BossManTee
@BossManTee 7 жыл бұрын
how about using a fucking GUI ?!!
@logicprogrammingformulatio9592
@logicprogrammingformulatio9592 4 жыл бұрын
someone have a seizure while playing this game!
@pjak1minecraft
@pjak1minecraft 3 жыл бұрын
Yeah, my eyes are dying.
@neildevera9868
@neildevera9868 9 жыл бұрын
Dendi
@kucharekcoto8310
@kucharekcoto8310 7 жыл бұрын
System("cls") System("cls") System("cls") System("cls") System("cls") System("cls")
@NovakiSalem
@NovakiSalem 7 жыл бұрын
if you comment this line out you'll be in for a chuckle
@luongmaihunggia
@luongmaihunggia 2 жыл бұрын
How do I slow down the ball's speed?
@rachithkanchanabandarawickrama
@rachithkanchanabandarawickrama 2 жыл бұрын
Thank you
@murad3460
@murad3460 7 жыл бұрын
System("cls") System("cls") System("cls") System("cls") System("cls") System("cls")
C++ Tutorial 23 - STL Templates and Vector library example
12:11
C++ Tutorial 21 - Simple Pong Game (Part 1)
15:27
NVitanovic
Рет қаралды 198 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 42 МЛН
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
BEST WAY to make Desktop Applications in C++
26:00
The Cherno
Рет қаралды 947 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 845 М.
C++ Tutorial 21 - Simple Pong Game (Part 2)
14:40
NVitanovic
Рет қаралды 83 М.
I Redesigned the ENTIRE YouTube UI from Scratch
19:10
Juxtopposed
Рет қаралды 913 М.
When the #1 Shen gets "COUNTERED"... *10 Solo Kills*
33:59
CoPilot Review: My Thoughts After 6 Months
9:45
ThePrimeagen
Рет қаралды 559 М.
What Is Your Level In Russian? (Grammar)
8:01
Life of Yama
Рет қаралды 222 М.
Top 10 Linux Job Interview Questions
16:04
tutoriaLinux
Рет қаралды 2,4 МЛН