Problem is, that would only allow my snake to be up to 253 squares long, including the head. I suppose I could just ignore that and just make you go faster after that to keep making it harder.
Even if I use a byte instead of an int, instead of being 7.5KB of RAM needed, it's 3.75KB. Still too much! What I need is a better system... I can't think of anything.
EDIT: Being a genius, I missed a post.
O'k, I didn't play this game for a while... And I find it an good brain exercise for weekend ;)
Yeh, not much could be optimized w/o changing the logic, I just have an idea:
in the beginning create "image-map" of the food, 1 - food, 0 - nothing.(492 bytes).
as snake couldn't be too long, put it on a "running track" - small array
size = maximum length of snake (what is it 8 or 16). Each elements of it holds XY coordinate of
the snake body pixel. One byte is enough for it, two make programming easier.
So it will require 16 integers, high byte X, low byte Y. ( 32 bytes ).
transfer foods image map to output buffer image the same size, add to output
image of the snake. (492 bytes).
Now on "click", move a "running track" like a conveyor belt / logical shift operation.
copy each element to left/right, if elements last in the chain it will be lost.
you know where snake moving on next step, look in food map check is there is "1",
add up XY coordinate on top of the snake body, clear food map to "0".
For more size reduction, I'd consider foods image-map create in the same way as a
snake's image, and it even doesn't have to move.
That's smart! But I just realized that since there's always just one piece of food on the map, instead of making an "image map" which I don't know how to do, I can just store the coordinates in 2 bytes.
But you were saying you could store both coordinates in one byte, it's just harder. How do I do that? The game field is 84x48.
BTW, why do booleans always suck up an entire byte? It makes no sense... Why does everything have to be in blocks of 8? Couldn't the ATMEGA store 8 booleans per byte rather than using 8 bytes for 8 booleans?