Results 1 to 8 of 8

Thread: Game Help Please

  1. #1

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372

    Game Help Please

    Hi,

    I've written a game, which is playable but I need to fix a few minor problems. One of them is in the collision detection.
    I have an image(a fly) popping up at random around the screen and when the Frog collides with it, points are supposed to be added to the score and a sound plays. Problem is, the points and sound are playing when the frog is nowhere near the fly, then when the frog gets the fly it doesn't always work.
    Here's the code I've used:
    Code:
    Dim GameTop As Single
    Dim GameLeft As Single
        
    'Code for Bonus Fly
    Randomize
    With imgBonusFly
        GameTop = Rnd * (Height - .Height)
        GameLeft = Rnd * (Width - .Width)
        .Move GameLeft, GameTop
    End With
    
    'Froggy gets Fly
    If imgBonusFly.Left < imgFrog(FrogIndex).Left + imgFrog(FrogIndex).Width _
    And imgBonusFly.Left + imgBonusFly.Width > imgFrog(FrogIndex).Left Then Bonus
    Could someone show me where I've gone wrong?
    How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?

    Global Freelancers | Web Traffic Analyser

  2. #2
    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
    Hmm weird, I was gonna tell you to normalize the vector and then do a whole bunch of complicated stuff, but hey, I think that this should work too:

    MouseCos = (MouseX - PlayerX) / Sqr((MouseX - PlayerX) ^ 2 + (MouseY - PlayerY) ^ 2))
    MouseSen = (MouseY - PlayerY) / Sqr((MouseX - PlayerX) ^ 2 + (MouseY - PlayerY) ^ 2))

    Don't ask. I inverted the formulae I use to find a point in a circle based on the position and radius of the circle, and an angle, to find the Cosine and Sine

    Hey wait! I just found a formulae to normalize a vector!!! YES!!! Thank you thank you thank you thank you
    I was looking for this for quite some time. Oh well. All I need now is to find out what the hell is the "dot product" of a vector (any idea?). Damn C++ articles for D3D, never try to use them in 2D you never find the functions you need...

    Oops sorry. Ok back to your question... now you normalized the vector of the mouse (duh I ended up doing the same thing ) all you have to do is convert the Cos and Sen you have into a usable angle (in degrees). Maybe someone can help me in this one, I don't think I know how to do it... I'll do a little bit of research and post here again in a few hours.
    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."

  3. #3
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Are you trying to do a box collision??
    Do something like this:


    function isColliding(SrcRect, DestRect) As Boolean
    Dim Colliding as boolean
    Colliding = True

    if SrcRect.Left > DestRect.Right And
    SrcRect.Top > DestRect.Bottom And
    SrcRect.Right < DestRect.Left And
    SrcRect.Bottom < DestRect.Top Then

    Colliding = False
    End If

    isColliding = Colliding
    End Function

    Or use the API Call "IntersectRect" to intersect the rectangles to see if they collide and if they do, it will return the parts of the first rect that collides with the second rect.

    If you are looking for a circle collision or some odd shape collision detection, then you will have to do loads of work (kind of like what Jotaf is talking about). Cosines and Sines!! Just Math.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  4. #4

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372
    Erm, Jotaf98, you lost me there...

    I've tried using a couple of different collision methods, but they don't seem to work. When the games first starts, if the fly pops up on the starting position of the frog then the collision is detected, no problem, but once the frog starts to move around the game area the collision detection stops.
    How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?

    Global Freelancers | Web Traffic Analyser

  5. #5
    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
    Oops sorry, I replied in the wrong post hehe

    Actually I replied to the post, forgot, then replied again but in this one. It was late and I was sleepy this kind of things happen a lot under these conditions

    Anyways... there's a problem with your code but it's pretty obvious, I'm sure you already noticed it... you're only testing in the X axis (Left and Width), you should also do the same in the Y axis (Top and Height). You should use MoMad's code if you're using RECTs. If not, use this one:

    'Froggy gets Fly
    If imgBonusFly.Left < imgFrog(FrogIndex).Left + imgFrog(FrogIndex).Width _
    And imgBonusFly.Left + imgBonusFly.Width > imgFrog(FrogIndex).Left _
    And imgBonusFly.Top < imgFrog(FrogIndex).Top+ imgFrog(FrogIndex).Height _
    And imgBonusFly.Top + imgBonusFly.Height > imgFrog(FrogIndex).Top Then Bonus
    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."

  6. #6

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372
    Hi,

    Still not working. It should, I can't see anything wrong.
    I've attached the form, maybe you can see something.
    Attached Files Attached Files
    How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?

    Global Freelancers | Web Traffic Analyser

  7. #7
    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
    Hmm sorry, but the images are missing... put the images, the form and the vbp file in a single zip file and upload it here
    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."

  8. #8

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372
    It's OK, I've got it fixed now. I had the collision detection in the wrong place.
    How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?

    Global Freelancers | Web Traffic Analyser

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