Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Game Programming (http://www.xtremevbtalk.com/-net-game-programming/)
-   -   Trying to code body collision for snake game in vb 2012 (http://www.xtremevbtalk.com/-net-game-programming/326647-trying-code-body-collision-snake-game-vb-2012-a.html)

vicki442 12-06-2013 08:52 PM

Trying to code body collision for snake game in vb 2012
2 Attachment(s)
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.

passel 12-08-2013 01:59 PM

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).

All times are GMT -6. The time now is 03:04 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.