This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

"Snake" Ggame on LPC1768

Hi everyone :) I'm writing project for my studies and my idea is write a game something like Snake. I have big problem with checking pixels, OK I'll explain it. I draw a line on LCD, draw and draw but as you see on movie if the "snake" enters on himself there should to end game and show "GAME OVER", but I don't know how can I check it. I have some idea for it. I declarated a table which has two dimensions - height and width LCD. When "snake" go anywhere, for example if he goes up, he safe "1" to the table on current coordinates x and y. One word - it safe last position. And there I check if new position will be "1" program stop. At the beginnig all table has "0". Every draw pixel put "1" to the table. I think you understand my idea. But...It doesn't work. I don't know why. When I flash processor everything stop and I can see only white display...No reaction. It works when I give small table...not as a LCD size, for example 50x50 ([50][50]) and draw snake on small place on the LCD. How can I do it...? I hope that you help me with it. And the movie... sorry for quality.

www.youtube.com/watch

and code...I must safe it to txt file because my thread is too long (when I have written it, there was error about to much words on text)

www.dropbox.com/.../main.c

I think that it looks like good for analyze and watch ;)

Parents Reply Children
  • Generally, I think your idea is the way you would have to do it. That is, maintain a two-dimensional 'collision map' using the array as you have suggested. However, memory is obviously a limitation. Therefore I would suggest that you consider drawing in blocks of pixels as the snake advances, effectively reducing your resolution and hence reducing the size of your collision array. For example, each advance of the snake might be a 10 x 10 block of pixels. Therefore assuming a 1/4 VGA LCD, you would have 32 x 24 discrete blocks to record rather than 320 * 240.

    Another way would be to actually read back the state of individual pixels from the LCD controller's frame buffer memory. Without looking at datasheets, I don't know whether or not you can do this with your particular LCD / controller.

    If you can't get your collision array to actually work for you then you'll need to post up some example code. Format it using the instructions seen above the textbox when you're posting.

  • Note that you want your collision map to only use one bit for each collision.

    A char array of 50*50 is 2500 bytes. So it quickly gets large. Having one bit/pixel would instead make it 7*50 = 350 bytes.

    With a 320x240 display, a full map would be 40*240 = 9600 bytes which is small enough to work with even if you have a full 1:1 map between LCD pixels and collision map. Going 2 pixels on LCD for one pixel of collision map, it would quickly have shrunk to 2400 bytes - same as your original 50x50 if used with full bytes.