Results 1 to 11 of 11

Thread: My lil game,... colition help

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Location
    Beaver, PA
    Posts
    6

    Question

    In my game you shoot bad guys with lasers. I want to see if there is a easy way of testing if the laser hit the target or not. Is there some kind of:

    If line1 is touching shape1 then

    sort of thing???

    If you can tell me if there is please tell me. If there isent one can you please tell me the best way to do this? This game will be mutiplayer it will be the next number one game!

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Woah! The story in yet game is incredible!!! Better than any DeusEx or whatever!

    Erm - enough of laughing

    Try this:

    Code:
    Dim Laser As RECT
    Dim Shape As RECT
    
    If Laser.x + Laser.w > Shape.x Then
       If Laser.y + Laser.h > Shape.y Then
          If Laser.x < Shape.x + Shape.w Then
             If Laser.y < Shape.y + Shape.h Then
                'Code for hit here!   
             EndIf
          EndIf
       EndIf
    EndIf

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    what shape is shape1?
    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.

  4. #4
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Kedaman, if someone asks such a question I think rectangular collision is good enough

    Or prolly a circle.. ask if you want to collide circles

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    yeah maybe, but i guess it depends, if the laser line is long enough i would treat it as a line
    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.

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Location
    Beaver, PA
    Posts
    6
    Hey Fox,...

    what does this do :

    Dim Laser As RECT <--------here
    Dim Shape As RECT <--------here

    If Laser.x + Laser.w > Shape.x Then
    If Laser.y + Laser.h > Shape.y Then
    If Laser.x < Shape.x + Shape.w Then
    If Laser.y < Shape.y + Shape.h Then
    'Code for hit here!
    EndIf
    EndIf
    EndIf
    EndIf

    My lasar is line1 and my shape is shape1,.. explian the vareibles to me please!

  7. #7
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    A RECT type has the x & y coordinates of the top-left corner of a rectangle, and either the coords of the bottom-left corner or the height and width of the rectangle. It's just a structure to store a rectangle in.

    Anyway, like Kedaman said, what kind of shape is it? A circle?
    Harry.

    "From one thing, know ten thousand things."

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Location
    Beaver, PA
    Posts
    6

    its a square!

    Its a sqare... But my laser is line1 and my shape is shape1 ,.... what does darclaring those vars do??

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Location
    Beaver, PA
    Posts
    6

    More trouble

    When i try to run that code the VB program highlights " Laser As RECT" from Dim Laser As RECT and says "Compile error: User-defined type not defined"
    whats does that mean?

  10. #10
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    It means you must declare the Type, as it is an extended member of the normal VB types:

    Code:
    Type RECT
       Left as Integer
       Top as Integer
       Right as Integer
       Bottom as Integer
    End Type
    Then make sure the scalemode is 3 - Pixels (vbPixels)

    Then you would put .X1 in left, .Y1 in top, .X2 in right, .Y2 in bottom (for the line).

    For the shape you would put .Top in Top, .Left in Left, .Left + .Scalewidth in Right, and .Top + .Scaleheight in Bottom. Then you can check the collision.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  11. #11
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Since I didn't really use the original RECT type you should either include this instead:

    Code:
    Type RECT
       x As Integer 'x-pos
       y As Integer 'y-pos
       w As Integer 'width
       h As Integer 'height
    End Type
    ...or replace x by left, y by top and so on in my code.

    It does not depend wheter your laser is just a line or a rectangle, use this code will work in both cases (better said: if you decide to switch to a rectangular (bitmap) laser, the code will still work perfectly)

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