C++ Tutorial 18 - Simple Snake Game (Part 2)

  Рет қаралды 753,548

NVitanovic

NVitanovic

Күн бұрын

Пікірлер: 787
@Felix-cn5vf
@Felix-cn5vf 3 жыл бұрын
I love that you left the problem solving part in when there's a error. Makes the vid feel more relatable.
@cgme9535
@cgme9535 3 жыл бұрын
yep
@thesun___
@thesun___ 2 жыл бұрын
yep
@ryanfredericks4403
@ryanfredericks4403 4 ай бұрын
yep
@markypoo5152
@markypoo5152 4 жыл бұрын
I'm learning c++ right now and found this and its honestly one of the coolest things I've ever seen
@forresearchpurposes7853
@forresearchpurposes7853 3 жыл бұрын
if ur fruit is not random generating try this: add #include in header in main() before setup(); add srand(time(NULL)); The rand() function does not generate a truly random number; it actually returns the next pseudo-random value in a sequence of values ranging from 0 to RAND_MAX. You can change the starting point in that sequence using srand().
@TheDorkol5
@TheDorkol5 3 жыл бұрын
What about my fruit not spawning after eating it 3 times. I checked the x,y and their good. Why noshow?
@bars9039
@bars9039 3 жыл бұрын
thanks man
@jonahbutler9079
@jonahbutler9079 2 жыл бұрын
mvp
@brhiandavila6987
@brhiandavila6987 Жыл бұрын
You are a great help, thank you
@jamesbalajan3850
@jamesbalajan3850 8 жыл бұрын
When he was having trouble with the logic I was screaming at the computer you put the decrement/increment under the break statement.
@scottmyron9453
@scottmyron9453 7 жыл бұрын
When i wrote my code, i didnt even realize he had done that, i just threw them before the break statement and was wondering, wait why is he having "Oh no he did it again".
@mattshu
@mattshu 7 жыл бұрын
I WAS SCREAMING TOO
@zelalemtenaw8660
@zelalemtenaw8660 7 жыл бұрын
Me too.
@sudharsanbalaji5633
@sudharsanbalaji5633 7 жыл бұрын
me 2
@josephsvec5478
@josephsvec5478 7 жыл бұрын
Me too, but we all make mistakes.
@reezuleanu1676
@reezuleanu1676 7 жыл бұрын
Definetely I've learned a thing or two about coding just from the first video. Really glad you explain what each line of code does.
@lalo24681
@lalo24681 8 жыл бұрын
If anybody else runs into the issue where it goes up and down faster than it goes left and right try this: in the main() put this if (dir == LEFT || dir == RIGHT) { Sleep(5); } Sleep(100); if (dir == UP || dir == DOWN) { Sleep(60); } This should improve the snake movement and make the walls spazz out less
@AndyU96
@AndyU96 7 жыл бұрын
Won't 'Sleep()' make the game less responsive?
@pialdas2451
@pialdas2451 7 жыл бұрын
I put the Sleep function after Draw() in main(), not after Input()
@user-ot6or1ze1y
@user-ot6or1ze1y 3 жыл бұрын
sleep was not declared in this scope
@sakshamchaturvedi
@sakshamchaturvedi 3 жыл бұрын
@@user-ot6or1ze1y add #include header file at the top of your program
@RyuuTenno
@RyuuTenno 3 жыл бұрын
this is a life saver. My pc is *way* too powerful for this XD
@simplyincorrigible7708
@simplyincorrigible7708 5 жыл бұрын
if you dont want the game to TERMINATE on screen edge, use this to make the snake 0 appear on the opposite side. if (x > width) x = x - width; if (x < 0) x = x + width; if (y > height) y = y - height; if ( y < 0) y = y + height;
@hellomynameisorange2860
@hellomynameisorange2860 9 жыл бұрын
Thanks for making these tutorials! I've learned quite a lot about C++. Once again, thank you.
@worldshaper1723
@worldshaper1723 4 жыл бұрын
Hey brother are amazing at programming ?
@dogtooth_gg
@dogtooth_gg 8 жыл бұрын
Note: I have tried working this in Dev C++, if you're having problems please put #include and #include
@NVitanovic
@NVitanovic 8 жыл бұрын
Thanks for the contribution!
@snowangel7980
@snowangel7980 7 жыл бұрын
did you figure out how to define the case labels? Mine keeps coming up with the errors "break statement not within loop or switch" and "case label "a [and all the other letters] " not within a switch statement"
@5x9x
@5x9x 4 жыл бұрын
If your snake goes too fast try this: #include int main() Setup(); while(!gameOver){ Draw(); Input(); Logic(); Sleep(40); } return 0;} } Also the fruit randomization is NOT random.
@sanidhyas3s
@sanidhyas3s 3 жыл бұрын
I added an input from user to take the difficulty and then set the Sleep(100-input) as input increases the user will get lesser time.
@memoalada
@memoalada 4 жыл бұрын
You can add: std::srand(std::time(nullptr)); before using rand() that's will change the random number according to your real time on pc while runtime that's will change the Fruit position every time you run the game :D but don't forget to write #include
@IamNotBored
@IamNotBored 6 жыл бұрын
for(int i = 0; i < width; i++) i have learnt so much
@jaydon.2833
@jaydon.2833 3 жыл бұрын
Congrats on making a limited loop! I also love this tutorial
@ravenrepairco.7885
@ravenrepairco.7885 5 жыл бұрын
Thank you so much for this tutorial! Listening to your explanations about each line really helped me with the basics of C++. I do have one critique, though. You mention a lot of Unix alternative commands for certain lines, but unfortunately the entire input code isn't at all Unix-compatible due to requiring conio.h for _kbhit and _getch (although _getch can be easily worked around by using ncurses.h instead of conio.h and replacing "_getch" with "_getchar", whereas _kbhit requires an entire rework of certain parts of the code, which isn't a simple task to a novice programmer, albeit there are quite a few posts about people working around similar issues online.). You might want to list that the finished product as you explain it is only compatible with Windows and DOS-based systems! Regardless though, a really well-made tutorial, even when you made mistakes in the video and had to stop and think for a second, it felt very real and genuine and helps us novices feel less bad about making mistakes!
@sugar8354
@sugar8354 5 жыл бұрын
Hello there!! We noticed exactly what you noticed too. We are trying to make a snake game on linux and have a problem coding the keys. Could you help us in some way please?
@daserstereichen
@daserstereichen 8 жыл бұрын
I love the intro music! Thanks for the tutorials :D
@funnifurrytechgirl
@funnifurrytechgirl 4 жыл бұрын
even as a complete newbie i put the command above the break lol, but great tutorial, it was really helpful and educational!
@hustler212
@hustler212 3 жыл бұрын
☁️9
@samikshapatel4337
@samikshapatel4337 4 жыл бұрын
4:39 is the logic spot
@artdrawpictures3266
@artdrawpictures3266 8 жыл бұрын
+NVitanovic how can i fix that flickering of the # Icons?
@foquro668
@foquro668 4 жыл бұрын
I don't know but mine isn't flickering. Sry that I have no solution for you : (
@foquro668
@foquro668 4 жыл бұрын
I got it working! I just reversed fruitX and fruitY: if (x == fruitY && y == fruitX) { fruitX = rand() % width; fruitY = rand() % height; score+=10; } I know usually this isn't good but it works!
@vir7796
@vir7796 2 жыл бұрын
I honestly love this tutorial so far. very nice, simple, and easy to understand. I'm personally using ncurses and cstdlib instead of conio since isn't available on macOS and Linux. There's not much difference in its implementation though, so it works out fine enough.
@MissRhea19
@MissRhea19 5 жыл бұрын
Hi sir, im having trouble with the movement of the snake its quite fast i cant even handle it. Is it possible to adjust the speed of the snake?
@stephenmatthew3881
@stephenmatthew3881 5 жыл бұрын
Use the sleep function. sleep(1000);
@GilFavor101
@GilFavor101 5 жыл бұрын
For windows, try __sleep()_ , example: if (dir == LEFT || dir == RIGHT) _ sleep(40); if (dir == UP || dir == DOWN) _ sleep(60); I put this in the Draw function, works okay.
@MrDeeb00
@MrDeeb00 5 жыл бұрын
@@GilFavor101 thx :)
@sonifasharmin3609
@sonifasharmin3609 4 жыл бұрын
@@stephenmatthew3881 I find 150 works best.
@foquro668
@foquro668 4 жыл бұрын
If you're using Linux and sleep() is too slow use usleep(). sleep() is using seconds and usleep is using microseconds.
@joshstadtmueller6765
@joshstadtmueller6765 5 жыл бұрын
fatal error: conio.h: No such file or directory #include is anyone else running into this problem would really appreciate some help, thanks
@greenjd3700
@greenjd3700 5 жыл бұрын
If you are still having this problem you may have to reinstall visual studio or whatever you are using.
@justcause7350
@justcause7350 5 жыл бұрын
Do not use conio.h in these applications. It is not recommended.
@funnifurrytechgirl
@funnifurrytechgirl 4 жыл бұрын
works fine for me, im using "TDM-GCC 4.9.2 64-bit release" for my compiler
@devashish_manna
@devashish_manna 7 жыл бұрын
I found two loop holes. 1) fruit should not generate where your tail is 2)if you are going left you can't go right .(applied to all directions) I actually solved them . Thanks for this tutorial. It helped
@AndyU96
@AndyU96 7 жыл бұрын
Even if fruit generates where the tail is, that won't make too much of a problem as long as the fruit doesn't get eaten by the tail, I think
@jayseagal3681
@jayseagal3681 3 жыл бұрын
is there a way to take keypressed input without using #include or #include
@Roast_Pollo
@Roast_Pollo 5 ай бұрын
#include and #include are what make those things work
@roydaher6671
@roydaher6671 5 жыл бұрын
i'm using visual studio 2019 they're telling me that the sleep function has been replaced by another version and its undefined . could somebody help me out please?
@harshjain4256
@harshjain4256 4 жыл бұрын
Use delay func
@privatepancake2760
@privatepancake2760 4 жыл бұрын
you could also put #include
@amirkia2378
@amirkia2378 4 жыл бұрын
dont put std:: behind it and add #include
@nurhusna1407
@nurhusna1407 4 жыл бұрын
So glad you show that you make mistake and how to fix it. A very good way to learn. Thank you!
@OmK-st2kk
@OmK-st2kk 5 жыл бұрын
Hi, Nvitanovic. Your tutorial is great and I used it but I have a problem. First of all the program flickers too much that I can't see anything. Second of all my snakes head moves so fast and vanishes after a second and I can't catch the fruits and the game instantly terminates. I was hoping if you or anyone could help me.(BTW will the sleep thing help any of those problems?)
@geneticallygamer
@geneticallygamer 2 жыл бұрын
If you guys want it to only move once every keyboard press/hit then use else{ dir = STOP;} after void input if statement
@rhodaappiah8120
@rhodaappiah8120 Жыл бұрын
Will it be after the } sign?
@boy6530
@boy6530 3 жыл бұрын
I will come back I hope a year from now I can execute this snake game easily so future me hello I hope you made it I believe in you by the way this is my first semester in Uni( IT )
@gonzalorosario1278
@gonzalorosario1278 4 жыл бұрын
I eat my nails seeying that you overlook the break; over the argument that you wanna execute in the switch argument. Great video!!!
@kaimynelis
@kaimynelis 5 жыл бұрын
cool tutorial, as long as it doesn't hit conio.h library which is windows specific, and in linux there is no such stuff. as long as I researched. there is ncurses.h library which should do the work, but it may or may not conflict with iostream library. probably would be nice to rewrite this interesting tutorial in portable manner, where correct libraries would be used depending on machine.
@simi8220
@simi8220 4 жыл бұрын
my score part and logic and input is completely same as in the video but when i pass over F my score doesnt increase and the F doesnt teleport to another spot randomly. help?
@gabrielmendesturyguimaraes8253
@gabrielmendesturyguimaraes8253 Жыл бұрын
Bit late, but you probably inverted the i and j when printing ur fruit in the Draw function
@NikiGz
@NikiGz 8 жыл бұрын
Nice tutorial, but i have a small problem. My snake moves too fast, what can i do to make it go slower?
@kamahlarcherfair2061
@kamahlarcherfair2061 8 жыл бұрын
the int main() go to the sleep and increase the sleep number the parenthesis. Example: Current - Sleep (10); Change to - Sleep (100); whatever number is your choosing.
@NikiGz
@NikiGz 8 жыл бұрын
thanks, it works :D
@kamahlarcherfair2061
@kamahlarcherfair2061 8 жыл бұрын
+Tacticz Spain you are welcome.
@deadyanothaikiropool1chait713
@deadyanothaikiropool1chait713 8 жыл бұрын
What library?
@Seboolek
@Seboolek 8 жыл бұрын
#include
@omkarpatil2094
@omkarpatil2094 8 жыл бұрын
snake wont move... seems to be a problem with enum, and when i typed switch(dir), visual studio did not directly add the parameters!
@manoj_kumar_sarkar
@manoj_kumar_sarkar 6 жыл бұрын
use eDirecton
@aronkafexhiu3068
@aronkafexhiu3068 4 жыл бұрын
same problem,did u solve it
@rishika6525
@rishika6525 3 жыл бұрын
The enum dir when using in switch case is showing ambiguity. What to do ?
@rizpect01
@rizpect01 4 ай бұрын
You are amazing MAN!!
@naveenkr.904
@naveenkr.904 3 жыл бұрын
how the snake head is moving continuously if there is only one time (x++) increment statement??
@S_whoelse
@S_whoelse 3 жыл бұрын
loop function, you have the input in the main function and its always playing when the setup is active. So when you loop it into the main function it does the X++ statement infinitely.
@veracruz4593
@veracruz4593 4 жыл бұрын
Trying to replace conio.h was annoying -- use ncurses. You can define your own kbhit function pretty easily. If you need a hand here's my snake game: github.com/vvveracruz/snake-game
@akankshapawar7378
@akankshapawar7378 Жыл бұрын
Thanks!
@sawyeranderson4166
@sawyeranderson4166 Жыл бұрын
Thanks, I've spent an embarrassing amount of time on this. :)
@w1nt3rolymp1cs3
@w1nt3rolymp1cs3 15 күн бұрын
thanks im stuck here rn
@monty7474
@monty7474 6 жыл бұрын
hi, how do you get the drawings to stop flickering?
@sachinmalik5837
@sachinmalik5837 5 жыл бұрын
see topic namely double buffering in c graphics . he is not using graphics .h thats why there is this flickering
@sampathkumartallapally5691
@sampathkumartallapally5691 4 жыл бұрын
if it stops flickering , we will see all heads or 0
@artfulization
@artfulization 8 жыл бұрын
Can you explain please. How can a point ( O ) go up, when you decrease Y value? I dont get that logic ... And how can it go down when you increase it?
@carterschmalzle1245
@carterschmalzle1245 8 жыл бұрын
In this case the origin is in the top left corner. Y is the distance from a point to the origin, so the larger Y is, the further it will be from the top of the screen. Basically Y is the opposite of what it would be on a standard coordinate plane.
@robertoreal9371
@robertoreal9371 8 жыл бұрын
Ok, thank you very much!! One last question, do you think that will be possible to put random walls in the middle of the square in order to make it more difficult?
@johanlindstrom9503
@johanlindstrom9503 8 жыл бұрын
When I try to compile and build I get error: 'kbhit was not declared in this scope exact same error on the getch. Im building in CodeBlocks on Linux. any suggestions for a fix?
@dizhong8368
@dizhong8368 8 жыл бұрын
Hi, I wonder how to make the snake moves slower? It is movin too fast for now.
@fastoon4789
@fastoon4789 8 жыл бұрын
add Sleep(put ur number here) the time is in miliseconds so 1000 is 1 sec 10000 is 10 sec etc...
@dondare7334
@dondare7334 4 жыл бұрын
Why isnt this guy uploading anymore,? Does anybody know?
@NVitanovic
@NVitanovic 4 жыл бұрын
Will do :), I've been planning for quite some time a new game tutorial for C++ that will teach you how to use Polymorphism by making a simple game. After that I will probably start a new series on C# or Python. Have a happy New Year!
@dondare7334
@dondare7334 4 жыл бұрын
@@NVitanovic You too, wasn't really expecting a response. But I really like your videos! Your tutorials are great! Can you do sukudo or minesweeper?
@ctonew6155
@ctonew6155 3 жыл бұрын
I am learning C++ and you made it fun and intresting. I also love the comments #include helped in slowing the snake and #include to make the fruit appear randomly. Thanks.
@hustler212
@hustler212 3 жыл бұрын
This helped
@qutabshah2889
@qutabshah2889 2 жыл бұрын
Thank you and also show us the hole program when it is don
@drinkurtishi8735
@drinkurtishi8735 6 жыл бұрын
How to add graphics to this?
@noormuhammad5923
@noormuhammad5923 5 жыл бұрын
use a game engine
@daivaanshusoanii6129
@daivaanshusoanii6129 4 жыл бұрын
How to make one
@Sake679
@Sake679 3 жыл бұрын
@@daivaanshusoanii6129 Code your own game engine
@bishwajeetsharma3498
@bishwajeetsharma3498 7 жыл бұрын
what is the need for enumerator why can't we directly use switch(getch()){case 'a': x++; break;........}for change of direction
@CarlWithAKay
@CarlWithAKay 9 жыл бұрын
5:40 That moment when mine works great and his is broken XD 20 min of programming and I AM THE MASTER!
@MrDeeb00
@MrDeeb00 5 жыл бұрын
lol
@harisadam9929
@harisadam9929 2 жыл бұрын
i can't use _kbhit() and _getch() in linux
@clashes4d34
@clashes4d34 5 жыл бұрын
hi im coding this on linux debian and the conio.h is only supported for ms compilers Using gcc compiler is there an alternative???? THX : )
@clashes4d34
@clashes4d34 5 жыл бұрын
FOUND IT! it´s ncourses.h import it in linux with the command: debian: sudo apt-get install libncurses5-dev libncursesw5-dev ubuntu: sudo yum install ncurses-devel ncurses hope i could help you a little bit!!! :) (insert lennyface)
@pponcho8245
@pponcho8245 5 жыл бұрын
How come my Visual Studio didn't populate the cases like it did on him on 4:53 ??
@JessePatrick-zc8ng
@JessePatrick-zc8ng 3 жыл бұрын
You hit tab when the little windows appear
@sanghuncho4989
@sanghuncho4989 8 жыл бұрын
I am using eclipse C++ and conio.h doesnt work and kbhit() also fails to work.. so would be great if there is a solution for this
@steliostb3120
@steliostb3120 6 жыл бұрын
I see the error
@austin-m8r-w6d
@austin-m8r-w6d 6 жыл бұрын
I know it's late but I'm pretty sure conio.h is windows only so if you are on mac or linux it will not work
@sutterseba
@sutterseba 5 жыл бұрын
@@austin-m8r-w6d Alternative?
@austin-m8r-w6d
@austin-m8r-w6d 5 жыл бұрын
@@sutterseba I believe ncurses is the best bet.
@kayang04
@kayang04 8 жыл бұрын
8:52 when i ran the game with that line of code, it closes immideatly as it opens
@kimchist2916
@kimchist2916 5 жыл бұрын
this the lesson i was lookin for. thx brah
@Muck-qy2oo
@Muck-qy2oo 7 жыл бұрын
I don 't have conio.h as I use Linux Mint. Is there an alternative?
@adithyan9584
@adithyan9584 5 жыл бұрын
Hi . How does the functions Input(),Draw(),Logic() work repeatedly (Like the snake keeps moving LEFT when we press key'A' once), even though we have not used any loops in the main() function
@sencerkaraduman959
@sencerkaraduman959 4 жыл бұрын
Too late but we have used a while loop in the main function. This would be the main function: int main() { Setup(); while (!gameOver) { Draw(); Input(); Logic(); } }
@TheDorkol5
@TheDorkol5 3 жыл бұрын
It's at a lower scope so it doesn't get returned to defaults
@burningknight7
@burningknight7 9 жыл бұрын
can you tell me which funtion or which part of the program lets us constantly get the output after we move the head?
@xajiraqab
@xajiraqab 9 жыл бұрын
+burningknight7 Draw();
@bilgehansel172
@bilgehansel172 9 жыл бұрын
+burningknight7 I think you wrote _kbhit instead of _kbhit()
@dobbertje0951
@dobbertje0951 6 жыл бұрын
I found it was better to put de Draw() function in the Setup function, and in the while loop after the Input and Logic functions. Because the user then has a tiny little bit to no input delay. While the original placement has very magnificent input delay.
@drinkurtishi8735
@drinkurtishi8735 6 жыл бұрын
HELLO PLEASE, is there any way to stop the constant 'flickering' of the walls? please tell me :)
@reinhold1616
@reinhold1616 4 жыл бұрын
Nice, but i dont like how it flashes when it refreshes the screen, i rather made an array that had the characters inside it and then just overlayed the array on the screen so it wasnt flashing (i used pascal)
@huh5950
@huh5950 6 жыл бұрын
great video, just one question: my snake moves two steps at a time instead of one, what can I do?
@jweezy15able
@jweezy15able 2 жыл бұрын
I'm running this under Code:;Blocks 20.03 and it tells me everything from Input after switch getchis "invalid conversion" or "inconsistent expression". Any pointers? Edit: I solved it. If anyone else has this issue, remember to put 'x' and not "x", or you'll get error coded. Ngl, was kinda hard to read so tell which one was used so I'm glad I only suffered minor set backs.
@muhammadreza8049
@muhammadreza8049 8 жыл бұрын
This is awesome to see for a beginner like me. Thanks guy! How to set the speed of movement, faster or slower?
@shaynejuggles
@shaynejuggles 9 жыл бұрын
when I switch my dir, it does not automatically print the cases underneath, any suggestions?
@niiloniminen8695
@niiloniminen8695 9 жыл бұрын
+Shayne Winn write switc and press down and then enter and then write di press down and press enter =) hope this helped maybe not you but someone that has the same problem
@drcvagos-iu
@drcvagos-iu 8 жыл бұрын
Second question: In the Setup function, x and y are being initialized, in the draw function they are used with the same values as initialized, how comes that the values doesn't die. Sorry for these questions, I'm new to C++ programming.
@TM_Makeover
@TM_Makeover 3 жыл бұрын
Values are only used not consumed
@TM_Makeover
@TM_Makeover 3 жыл бұрын
Values are only used not consumed
@TM_Makeover
@TM_Makeover 3 жыл бұрын
Btw good question
@mikhapichkhadze2885
@mikhapichkhadze2885 4 жыл бұрын
well i made this snake game in dev c++ and i just copied the logic what you writed and it worked i dont have any trouble
@onee0.01
@onee0.01 6 жыл бұрын
Tks for your code. And you can make this game with pointer instead of array?
@ashhadkhan1871
@ashhadkhan1871 8 жыл бұрын
Hello Sir. I am using Eclipse IDE and it does not recognize the function system("clr"). Adding conio.h library also does not help. I am a windows user. Please advice me what to do.
@jimbeammeup9879
@jimbeammeup9879 5 жыл бұрын
for system("cls") you need to #include
@shohanrahman9392
@shohanrahman9392 5 жыл бұрын
Anyone else getting inverted controls? Like, mine starts off normally but 2 to 3 keystrokes in, each key does the opposite.
@kaspo1810
@kaspo1810 4 жыл бұрын
having the same issue
@araa5184
@araa5184 5 жыл бұрын
Anyone on osx or linux. The keyboard input can be change with including curses.h getch() is available but kbhit isn't but it still works.
@beckett7601
@beckett7601 4 жыл бұрын
I'm on Linux (Pop!_OS) and kbhit works for me
@araa5184
@araa5184 4 жыл бұрын
@@beckett7601 I'm using the g++ compiler through terminal so its not included in the standard library or any library that I have installed. Unless I'm missing an include argument that I haven't found.
@beckett7601
@beckett7601 4 жыл бұрын
Oh, yeah, it's not included in g++. I had to download conio.h. Here: github.com/thradams/conio
@edwinG650
@edwinG650 6 жыл бұрын
You sounded like the Terminator when you said, "game terminates", with accent and all. You should've said game terminated. Haha
@MsPistoler
@MsPistoler 9 жыл бұрын
Awesome! You explain so clearly. Thank you!
@MrStevenplumb
@MrStevenplumb 7 жыл бұрын
Am I able to make my border less "jumble" it moves constantly and it's hard to see where I am moving the snake!
@Baccarebel2580
@Baccarebel2580 8 жыл бұрын
YOU BUT THE y--; and y++; under the break statement @5:30
@r0x304
@r0x304 5 жыл бұрын
No shit.. Really?
@ekyam2892
@ekyam2892 3 жыл бұрын
Im doing the same thing but its not working for me I am half way to giving up XD
@ishanpahwa1179
@ishanpahwa1179 3 жыл бұрын
which IDE are you using? If you don't mind me asking.
@yyfoo755
@yyfoo755 9 жыл бұрын
How can we use the arrow buttons on the keyboard to key in the input instead of pressing the alphabets (a, w, s & d)?
@yousefaweni3038
@yousefaweni3038 4 жыл бұрын
Help!!! The program keeps telling me the reference to 'left' is ambiguous what to do . Help please
@Viralfanatics
@Viralfanatics 4 жыл бұрын
Use LEFT and RIGHT instead of left and right.
@yousefaweni3038
@yousefaweni3038 4 жыл бұрын
@@Viralfanatics yes thanks i knew that a long time ago.
@jamesisgreat5634
@jamesisgreat5634 9 жыл бұрын
But conio.h is only available on windows. Is there any way around this if I'm using a mac?
@hellomynameisorange2860
@hellomynameisorange2860 9 жыл бұрын
+James IsGreat Yea, buy a PC.
@mdyasin7008
@mdyasin7008 7 жыл бұрын
i think this can be help you discussions.apple.com/thread/1176684?tstart=0
@ShizL
@ShizL 7 жыл бұрын
Hello My name is Orange XDDDD
@3ndr3wmusic56
@3ndr3wmusic56 6 жыл бұрын
good one xD
@thorpedersen8981
@thorpedersen8981 8 жыл бұрын
at 9:02, what is he using, I's, ls or what? when he is adding something to the if statement if (x > width II (what is this? Last two things
@thorpedersen8981
@thorpedersen8981 8 жыл бұрын
I'm new to c++ :)
@KCBunne
@KCBunne 9 жыл бұрын
8:08 At this point my snake head is blazing fast, I can barely keep track of it. Is this because my computer is faster? Can I control refresh rate of the terminal?
@KCBunne
@KCBunne 9 жыл бұрын
+KCBunne BlubbeN ! 's comment fixed my problem
@philip4902
@philip4902 9 жыл бұрын
+KCBunne How?
@philip4902
@philip4902 9 жыл бұрын
+KCBunne Problem solved nvm
@I_love_pancakes-k4p
@I_love_pancakes-k4p 6 ай бұрын
Not sure if anyone would see this, but I ran into a problem with the fruit placement on the map and I dont know how to solve it. The fruit is sometimes placed outside the map. Does anyone know how to fix this?
@xXPredator21Xx
@xXPredator21Xx 7 жыл бұрын
+NVitanovic Im using a Mac on eclipse and the _kbhit and getch wont work. People have said the conio.h will not work with it, so is there a replacement?
@chrysanthemon3040
@chrysanthemon3040 3 жыл бұрын
how is your board on the console so calm? mine is flickering all the time, and i have sleep(100) and it still is flickering as hell. any ideas how to stop that?
@manelouafi9653
@manelouafi9653 8 жыл бұрын
I use Linux...conio.h doesn't exist what can I do to replace kbhit() ?
@HellGod67
@HellGod67 8 жыл бұрын
+Manel Ouafi if (key==75) dir==LEFT; if (key==77) dir==RIGHT; if (key==72) dir==UP; if (key==80) dir==DOWN;
@werewolf218961
@werewolf218961 8 жыл бұрын
+Manel Ouafi perhaps you would like to refer to this page cboard.cprogramming.com/c-programming/63166-kbhit-linux.html
@arnold9448
@arnold9448 8 жыл бұрын
"Key was not declared in this scope"?
@werewolf218961
@werewolf218961 8 жыл бұрын
Check where you have defined variable key...and check if it is accessible within curly braces
@chinmayingle423
@chinmayingle423 8 жыл бұрын
include curses or ncurses at the start for Linux this will get the job done I suppose
@leeantoine976
@leeantoine976 5 жыл бұрын
In visual studio 2019, it says 'DOWN' is not recognized in 4:11 Can someone please help and direct me on how to fix this issue?
@leeantoine976
@leeantoine976 5 жыл бұрын
@@qrightdev what should I look for in the first video?
@rastor6484
@rastor6484 4 жыл бұрын
How did the dir case appear automatically @5:00
@lonzeking1038
@lonzeking1038 8 жыл бұрын
i have a problem , when i put switch (dir) into logic nothing happened and the letters weren't red i'm not sure if it caused it but my snake wont move at all
@learntime6357
@learntime6357 6 жыл бұрын
hello dude my compiler has an error with this: if (_kbhit()) { switch (_getch()) it wrote that : main.cpp: In function ‘void Input()’: main.cpp:56:16: error: ‘_kbhit’ was not declared in this scope if (_kbhit()) ^ main.cpp:58:24: error: ‘_getch’ was not declared in this scope switch (_getch()) ^
@zarulhadi4390
@zarulhadi4390 7 жыл бұрын
why is my compiled game flickering??? how do i fix the flickering thing
@anujgore2175
@anujgore2175 7 жыл бұрын
Zarul Hadi The flickering thing is due to the fact that tge square frame is being drawn everytime. It requires some time and hence it flickers. I guess the flickering depends on the CPU speed
@dimensionalblade2778
@dimensionalblade2778 5 жыл бұрын
6:09 to 8:00 yup that's me on while printing 'hello world'.
@اساور-و2ق
@اساور-و2ق 3 жыл бұрын
شكرا جزيلا 💙💙💙💙
@farhanchohan2479
@farhanchohan2479 9 жыл бұрын
I was thinking how two functions can execute simultaneously..... Moving the snake and catching the input..... program control works in sequence.... how can it go to the input function without completing execution of draw.....?
@shreyasrajapurkar3816
@shreyasrajapurkar3816 9 жыл бұрын
+Farhan Azam hello! i am not a pro but...yes the program control works in sequence...what do you mean how does it go to the input function without completeing the draw? the draw function's job was to just create the walls! so the draw function has been executed (which you know because you can see the walls there)...and THEN you input your key and then the snake moves (whch is done by the logic function). so every thing is in sequence i suppose...i am just a beginner and only hlfway through the video and i cant continue becuse i am facing some problems and i cant figure it out...so my answer has a really high probability of being wrong XD but since there was no answer to your comment so i thought that i should provide my views. cheers :)
@farhanchohan2479
@farhanchohan2479 9 жыл бұрын
I have developed it completely..... I have understood everything when I dry run every step. Now I know how snake is continuously moving and how you can input your keys. What problems are you facing ?
@NVitanovic
@NVitanovic 9 жыл бұрын
+Farhan Azam Sorry for not being able to explain this more in detail, videos would be a lot longer than they are currently. I'm happy that you managed to sort things out on your own and that's a big plus in your case. If you have any questions currently please reply to my comment. Thanks for watching! Best regards!
@farhanchohan2479
@farhanchohan2479 9 жыл бұрын
And also tell you something that in this video there are some logic which can confuse you. like kbhit logic using switch statement. In this video it is used twice whereas it doesn't need like that. The only thing which I had referred from this video is where to put the snake movement logic which I could had done if I think a little more. I regret for it. So if you will see this logic and implement it you will never learn to do yourself. Programming depends on logic and if you can't design a logic then you are not a good programmer.
@NVitanovic
@NVitanovic 9 жыл бұрын
+Farhan Azam I've made a lot of versions of this game on the similar principle. It's hard to implement this kind of game with limited features that console offers, there are by the way libraries that let you handle console drawing more easily. The library is called "ncurses" and it would help drastically to make a game look more fluid. You can also do it graphically by using SFML or plain SDL. As for the input, If I wanted to make a real game I would use an input library or SFML or native windows API for doing so. The problem is that I couldn't as I didn't mention these libraries or showed viewers how to use other libraries. The logic part is of course up to you, and it is normal that it varies, not all people think the same :). I had to adapt the game to the tutorial series knowledge as most of the viewers are here still learning. If you want you can share your code here so other users can see your code and you may help them :). Best regards!
@beesleyrc759
@beesleyrc759 6 жыл бұрын
I have a flickering line on my game, any fixes?
@mose999
@mose999 Жыл бұрын
thx it's helpful for me a newbie
@jjwwe2712
@jjwwe2712 2 жыл бұрын
Awesome material
@Caulin_
@Caulin_ 3 жыл бұрын
When I include the conio.h library it includes but there are a bunch of warnings
@amnaiqbal8307
@amnaiqbal8307 2 жыл бұрын
I am following the tutorial as it is but my screen keeps flickering and reprinting my for loops...? What should i do?
@Loose_DP
@Loose_DP 4 ай бұрын
Ok so i ran into a problem. Somehow in Void Draw() VS doesnt has x, y with the value of 10, but with the value of 0 instead. Even thoug it appears to do the divison of height and width in void Setup() If i write the divison of height and width to save it in x, y in int main() it works......BUT WHY? I wrote everything exactly the way shown.....
@Loose_DP
@Loose_DP 4 ай бұрын
NVM im Stoooooopid. didnt out Setup() in main LOL
@monome3038
@monome3038 8 жыл бұрын
keep making the good videos please! thank you!
@edsan4495
@edsan4495 Жыл бұрын
When the code runs, it's followed by a "press any key to delete the screen" even though i have put the _ifkbhit(). What can i do to make the screen wait?
@ThisIsMMI
@ThisIsMMI 5 жыл бұрын
In 5:04 why did you remove case STOP ? I am finding the this when I remove case STOP from the switch. warning : enumeration value 'STOP' not handled in switch [-Wswitch]. What should I do? Please help. ( I am using codeblocks). If you have any suggestion, please type the full code snippet when replying. Thanks in advance.😁
C++ Tutorial 18 - Simple Snake Game (Part 3)
16:19
NVitanovic
Рет қаралды 588 М.
Making a Game With C++ and SDL2
8:14
PolyMars
Рет қаралды 1,7 МЛН
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
how NASA writes space-proof code
6:03
Low Level
Рет қаралды 2,4 МЛН
C++ Tutorial 18 - Simple Snake Game (Part 1)
11:16
NVitanovic
Рет қаралды 2,2 МЛН
I made the same game in Assembly, C and C++
4:20
Nathan Baggs
Рет қаралды 839 М.
Making Simple Windows Driver in C
7:26
Nir Lichtman
Рет қаралды 372 М.
15 Years Writing C++ - Advice for new programmers
4:04
SyncMain
Рет қаралды 1,3 МЛН
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,8 МЛН
2 Years of C++ Programming
8:20
Zyger
Рет қаралды 292 М.
C++ TIC TAC TOE game for beginners ⭕
19:09
Bro Code
Рет қаралды 42 М.
Cross Platform Graphical User Interfaces in C++
44:49
javidx9
Рет қаралды 876 М.
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН