Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Snake Game, getting the tail to follow the head. help please.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
pear123




PostPosted: 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



Snake.zip
 Description:

Download
 Filename:  Snake.zip
 Filesize:  3.99 KB
 Downloaded:  139 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: 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.
pear123




PostPosted: 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?
Dreadnought




PostPosted: 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
Turing:
var MyArray : array 1..10 of int := init (0 1 2 3 4 5 6 7 8 9) % Setup an array with values [0 1 2 3 4 5 6 7 8 9]

% Now to shift all values down by one
for decreasing ArrayIndex : 10 .. 2 % We only go to 2 since the first element has nothing preceding it
    MyArray(ArrayIndex) := MyArray(ArrayIndex - 1) % set the value of each index to the value of the preceding index
end for
MyArray (1) := 10 % set the first index to a new value

% The array is now [10 0 1 2 3 4 5 6 7 8]


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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: