Results 1 to 4 of 4

Thread: Intersect Rect

  1. #1

    Thread Starter
    Member nXt's Avatar
    Join Date
    May 2001
    Location
    UK
    Posts
    37

    Intersect Rect

    I'm having trouble with collisions..

    i am drawing a map using an array of tiles (which are picture box's) and i have been told to make a tile collidable i need to use intersect RECT

    can anyone tell me how to do this?

    Cheers

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    The reason why most games don't use pictureboxes for each tile is that it requires 4 draws of the character, one for each part of a picturebox he's in (on rare occasions it could be 1 or 2). That's why there's one large picturebox and all of the tiles are blitted on. Then the character is.

    Anyways, IntersectRect works seeing if two RECTs are intersecting. For example:
    VB Code:
    1. Dim X As RECT: Dim Y As RECT
    2.  
    3. X.Left = Chara.NextX
    4. X.Top = Chara.NextY
    5. X.Right = Chara.NextX + Chara.Width
    6. X.Bottom = Chara.NextY + Chara.Height
    7.  
    8. Y.Left = Tree.X
    9. Y.Top = Tree.Y
    10. Y.Right = Tree.X + Tree.Width
    11. Y.Bottom = Tree.Y + Tree.Height
    12.  
    13. If Not IntersectRect(X, Y) Then
    14.     Chara.NextY = Chara.Y
    15.     Chara.NextX = Chara.X
    16. End If
    An ideallistc sample at best, this says you have a tree and a character, and the character & tree have X, Y, Height, and Width properties. Normal stuff. The chara also has a nextx & y, which is where you are moving them. You can simply use something like this before drawing, to make sure that the character doesn't move into said "tree".
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Member nXt's Avatar
    Join Date
    May 2001
    Location
    UK
    Posts
    37
    but doesn't that mean i have to declare it for every tile on my map? is there a way i could use interesect RECT with everysingle tile (1) on my map?

  4. #4
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    It's easy, instead of a Tree, use the tile where the player is about to move to (for example Map(PlayerX, PlayerY-1) if he's moving up
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

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