Re: Snake game on LCD using Flowcode 7
Posted: Tue Dec 18, 2018 9:02 am
Hi,
You need some way to store the positions of each 'segment' of the snake. So you could use an array or a circular buffer. To move you draw the new 'head' of the snake and erase the last section - the contents of your storage need to reflect this (ie the new 'head' gets added to the front and the last element is deleted - if you are using a circular buffer you can amend the pointers to the front and back element of the snake and with an array - shift the contents of the array).
Your array or buffer needs to be large enough to store the longest possible snake.
Depending on the size of your display you can store each position as a byte (if the screen has <= 255 possible positions) or a word (possibly with x/y as high/low byte)
Martin
You need some way to store the positions of each 'segment' of the snake. So you could use an array or a circular buffer. To move you draw the new 'head' of the snake and erase the last section - the contents of your storage need to reflect this (ie the new 'head' gets added to the front and the last element is deleted - if you are using a circular buffer you can amend the pointers to the front and back element of the snake and with an array - shift the contents of the array).
Your array or buffer needs to be large enough to store the longest possible snake.
Depending on the size of your display you can store each position as a byte (if the screen has <= 255 possible positions) or a word (possibly with x/y as high/low byte)
Martin