Results 1 to 11 of 11

Thread: Colision

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Near Montreal
    Posts
    9

    Angry 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

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  3. #3
    Zaei
    Guest
    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.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Near Montreal
    Posts
    9

    Unhappy doesn't work!

    Hi,

    I use your code but it do nothing... I first copy it on the form load. After, I decide to put it in a timer. No difference...
    I'm a newbie... so maybe it's stupid to ask but can you say where to put the code and an example of a collision(The picMan to not move)

    Thanck you
    DarKsLiMe Was Here

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Near Montreal
    Posts
    9

    ...

    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

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Near Montreal
    Posts
    9
    There is a little program similar to what I'm doing with little funny graphic. If you can modify it and send it back to me, i would be cool!

    There is the program!
    Attached Files Attached Files
    DarKsLiMe Was Here

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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)

  10. #10

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Near Montreal
    Posts
    9

    Wink 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

  11. #11

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Near Montreal
    Posts
    9

    Question ???? hello?


    Is anybody here to save me?
    DarKsLiMe Was Here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width