palistov
Posting Freak
Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation:
57
|
RE: Snake: The Dark Descent
The animation is simply an infinitely loop; a function which calls itself on a timer. The timer's duration is a global variable so I can change it with power ups and such, or simply to debug by watching it slowly.
Since the grid consists of 800 units, it's not very efficient to use a for loop or to try and track which grid units should be lit/unlit and other data. The data structure would be huge...I tried that approach but I ended up with an 800 member array, and each member was an array of 7 or 8 variables (direction, lit/unlit, and some more variables I can't think of off the top of my head). Instead, I just activate the grid light which is the snake's head position, and create a timer whose duration increases as the snake's length increases, which in turn deactivates the grid light. It's really quite a simple approach, and makes checking for the snake's head-to-body collisions fairly simple.
|
|
11-03-2011, 08:15 AM |
|