Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Game Programming (http://www.xtremevbtalk.com/-net-game-programming/)
-   -   Problem with collision detection (http://www.xtremevbtalk.com/-net-game-programming/326000-collision-detection.html)

vestais 05-31-2013 06:34 AM

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!

passel 05-31-2013 08:16 PM

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.

Chazz85 12-15-2013 01:06 PM

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

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.

All times are GMT -6. The time now is 08:47 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.