Results 1 to 10 of 10

Thread: Mouse Position

  1. #1

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Mouse Position

    Hello everyone,

    I have successfully made a Commandos Style game in vb that has one level(working on it). The player has the abillity to pick up weapons and such. But, when the player clicks the gun, i want the gun icon to be displayed as long as the cursor is within 600 Twips of the Player. Here what i have but it doesnt work.

    VB Code:
    1. Private Sub Image2_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    2. Dim CX, CY As Integer
    3. Dim CursorPosition As PointAPI
    4.  
    5. GetCursorPos CursorPosition
    6.  
    7.  
    8. CX = CursorPosition.x
    9. CY = CursorPosition.y
    10.  
    11. If HoldSilPistol = True And CX <= MainFigure.Left - 600 Then
    12. Image2.MouseIcon = LoadPicture(App.Path & "\data\images\Entities\nopistol.ico")
    13. ElseIf HoldSilPistol = True And CX >= MainFigure.Left + MainFigure.Width + 600 Then
    14. Image2.MouseIcon = LoadPicture(App.Path & "\data\images\Entities\nopistol.ico")
    15. Else
    16. Image2.MouseIcon = silpistol.Picture
    17. End If
    18. End Sub
    nopistol.ico is a gun picture with a cross over it showing that the user cant shoot here. But if the cursor is within 600 twips of the player, it shows the pistol icon.


    Any ideas would be appreciated


    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  2. #2
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Have you made sure that mousepointer is set to 99 - Custom?
    Apart from that it works fine when I've tested it.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  3. #3

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    yeh, mousepointer is custom - 99, any ideas why it does work??

    Visual Studio 6, Visual Studio.NET 2005, MASM

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    GetCursorPos returns the X, Y relative to the top-left (0,0) of the screen. Controls have X, Y values relative to the top-left of their control. Therefore, you must compensate for this in your code (because I don't have the whole project in front of me, that's the most likely cause I can see!)

    Cheers.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Because my Form is maximised, GetCursorPos is returning the X, Y coordinates from the screen, but form top left is 0,0 to the screen. Should it not matter if this was the case??

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    You need to work on your logic, sorry I didn't see if before..

    You're saying if its to the left..... or if it's to the right... show the NO PISTOL icon. You need to use Ands/Nested IFs to do what you want, ex.
    Code:
    if (cx > (player.left - 600)) and (cx < (player.left + player.width + 600)) then
        if (cy > (player.top - 600)) and (cy < (player.top + player.height + 600) then
            '// Now do your stuff.
        endif
    endif
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7
    Addicted Member Aldragor's Avatar
    Join Date
    Oct 2002
    Location
    Québec, Canada
    Posts
    140
    Maybe you should calculate a distance between the man and the gun. With the Pythagore thing:

    VB Code:
    1. distance = sqr((distanceX*distanceX) + (distanceY*distanceY))
    then
    VB Code:
    1. if distance > 600 then
    2.   bla bla...
    3. else
    4.   bla bla..
    5. endif

    This also cover diagonal distance
    Last edited by Aldragor; Nov 5th, 2002 at 09:33 AM.
    Mens sana in corpore sano
    ... pour mieux travailler!

  8. #8

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Hey thanks all, its working now, just gotta make it bigger than 600 its not much really..LoL. Aldragor i tried doing what u suggested using Sqr() but i couldnt get it to what i wanted. Thanks anyway.

    Sastraxi im using your suggestion, and it works great, thanks!

    Visual Studio 6, Visual Studio.NET 2005, MASM

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    I would suggest using Aldragor's suggestion, as it will work in a circle around the person as opposed to a square - as all proffesional games would do.

    Here's how I think it should be:
    VB Code:
    1. distanceX = abs(cx- (player.left+player.width/2))
    2. distanceY = abs(cy- (player.top+player.height/2))
    3.  
    4. distance = sqr((distanceX*distanceX) + (distanceY*distanceY))
    5. if distance > 600 then
    6.         '// Now do your stuff.
    7. end if
    NB: the distances are from the center of the person, so you'll probably want to increase the 600 a bit.

  10. #10
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Its really up to you, phreak, which one you use. Just remember that while mine may be good for this instance, good coding style would call for the other suggestions by Aldragor and Si.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

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