Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012
Go Back  Xtreme Visual Basic Talk > > > Trying to code body collision for snake game in vb 2012


Reply
 
Thread Tools Display Modes
  #1  
Old 12-06-2013, 08:52 PM
vicki442 vicki442 is offline
Newcomer
 
Join Date: Dec 2013
Posts: 3
Unhappy Trying to code body collision for snake game in vb 2012


So, hi my first post here, I'm trying to code a body collision for a snake game, so that whenever the snake intersects whit it's own body it ends the game, but it doesn't seem to work as all the code (that I made for the body collision) does is that once I have 2 pictureboxes it spams the message box saying you lose.

I've been stuck on trying to code the body collision for a long time now.

I've added my code, and design with this post.
Attached Files
File Type: vb Form1.Designer.vb (3.1 KB, 5 views)
File Type: vb Form1.vb (5.2 KB, 2 views)
Reply With Quote
  #2  
Old 12-08-2013, 01:59 PM
passel's Avatar
passelTrying to code body collision for snake game in vb 2012 passel is offline
Sinecure Expert

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

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?
Code:
'
        For i = snakeLength To 1 Step -1
            snakeBody(i).Top = snakeBody(i - 1).Top
            snakeBody(i).Left = snakeBody(i - 1).Left
        Next
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
Reply

Tags
game, snake, vb2012


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012 Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012
 
Trying to code body collision for snake game in vb 2012
Trying to code body collision for snake game in vb 2012
 
-->