C++ Tutorial 18 – Simple Snake Game (Part 3)
Welcome to my simple game tutorial on C++. In this tutorial i will going to show you how to make a fun snake game.
We will finish our game, by adding a tail to the snake, and polishing the code up a bit.
Source code:
Finished game:
Mirror link:
Great C++ books that I recommend for beginners:
C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart (3rd Edition)
C++ Primer Plus (6th Edition) (Developer’s Library)
Programming: Principles and Practice Using C++ (2nd Edition)
Download link for visual studio 2012 express:
If you have any questions I’ll be glad to answer, please leave a comment on the video.
Thanks for watching and please subscribe.
Nguồn: https://blackdiamondskinserumsite.net/
Xem thêm bài viết khác: https://blackdiamondskinserumsite.net/game/
thank you for videos!!! Your explanation is awesome <3
Anyone provide source code of this
Thank you
Loved it .! Really appreciated . I felt so good when the tail worked . Also , for a beginner programmer like me i understood everything . Thanks Mate. You've earned yourself a subscribe .
when i pass over F it takes literally 10-20 seconds for my tail to grow, the score to increase and the F to respawn somewhere
PLS HELP
My snake is moving too fast can someone help me pls ?
Even though you said that this game is simple, this was so hard to understand since I am still learning the fundamentals of C++. This was a cool project though!
Can anyone explain me the tail concept
How to slow down the process
• My project run too much fast. want to slow it.
The finished game is a virus
Just imagen the amount of code used to make gta v lol
(nice game) i did the game and i was wondering how i can change the color of thing in the game???
I have run the code but the code is only running the draw function repeatedly and I am not able to input anything.
como fasso para aprender tudo isso?
nice man
so i fixed some problems and did some quality upgrades:
1)whenever he takes we fruit the "o" pops up at the top left corner of the map.
to fix that go to logic() and change from:
for(int i=1; i < nTail; i++)
to:
for(int i=1; i <= nTail; i++)
2)also you move you can backtrack and instantly kill yourself.
to change that go to input() and change it to:
if(_kbhit()){
switch (_getch()){
case 'a': if(dir != RIGHT){dir = LEFT;}
break;
case 'd': if(dir != LEFT){dir = RIGHT;}
break;
case 'w': if(dir != DOWN){dir = UP;}
break;
case 's': if(dir != UP){dir = DOWN;}
break;
case 'x': gameover = true;
break;
}
}
3) I also changed 'x' from gameover to pause by replacing:
case 'x': gameover = true;
break;
to:
case 'x': dir = STOP;
break;
and putting everything in logic() into: if(dir != STOP)
there is also a problem with fruit spawning inside snakes tail but I am too lazy to fix it.
mine is flickering..
I love this tutorial but is there a chance that you could make new snake game tutorial where u explain all the commands that you use?
My PC is so fast, that I can't control the snake and for some reason Sleep() doesn't work. Does anybody know how i can fix that?
Can any body send me the text of code
This actually worked , thank you !!!
Done the whole code……and got the perfect output…..Thanks man ✌️✌️
https://youtu.be/_efMgrQcBg0
how do you make the position of the fruit more random?
incase people dont understand how to see the score before the console closes on gameover, try adding
this:
System("cls");
cout << "Enter your deathscreen text here" << score << endl;
cout << "Press Enter To Quit";
cin.get();
right above the return 0; line in main, this will give you an nice little deathscreen that shows your score when you die.
When you run finally this project on the right i’ve seen letter ‘o’ which appears and disappers immediately. Why that happens???
Are you using VS
I was using visual studios and I ended up still messing up the "o"s in the corner even after watching your video and debugging a thousand times… plz help
It works but we cannot kill ourselves Kappa
There is a little bug like if if it's going right and I press to go left then it's game over so how to fix it
I think it's best to make array size of tailX and tailY [height*width]
Why don't you just have a list of [x, y] for the tail? And just remove the segment at the end of the list and just add a new one on the start?
Whats going on in 5:50 ?
i can't eat the fruit , i just go on top of it
the hardest part is in the draw function
My snake is too fast,does anyone know why?
Thanks. I learnt a lot , yet I could not run the game through code blocker and have a problem with visual studio 2019.
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?)
It is moving so fast I can even eat the fruit
@NVitanovic, how long have you been working with c++ until you can make something like a snake game?
The fruit move all over the screen but I don’t see any issue with my programs
Does someone else have the same issue
you r a fucking genious bro
Sir how to give colour to the wall and snake
simple game that requires a long code
I just can't seem to understand it
int prevX = tailX[0];
int prevY = tailY[0];
int prev2X, prev2Y;
tailX[0] = x;
tailY[0] = y;
for (int i = 1; i < nTail; i++)
{
prev2X = tailX[i];
prev2Y = tailY[i];
tailX[i] = prevX;
tailY[i] = prevY;
prevX = prev2X;
prevY = prev2Y;
}
Thanks a lot!
Super cool, thank you so much
Mine keeps opening white windows with nothing showing up on them.
How do i fix this?
How to install this on android