|
-
May 2nd, 2001, 08:48 PM
#1
Thread Starter
New Member
Colision
PLEASE HELP ME PLEASE!
lol
I'm a secondary 5 students and I do a game in a crappy Computer class with a stupid teacher who doesn't know anything! So there is the problem. I have 2 picture box.
picMan
picRock
I move the man with left and top proprieties. I want to know the code for the colision between the rock and the man.
And where I need to copy it! Thank you a lot!
Sorry for my english! I speak french!
 DarKsLiMe Was Here 
-
May 3rd, 2001, 02:14 AM
#2
transcendental analytic
Code:
dim collision as boolean,l1&,l2&,r1&,r2&,t1&,t2&,b1&,b2&
l1=picMan.left
l2=picRock.left
t1=picMan.top
t2=picRock.top
r1=picMan.width-l1
r2=picRock.width-l2
b1=picMan.height-t1
b2=picRock.height-t2
collision = (r1>l2 and r1<r2 or l1>l2 and l1<r2) and (b1>t2 and b1<b2 or t1>t2 and t1<b2)
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 3rd, 2001, 11:53 AM
#3
So, kedaman, are you a mathematician, or a scientist? =)
You can use the "IntersectRect" API call. Look around in the help files for more information.
Z.
-
May 3rd, 2001, 11:56 AM
#4
transcendental analytic
I'm a contrarian visioner :P
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 4th, 2001, 12:30 PM
#5
Thread Starter
New Member
-
May 4th, 2001, 12:52 PM
#6
transcendental analytic
the code should go where you want to detect the collision, if you put it in a timer you should ensure you have a interval>0 and enabled, the code itself just assigns collision variable true if there is a collision, otherways false. how do you move picman?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 4th, 2001, 03:52 PM
#7
Thread Starter
New Member
...
To move picman, I use this code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then picMan.Top = picMan.Top - 50
If KeyCode = vbKeyDown Then picMan.Top = picMan.Top + 50
If KeyCode = vbKeyLeft Then picMan.Left = picMan.Left - 50
If KeyCode = vbKeyRight Then picMan.Left = picMan.Left + 50
End Sub
And it work perfectly
All I want it to do is that when he touch the rock, he can't pass thrue it! I want him to not move!
Tank you for your help man
 DarKsLiMe Was Here 
-
May 4th, 2001, 04:12 PM
#8
Thread Starter
New Member
-
May 4th, 2001, 05:06 PM
#9
Good Ol' Platypus
You want to check for the collision FIRST, and then do it:
If CheckCollision() = False Then 'execute code
something along those lines, where it (CheckCollision()) would tell if picRock is in picMan.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
May 5th, 2001, 09:34 PM
#10
Thread Starter
New Member
Thanks god! It almost work!
Hi!
With the help of J Wilton who e-mail me, we almost got the perfect code. There is only one last bug! When the picMan come from the bottom, he pass thrue the picRock but not in the other side! Someone is havint an idea how to fix that? Please help me! 
here is the code
Dim collision As Boolean, l1&, l2&, r1&, r2&, t1&, t2&, b1&, b2&
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If (collision) Then
picMan.Left = picMan.Left - 50
picMan.Top = picMan.Top - 50
picMan.Left = picMan.Left + 50
Exit Sub
End If
If KeyCode = vbKeyUp Then picMan.Top = picMan.Top - 50
If KeyCode = vbKeyDown Then picMan.Top = picMan.Top + 50
If KeyCode = vbKeyLeft Then picMan.Left = picMan.Left - 50
If KeyCode = vbKeyRight Then picMan.Left = picMan.Left + 50
End Sub
Private Sub Timer1_Timer()
l1 = picMan.Left
l2 = picRock.Left
t1 = picMan.Top
t2 = picRock.Top
r1 = picMan.Width + l1
r2 = picRock.Width + l2
b1 = picMan.Height + t1
b2 = picRock.Height + t2
collision = (r1 > l2) And (l1 < r2) And (b1 > t2) And (t1 < b2)
'If (collision) Then imgcool.Visible = True
End Sub
 DarKsLiMe Was Here 
-
May 6th, 2001, 08:48 PM
#11
Thread Starter
New Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|