Computer Science Canada

collision detection help

Author:  wargamer17 [ Wed Apr 11, 2007 4:22 pm ]
Post subject:  collision detection help

I am trying to make my own version of the classic game Haunted House from the Atari 2600. Currently, I am trying to work on collision detection for the walls, but since it has multiple rooms, I am going to have many walls. For collision detection so far, I have been doing this:

code:

'shpCircle is the player that is moving
'shpWall is the wall to hit
'left wall
    If shpCircle.Left <= shpWall(1).Left + shpWall(1).width Then
    shpCircle.Move shpCircle.Left + 20 * intSpeed
    End If


Although this works for collision, I would have to do that for each wall. Is there any way I could use one piece of code like that for multiple walls, such as like a check to see if that wall is hit, then do the code for that wall? Maybe with a boolean? Maybe with colour detection so that if the player, the background, and the wall are different colours, and the player hits a certain colour(in this case blue for the wall) then it would stop as if it collided? This is what i have been troubled with. I think that as soon as I get collision detection working properly, I can finally get moving on this project.

Author:  wargamer17 [ Fri Apr 13, 2007 9:15 pm ]
Post subject:  Re: collision detection help

Well, i've been working on more tests for collision detection, and was able to get this:
code:

Sub Collision()
For intI = 0 To 5
If shpCharacter.Left + shpCharacter.Width >= shpWall(intI).Left And shpCharacter.Left <= shpWall(intI).Left + shpWall(intI).Width  Then
    If shpCharacter.Top <= shpWall(intI).Top + shpWall(intI).Height And shpCharacter.Top + shpCharacter.Height > shpWall(intI).Top Then
*****trying to fix this**********       
        'shpCharacter.Move shpCharacter.Left + 20 * intSpeed
        intCount = intCount - 1
        lblCount.Caption = intCount
    End If
End If

Next intI

If intCount = 0 Then
    MsgBox "Game over!"
    Unload Me
    frmGame.Show
End If
End Sub

'timer interval=1
Private Sub tmrCheckCollision_Timer()
Call Collision
End Sub


It is working, except after the collision, i want the character to stop. So far, it recognizes a collision, and counts down health.


: