Problem with collision detection
Problem with collision detection
Problem with collision detection
Problem with collision detection
Problem with collision detection
Problem with collision detection Problem with collision detection Problem with collision detection Problem with collision detection Problem with collision detection Problem with collision detection Problem with collision detection Problem with collision detection
Problem with collision detection Problem with collision detection
Problem with collision detection
Go Back  Xtreme Visual Basic Talk > > > Problem with collision detection


Reply
 
Thread Tools Display Modes
  #1  
Old 05-31-2013, 07:34 AM
vestais vestais is offline
Newcomer
 
Join Date: May 2013
Posts: 1
Default Problem with collision detection


I'm a beginning programmer working on an assignment for a programming class I'm taking. We are expected to make a small game of any kind in VB 2008. My game idea was to make a maze where the player moves a character around and "picks up" objects. The problem is that I'm having a lot of trouble making sure the picture box with the little character in it can't touch the walls. I've looked online in a lot of different places, tried to make the maze walls out of picture boxes, labels, and rectangle shapes, and tried multiple methods of collision detection, but nothing seems to work and I can always move the picture box either in front of or behind the walls.

I feel like I'm missing some important knowledge not present in collision detection tutorials I've been looking at because it's assumed that I know it already. Is someone willing to provide a small bit of code that can help me out, or help me know what I'm doing wrong? I can post the code I have so far if needed!
Reply With Quote
  #2  
Old 05-31-2013, 09:16 PM
passel's Avatar
passelProblem with collision detection passel is offline
Sinecure Expert

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

How are you moving your object? Do you have restrictions on the directions you can move, i.e. if you're doing a maze, are you restricting movement to the four cardinal directions, up, down, left and right? Is your design of where you place your walls and objects to pick up going to be grid based, like pacman and many other games?
If so, then you usually wouldn't need to worry about collision detection. You would just use a "map", i.e. a two dimensional array of some sort that would define what is in each grid position, like a wall, or a object that is picked up, etc...
When you want to move in a given direction, you just check the array element in the direction you want to move to see if you can move there, and if so, move to the new location. If you can't move because the map indicates an obstacle, then you don't move.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 12-15-2013, 02:06 PM
Chazz85 Chazz85 is offline
Newcomer
 
Join Date: Dec 2013
Posts: 10
Default

Ok heres my best guess
If (player.Top + player.Height >= picturebox.Top) And (player.Top <= picturebox.Top + player.Height) And (palyer.Left + .Width >= picturebox.Left) And (player.Left <= picturebox.Left + player.Width) And player.Visible = True And picturebox.Visible = Then
player.Visible = False
Timer.Stop()

MessageBox.Show(" ")
End If
Ok that code should detect if you wall contacts your player on all 4 sides if it doesn't work my bad it's been taken from my space invaders game. Were the shot makes contact with the invader killing it. So ignore any (x) thats for a array. So yeah it does the following
1)Detects the walls on all 4 sides
2)Makes player Visible false if he makes contact with the walls
3)Stops the main game or player or all timers if you em
4) Dislays lose game message box
So that should work
If not sorry for waisting your time and listen to the mod if this doesn't work he is 10 X's better then me.
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
Problem with collision detection
Problem with collision detection
Problem with collision detection Problem with collision detection
Problem with collision detection
Problem with collision detection
Problem with collision detection Problem with collision detection Problem with collision detection Problem with collision detection Problem with collision detection Problem with collision detection Problem with collision detection
Problem with collision detection
Problem with collision detection
 
Problem with collision detection
Problem with collision detection
 
-->