Computer Science Canada Snake Game, getting the tail to follow the head. help please. |
| Author: | pear123 [ Mon Jan 23, 2012 7:10 pm ] |
| Post subject: | Snake Game, getting the tail to follow the head. help please. |
What is it you are trying to achieve? I got the tail to grow when you eat food pellets but I can't find out how to get the tail to follow the head piece. What is the problem you are having? Tail grows but doesn't follow the head of the snake. Describe what you have tried to solve this problem I tried to use Y-10 on the snake array but it just made things messy. Please specify what version of Turing you are using 4.1 |
|
| Author: | Dreadnought [ Mon Jan 23, 2012 7:33 pm ] |
| Post subject: | Re: Snake Game, getting the tail to follow the head. help please. |
pear123 wrote: I tried to use Y-10 on the snake array but it just made things messy.
Why not just have each piece move to the location of the piece in front of it? You can write a loop or a recursive function to do this. |
|
| Author: | pear123 [ Mon Jan 23, 2012 7:37 pm ] |
| Post subject: | RE:Snake Game, getting the tail to follow the head. help please. |
Any tips or tutorials on how to do that? |
|
| Author: | Dreadnought [ Mon Jan 23, 2012 10:25 pm ] | ||
| Post subject: | Re: Snake Game, getting the tail to follow the head. help please. | ||
Well, lets say you want to change shift all values down one index in an array and give a new value to the first index. It might look something like this
You can probably see that doing this over and over will move all values from the lower index to the upper index. Just like you would want the positions of the snake pieces to move from the front to the back. Since the head is not part of your snake the piece behind the head would be the first element in your array, but I think you can deal with that. There are more efficient ways to get this behavior but they are also more complicated. Hope this helps, if you want to learn more about all thing Turing I suggest you browse The Turing Walkthrough. |
|||