Help with snake clone

Started by
9 comments, last by kingpinzs 18 years, 7 months ago
I am trying to make a simple snack clone game. I am trying to figure out how to bend the snake. I am not sure if that makes sense at all. I am not sure how else to expalin it. Lwt me know if it does not make any sense.
Advertisement
Quote:Original post by kingpinzs
I am trying to figure out how to bend the snake.


<snip obligatory innuendo comment>


Snake is a fun game to recreate; no developer here will speak against that (hopefully, lest I look bad!). By 'bend' the snake, I'm assuming that you mean changing its direction so that the rest of the snake's body follows the direction that the last part of it moved in? (Wow, that IS hard to explain :P)

It might be best to look at it from a tile-based perspective, which is probably how you're handling it anyways. Your snake will occupy x tiles, and thus is x tiles long. When the head of the snake moves in one direction, snakebodypart #2 will move to the position that the head was last at, snakebodypart #3 will move to where #2 was last at, and so continuing until you reach x snakebodyparts. This way if the player takes a turn (recall that the user controls the head of the snake), the end of the snake will only take that turn once that position iterates its way down through the list of snakebodyparts.

Hoo, that came out much more shrouded than I had anticipated. Hopefully you'll see what I'm trying to nudge towards and will be able to go from there. ;) If not, I'm sure there's other members here than can pull out a more agile phrasing than I!
HopeDagger
So if I understand you right the body is actuley segments of tiles and that the the second tile just goes to the old first tile postition. It just seamed more like it moved more fluedly then that sounds. But then again i could be wrong. So I will give it a shot and let you know if it worked.

Thanks for the advise.
Quote:Original post by kingpinzs
So if I understand you right the body is actuley segments of tiles and that the the second tile just goes to the old first tile postition. It just seamed more like it moved more fluedly then that sounds. But then again i could be wrong. So I will give it a shot and let you know if it worked.


To be fair, I could just as easily be wrong. I'm not quite positive if I'm thinking of the same Snake game as you or not. If in doubt, you could link us to a game (or screenshot(s)?) of the Snake game in particular you had in mind, and we could work from there. I was never too big into the 'Snake scene', so maybe I'm thinking of another game.

Let us know how it goes. :)
Ive made a snake clone myself. If you want to look I just uploaded it (along with the source of course) to my website. Have a look if you want. Although this one is only ascii art Im sure the implentation of the so called "snake bending" (im not even going to try to explain it :P) would be very similiar.

Hope it helps and feel free to ask further questions about my source! :)

Mizii
I made a snake clone too. I did it by having a linked list for snake pieces. Each time interval you delete the last segment of the snake and put a new segment infrount of the first segment. I had somthing like a direction variable of the snake and that told me if I should put the new segment to the left / right / above / below . Good luck
If you would like a reference, here is a snake clone I made years ago. It runs in the Windows console and has a little score board.

clicky
Well that is the game I am trying to build it is just that I some how am having a hard time understanding how the tail of the snack really works. Thanks for every ones help I am going to study a little more and if I have any more questions I will post again. Thanks again
Ok I have a question now.I am using directDraw just incase you need to know.

how can I add a segment to a pervouse segment on the snakes body with out having to right out

THIS

Src.left = 0;
Src.top = 20;
Src.right = 23;
Src.bottom = 29;

Dest.left = SnLeft-Src.right;
Dest.top = SnUp+4;
Dest.right = SnLeft;
Dest.bottom = Dest.top+(Src.bottom-Src.top );


100 times? Could I use some kind of vector or a array?
you could just write a struct that maintains the current tiles coordinate then every x milliseconds you update all the other coordinates so that they're where the previous tile was then you can redraw the head of the snake.

You can use most data structures for it imo, queues, deques, vectors,linked lists, whatever

This topic is closed to new replies.

Advertisement