help me progam collision detection

03-13-2002, 11:05 AM
ok this is what i have obja is a picture box objb is a line
how do i tell the computer not to let obja pass (please use sample code and post what library was used)
Private Sub ObjA_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
ObjA.Top = ObjA.Top - 80
End If
If KeyCode = vbKeyEscape Then
End If
If KeyCode = vbKeyDown Then
ObjA.Top = ObjA.Top + 80
End If
If KeyCode = vbKeyLeft Then
ObjA.Left = ObjA.Left - 80
End If
If KeyCode = vbKeyRight Then
ObjA.Left = ObjA.Left + 80
End If

End Sub

03-13-2002, 12:33 PM
Are you using the Visual Basic line control which has X1, Y1, X2, and Y2? Or are you drawing a line programmatically?

03-15-2002, 03:02 AM
i dont know i am new at this

03-15-2002, 04:41 AM
Sorry, I don't understand your question.

'how do i tell the computer not to let obja pass'

Your moving a picturebox around, and you want to test a line for something, your code doesn't even show any objb???

Please try to explain in more detail what you are trying to achieve.

03-15-2002, 07:54 AM
If you are using a line control, you could check like this:
If KeyCode = vbKeyUp And ObjA.Top <= ObjB.Y1 + 80 Then
Then the object will go up only if it's not 80 from the line.
Hopefully, it's a line parallel with the sides. If the line is diagonal, this will require more coding.:)

03-19-2002, 10:29 AM
its a line and if i use that code what would i put after the then statement
to halt obja and objb is a line if you read the first post

03-19-2002, 02:51 PM
After this statement to halt obja, you would do whatever it is that you use to stop movement.
In this case, you are using KeyUp.
If KeyCode = vbKeyUp Then
If ObjA.Top <= ObjB.Y1 + 80
'ObjA hit the line, so ObjA does nothing. This would be a good place to add a 'OOF' sound effect
ObjA.Top=ObjA.Top - 80
End If
'You would do coding similar to this for the other directions.

Hope this helps :)

03-22-2002, 10:53 AM
that didn't work may be if i post what ive done so far as an attache ment you could help me don't scold my stupid and retarded program k

03-22-2002, 10:58 AM
oops don't have win zip just a sec

03-22-2002, 11:13 AM
sry last time

04-05-2002, 10:21 AM
im pretty sure this thread has had it

04-05-2002, 06:15 PM
Is there any difference between this thread and "ok lets talk pacman" ?

04-05-2002, 08:03 PM
Originally posted by Iceplug
Is there any difference between this thread and "ok lets talk pacman" ?

Yeah, One big difference. They both have different titles. :D

04-06-2002, 07:06 PM
what i changed isnt the best way for collision detection but it works... but it gets complicated if u want to make it a bit fancy
u should try using tiles

as with tiles u can also make a level editor, easily enough

04-08-2002, 04:38 AM
' From your program Andreww. :)
If KeyUp = True Then MoveY = -4
If KeyDown = True Then MoveY = 4
If KeyLeft = True Then MoveX = -4
If KeyRight = True Then MoveX = 4

If KeyUp = False And KeyDown = False Then MoveY = 0
If KeyRight = False And KeyLeft = False Then MoveX = 0

You could just put this before the keychecks:

If KeyUp = True Then MoveY = -4

Only thing wrong with the collision detection routine is that it only tests the man going from right to left. :)

04-08-2002, 05:03 AM
yea i sorta realised that :)

thats why i mentioned tiles

tiles i reakon are a very good idea, for the kind of game u are making

i mean u dont have to have the player moving per tile either

04-08-2002, 05:48 AM
Actually I don't even know what sort of game TinyTim is making here???

I thought this may have been part of the pacman one at first but now think he might be writing the start of a new game here....

So maybe tiles will be good for this... or maybe not. :D

Guess we'll have to wait and see.....

04-08-2002, 10:30 AM
well i first talked about it on the lets talk pacman but they got off subject and i started this thread then it died and then it arose hmm sound biblical

04-08-2002, 08:21 PM
Well that still sounds a bit confusing to me...

So does that mean this thread is still about your pacman game then? :confused:

04-09-2002, 08:05 AM
It has the same codes so it must be. It's still on the basics, though.

The thread descended to the dead thread section. On the third day, the thread arose. :cool:

04-09-2002, 10:19 AM
yeah this must be the thread of god
(god don't strike me down)

04-12-2002, 03:49 AM
Collision detection with walls.

This is a routing from my paddle game. When ball reaches bottom its dead, so i havent cased mball.y > scaleheight.

Sub CheckIfBallHitsWall()

Select Case mball.X
Case Is < 0
mball.X = 0
mball.xway = -mball.xway
PlaySound WallHit, True, False
Case Is > ScaleWidth
mball.X = ScaleWidth
mball.xway = -mball.xway
PlaySound WallHit, True, False
End Select

If mball.Y < 0 Then
mball.Y = 0
mball.yway = -mball.yway
PlaySound WallHit, True, False
End If

End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum