View Single Post
Old 12-08-2013, 01:59 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,031

You've posted in the Legacy VB side of the forum, the latest being VB6 which was released in 1998.
But the code attached, and the title and tags you've created state this is vb 2012, which is a recent VB.Net version.
You should post your current VB language questions in the current VB language side of the forum, not in the Legacy (i.e. old) side of the forum.
I'll move it over.

I would think you should put a breakpoint in the timer Tick to see what the values of where all the parts of the snake are.
Which parts are colliding and why?

Just look at your loop. What is the first time through the body of the loop doing?
        For i = snakeLength To 1 Step -1
            snakeBody(i).Top = snakeBody(i - 1).Top
            snakeBody(i).Left = snakeBody(i - 1).Left
Answer: the (1) segment is being put on top of the (1-1, i.e. 0) segment. The 0 segment is your head, so you're putting the second segment on top of the position of the head.

You then do your collision tests, so obviously, the second segment will always collide with the head since you just put it there.

After the collision tests, you call moveSnake() to move the head.
Perhaps you should think about moving the head before the collision tests, rather than after, so that the second segment is not on top of the head (or the head intersecting the body at the second segment, since that is your test).
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote