+ 7
A Little help, if possible...
After completing the Ben Ryves Tutorial and finally completing half of the MSDN Windows Programming Tutorial, I have decide to start working on a Snake game in C++! So far I can make the arena, some 10-12 levels ( Finite State Machine - Thanks to the tutorials shared by jay and help from many others), and the snake and random cherries. The game will increase the length of the snake by 1 whenever he eats a cherry... But, there is a problem that I am unable to work out a code for the dying scenario...
104 Answers
+ 8
oh btw. The levels could probably all be in one state. you could load levels layouts from a file or randomly generate them
available states would be something like:
intro
menu
level
options
exit
that way it will be much easier to add new levels
+ 8
lol. we about the same progress. Mine moves too fast by default though
+ 7
the snake is alllive! got mine appearing and responding to input.. but it has exponential growth lol. (every move the snake grows). more work required. How goes you Kinshuk?
+ 7
i havent done the length bit yet either. it just grows by itself 😢
+ 7
not yet. I have only got the head displaying.. so you are ahead of me!
+ 7
It continues on its own. What I did was store the current direction in a variable. Then in move function check which direction is current and +\- x y based on that. this continues the movement of the snake
+ 7
😆 ta. Yeah it is still very drafty! Lemme know improvements! I like improvements
+ 6
Nice! Well Done.
Here is a suggestion. You track the head position right? you have an index array that holds the info on what pixel/ascii char is where. so based on this.
if head and body are at the same x y coord. Dead.
if head = wall then dead.
+ 6
That gamemqking itself is pure awesomeness. I am still stuck in my little world of Python 🐍.
+ 6
ReadConsoleInput
+ 6
lemme know when u grabbed a copy
+ 6
That version has globals. ick. I had to do it that way though to get it into one file.. circular references and junk in Window and Gamestates.. But thanks! Hope it helps you with ideas for your version and the booking system you are designing
+ 6
Its a place that I put the final drawing code. As it is part of gamestate it gets called every loop. (along with logic and handle input)
It makes drawing to the screen unified across all gamestates. It is also where you could control movement speed (as you can see it goes pretty fast now as that code is still missing)
+ 6
check for only keydown events.
eventBuffer.Event.KeyEvent.bKeyDown
for a clearer understanding see the Paint Code I uploaded. It is alot clearer than in the snake game
+ 6
I just added that otherway just incase you ever needed it. what you said is correct for snake.
lol thats an awesome idea. maybe a super cherry that gives you a laser for x seconds!
+ 6
In my getting inputs function the only thing I do is set the current direction variable
I have another function called move this is what is actually called each loop in logic.
In the move function I do a switch statement on the current direction variable.
if current direction is up then y = - 1 if down y = +1 etc.
i.e
int dy, dx;
switch(currentDir) {
case UP:
dy = -1
}
newY = oldY + dy;
does this make sense?
+ 6
No bother friend!
+ 6
sorry finger slipped
+ 6
I take it you are not using game states. Wow That is cool code. I am unsure why it needs a loop though. But just seeing that, should work. looks the same as I am doing it (with a loop)
+ 6
This is why I used the state engine. Because we can seperate everything into three main functions easily. This can also be done in just a main single file. You want three main functions in your loop. handle input, (for getting input), logic (for game logic, move goes here eating fruit etc) and render (for printing to screen)
in these you include all your other functions