Many of you have probably seen the game "Nibbles" or "RattlerRace". The idea is that a snake moves around the screen eating numbers or apples (respectively) and getting longer with each one- if the snake gets all the apples without (a) running into a wall or (b) running into itself or (c) another snake (2 player in Nibbles or the enemy snake in RattlerRace), it advances to the next round, which either is faster or has more walls to run into, or both depending on the way it was programmed.
I'm rewriting this in Java, but having a hard time figuring out what the algorithm to draw the snake would be. Say if the snake were going left:
<-------
and then turned up, it would look like this:
^
|
-----
if it turned left again, it would look like this:
<--
|
---
I need to handle these turns in Java. Right now, I just have a rectangle that moves up and down, left and right. However, a snake could be the combination of many rectangles (I hope this makes sense)... so it would have to be a recursive algorithm. I was also thinking of storing the values in a Vector, but that wouldn't be very efficient.
Any ideas? Thanks all... [sig]<p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence."[/sig]
I'm rewriting this in Java, but having a hard time figuring out what the algorithm to draw the snake would be. Say if the snake were going left:
<-------
and then turned up, it would look like this:
^
|
-----
if it turned left again, it would look like this:
<--
|
---
I need to handle these turns in Java. Right now, I just have a rectangle that moves up and down, left and right. However, a snake could be the combination of many rectangles (I hope this makes sense)... so it would have to be a recursive algorithm. I was also thinking of storing the values in a Vector, but that wouldn't be very efficient.
Any ideas? Thanks all... [sig]<p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence."[/sig]