[Off-Topic] C++ Game
Hi,
I was trying to make a simple snake game with C++ but I'm encountering a problem, there's a spamming _ running around the screen without stopping, I tried an already made code from YouTube which is supposed to work but the same happened. PHP Code:
|
Re: [Off-Topic] C++ Game
Interesting :D, I want to try also... you have YouTube link ?
Here one way hide console line https://stackoverflow.com/questions/...=votes#tab-top |
Re: [Off-Topic] C++ Game
Quote:
|
Re: [Off-Topic] C++ Game
I don't really understand what's happening. Can you record it? I can't try out the code, there's no conio.h on Linux.
|
Re: [Off-Topic] C++ Game
Not the ideal place to get help with your homework, but w/e.
Now, you have some big crystal clear issues, wondering how you didn't catch them: 1.In Logic() you are not using break; in any switch case, meaning that moving up and left is going to do nothing, while moving down and right is working because of how you ordered the switch cases. 2.But you will quickly notice that if you fix the above mistake once you press one key the cursor will not move only one position, but it will move until it gets out of the board. 3.2 (and also your weird cursor movement) happens because you are always redrawing the map, while redrawing should be done only when you actually got some input. (also _kbhit is not needed, _getch already waits for input) |
Re: [Off-Topic] C++ Game
Quote:
My apologies, I haven't ever coded in C++ so that's why there's lots of mistakes. I'm going to fix the moving out of the map logic later. I did as you told me and now it's okay, but I still don't get why it worked for the guy in the video but doesn't work when I use his code. Video Link: https://www.youtube.com/watch?v=W1e5wO7XR2w&t=446s Code: PHP Code:
PHP Code:
|
Re: [Off-Topic] C++ Game
Now your Input() function never returns 0. It is working however because you moved Logic() after _getch which waits for input.
A better approach: PHP Code:
PHP Code:
|
Re: [Off-Topic] C++ Game
Quote:
|
Re: [Off-Topic] C++ Game
As a side note, you should avoid to use global variables when they are not really needed.
You may need them when writing plugins because we are working with external events so we can't pass whatever variables we may need to them, but in most other cases you work only with functions you created so you have control over what arguments they take. |
Re: [Off-Topic] C++ Game
Quote:
|
All times are GMT -4. The time now is 03:41. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.