|
-
Nov 3rd, 2002, 05:10 AM
#1
Thread Starter
G&G Moderator
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:
Private Sub Image2_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim CX, CY As Integer
Dim CursorPosition As PointAPI
GetCursorPos CursorPosition
CX = CursorPosition.x
CY = CursorPosition.y
If HoldSilPistol = True And CX <= MainFigure.Left - 600 Then
Image2.MouseIcon = LoadPicture(App.Path & "\data\images\Entities\nopistol.ico")
ElseIf HoldSilPistol = True And CX >= MainFigure.Left + MainFigure.Width + 600 Then
Image2.MouseIcon = LoadPicture(App.Path & "\data\images\Entities\nopistol.ico")
Else
Image2.MouseIcon = silpistol.Picture
End If
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
-
Nov 3rd, 2002, 05:42 AM
#2
Ex-Super Mod'rater
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.

-
Nov 4th, 2002, 10:15 PM
#3
Thread Starter
G&G Moderator
yeh, mousepointer is custom - 99, any ideas why it does work??
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Nov 4th, 2002, 10:32 PM
#4
Good Ol' Platypus
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)
-
Nov 4th, 2002, 10:53 PM
#5
Thread Starter
G&G Moderator
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
-
Nov 4th, 2002, 11:47 PM
#6
Good Ol' Platypus
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)
-
Nov 5th, 2002, 09:30 AM
#7
Addicted Member
Maybe you should calculate a distance between the man and the gun. With the Pythagore thing:
VB Code:
distance = sqr((distanceX*distanceX) + (distanceY*distanceY))
then
VB Code:
if distance > 600 then
bla bla...
else
bla bla..
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!
-
Nov 8th, 2002, 05:55 AM
#8
Thread Starter
G&G Moderator
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
-
Nov 8th, 2002, 06:31 AM
#9
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:
distanceX = abs(cx- (player.left+player.width/2))
distanceY = abs(cy- (player.top+player.height/2))
distance = sqr((distanceX*distanceX) + (distanceY*distanceY))
if distance > 600 then
'// Now do your stuff.
end if
NB: the distances are from the center of the person, so you'll probably want to increase the 600 a bit.
-
Nov 8th, 2002, 10:19 AM
#10
Good Ol' Platypus
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|