Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6
Go Back  Xtreme Visual Basic Talk > > > Setting boundaries on Snake Game vb6


Reply
 
Thread Tools Display Modes
  #1  
Old 03-11-2011, 01:35 PM
maxwell23 maxwell23 is offline
Newcomer
 
Join Date: Jan 2011
Location: Glasgow
Posts: 3
Default Setting boundaries on Snake Game vb6


I'm making the Snake game (decided to be cool and call it Serpent though) and I want to make it so that the snake can't go through walls and dies if it hits an edge, which is what my below bit of code does.

If ImgSerpent(0).Left < -1 Or ImgSerpent(0).Left = ScaleWidth Or ImgSerpent(0).Top < -1 Or ImgSerpent(0).Top = 680 Then
MsgBox ("You have hit an edge! Your score is " & score & ", Game Over") 'display message telling user their score
Call check_high_score
Timer.Enabled = False 'stops the timer
Set FormGame = Nothing 're-intitialises all the variables
End If

However, I have encountered a problem with it because although in the boundaries the snake cannot go into the top left hand corner of the screen as it dies as soon as it hits it, was just wondering if there's anyway to fix it?

thanks
Reply With Quote
  #2  
Old 03-12-2011, 03:00 AM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default Controls-based collision detection and beyond..

There is a way to fix it but you must become more knowledgeable about collision detection.
Then you will be able to adjust your If..then statement appropriately.

Have you had a chance to read through Iceplug's "Overlaps and Collisions" thread in the forum's Code Library.
This would be a great place to start.

Since you are doing "blocky graphics" (Image control based) collisions this thread might also be helpful, especially the demo attached to this this post.

The downside of using Image controls is that they have a tendency to flicker when animated (moved around).
The other limitation is that for irregular shapes (with transparent backgrounds) they don't offer pixel perfect collision. To do this you would need to evolve to using the Bitblt API.
If you are unfamiliar with the use of this API there are some beginner Bitblt demos in this Code Library thread.

By "bitblt-ing" the graphics (using a mask) you not only get flickerfree animation but the mask can be used for pixel perfect collision as demonstrated by the attachment to this post.

Lastly, there are about a dozen examples of snake games on the forum (if do a search) but it's hard to find a simple-basic one, that uses controls collision, with reasonably clean code, so I'll attach an example which hopefully will be helpful.
Attached Files
File Type: zip Simple_Snake_Game_using_shape_controls.zip (2.6 KB, 30 views)

Last edited by surfR2911; 03-12-2011 at 05:03 AM.
Reply With Quote
Reply


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
Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6 Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6
 
Setting boundaries on Snake Game vb6
Setting boundaries on Snake Game vb6
 
-->