Advertisement

A Snake Algorithm

Started by December 18, 2002 03:16 PM
0 comments, last by luridcortex 21 years, 11 months ago
l/o everyone! Ive been working on a console based ascii snake game, like the one thats on everyone''s graphing calculator and cell phone. Ive got the game working perfectly except for one major detail: i cant get my snake to grow! When the snake collides with food, he is supposed to grow by one character, these characters follow the snake just like his body. Thing is i cant figure out how to spawn the pieces, and draw them to the screen properly. i created a structure that looks like this to handle the body parts: struct BODY{ COORD Position[100]; }; This way each element of position would represent a piece of the snakes "body". Then when the snake collides with a food character a global counter variable that represents the element to be modified is incremented by one, and that variable is passed to a function that determines the position of the Positon element. I think i have that part down, and thats how i m going to handle the "spawning" part of the problem, if that made any sense I think the problm at hand now is how to handle drawing the individual parts to the screen. If anyone has any ideas id appreciate them greatly! Also if posting my code would help, lemme know.
I don''t really understand what the problem is. If you have an array which describe the worm''s body, it should be trivial to grow it. Then you said that the problem was drawing the "individual parts", and I can''t see how the two problems are related. Are you redrawing the entire screen every frame?

Code might help, if it is somewhat compact.

This topic is closed to new replies.

Advertisement