I am trying to make a snake animation with 10 circles. Each time the head of the snake moves in some direction, it will make the circle behind it move to where the head was previously. Likewise each circle moves to where the circle in front of it was previously.
Right now my snake is just a head:
How can I save a variable value, so I can move the other parts of the snake up? For instance taking the x,y and then setting the old x,y to the other circle behind it when ever it moves.
Also, any tips or examples on how I can get this to work in general would be of great help.
When I tried that the old one was the same as the new value. It did not save the value. It just made another variable with the same value. So, when the new value change the old valued changed to the same exact thing. [ October 26, 2007: Message edited by: Mark Quin ]
Someone else I had talked to said it had something to do with the way I was setting things up. I did not quite understand what he was trying to tell me. It had something to do with adding this:
s1= new snake (p) s2= new snake (p) s3= new snake (p) and so on... untill: s8= new snake (p) s9= new snake (p) s10= new snake (p)
privateSnakehead; public void setup (Snake head, Snake next,true for head,true for taill)
s1.setup(s1,s2,true,false) s2.setup(s1,s3,false,false) and so on... untill: s10.setup(s1,null,false,true)
if(leader)this prop() else head.prop()
prop() if(tail){ next.prop() next.setxy(x,y)}
-------------------------------------- I would have asked him more but he had to leave. Anyone understand what he was trying to tell me. I understand part of it. Like how it checks for head or tail and how the head sends the value to all of the other parts of the snake. But, I still don't fully understand how to implement this.
Anyone understand what to do? I really want to understand how this would work.
It's a lot less code to type or read, and a lot easier to change sizes later. Then we can move by putting each circle on top of the one before it for an instant - like an inch worm - except for the head which has to go someplace new.
Does that make sense?
I did something like this years ago and didn't actually move all the body parts. I just added a new one on the head end of the drawing and erased the tail one. It still looked like everything moved. Would that do the job? Only works if all the body parts are identical in appearance.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi