We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › contents of an array
Page Index Toggle Pages: 1
contents of an array (Read 564 times)
contents of an array
Dec 11th, 2005, 7:56pm
 
i'm trying to make a snake game for a school project, and the snake should be defined by an array. Can i create squares inside the array or just define the amount of squares, and then later in the void draw() i define that for each element of the array, i draw a square?
Re: contents of an array
Reply #1 - Dec 12th, 2005, 12:23am
 
I have a snake game already online if you would care to take a look.

It's designed to work on a mobile phone really (using processing mobile) but I wrote a normal applet to work on an AI system. No one is keen to offer solutions so I'm pondering what to do. That shouldn't stop you from exploring things like mazes, Mario style warps or bad apples. I would invent an egg or apple class if you are doing the latter two though, it will make things easier in the long run than the way I went about it.

In answer to your question, yes, store the snake as a string of squares existing on the grid it runs around on. It's much simpler to draw all the squares individually. If you wanted a more fluid drawing (say like markings on its back) then for each square, as well as an "x" and a "y" you should have a direction property as well. Then when it comes to drawing it you will be able to tell what direction to put the tiles down in or how you're supposed to be drawing around it.
Page Index Toggle Pages: 1