01-05-2014, 11:15 PM
What you could do is simply have a global variable to keep track of the portion of the zigzag (whether we are going in the positive or negative direction). For example, at the top of the code..
[code2=java]private int xDir = 1;[/code2]
And then, every time the snake moves, we simply change this variable, for example...
[code2=java]case Direction.NORTH:
newPoint = new Point(head.x + xDir, head.y - 1);
xDir *= -1;
break;[/code2]
This would create a wobble effect that works every turn. In order to make this for the y-axis, you would simply need a yDir global variable!
[code2=java]private int xDir = 1;[/code2]
And then, every time the snake moves, we simply change this variable, for example...
[code2=java]case Direction.NORTH:
newPoint = new Point(head.x + xDir, head.y - 1);
xDir *= -1;
break;[/code2]
This would create a wobble effect that works every turn. In order to make this for the y-axis, you would simply need a yDir global variable!