Help with the mouse!!!

Started by
7 comments, last by Corrosive 23 years, 10 months ago
Hi, i´m having some trouble with the mouse routines, I initialize the mouse, then call the function showmouse, then i get the x and y coordinates, but when i try to do some like this: if x_mouse <35 && x_mouse>10 it does not work, why it happens? i want to make a game called here in Brazil " Jogo da Velha" I need the mouse!
To code is to make things come to life ;)
Advertisement
Daí Corrosive, beleza?

How are you retrieving this x_mouse? Window messages or DirectInput or what? Give some more info.

Falou,

Nicodemus.

----
"When everything goes well, something will go wrong." - Murphy
Nicodemus.----"When everything goes well, something will go wrong." - Murphy
Yes, how are you obtaining the X Y coordinates. Do you already have a system which obtians the coordinates based on how many mickeys the mouse has moved or not. If not, the reason it isn''t working is because you are only getting values that reflect how far the mouse has moved on the X and Y axes not their exact position.
Well, i think this is the problem...

I made the function to return only the absolute values to x and y mouse, like mov ax,0x03 int 33h, etc...

how can i return in mickeys, and how can i use mickeys to orient the mouse and myself?


Any help is welcome, thank´s bye!
To code is to make things come to life ;)
ok here is a nice way to use the mickeys to get exact coords. First of all you need to need some number to tell you how fast the mouse is going to move:

long MouseX,MouseY; //Global Mouse Positions
float MickeyRatio=1.2; //Mouse Move Speed%

Then you need your function which asks for the mickeys each time though the loop to do this:

if (MickeyX) //if mouse moves on x axes
{
MouseX+=(LONG)(MickeyX*MickeyRatio); //get new X coord
if (MouseX > ScreenWidth)
MouseX=ScreenWidth; //bound right to screenwidth (global)
if (MouseX < 0)
MouseX=0; //bound left to 0
}

if (MickeyY) //if mouse moves on y axes
{
MouseY+=(LONG)(MickeyY*MickeyRatio); //get new Y coord
if (MouseY > ScreenHeight)
MouseY=ScreenHeight; //bound bottom to screenheight (global)
if (MouseY < 0)
MouseY=0; //bound top to 0
}

Of course I guess I should warn you, this is a good way to keep an accurate position on the screen because the mouse moves according to a speed percentage, if you set the MickeyRatio to 0.5, it is going to move at 50% of normal but you are going to get nice smooth pixel perfect accuracy. The problem with this mouse example is that the hardware mouse may not match what coordinates you have in MouseX and MouseY. This can be easily solved by SETTING the position to YOUR MouseX/MouseY coordinates at the end of your function; which you''ll probably have to do since it looks like you are using an old dos assembly interrupt call.

I would have written this out in assembly for you, but I think you can translate the basic idea over, plus I don''t have the time to do that right now anyway, sorry.
However, if you are using interrupt calls, there is a much easier way. It has been awhile since I have used that old stuff, lett me look at my old code source, one sec....

int 33h calls:

mov ax,0 //reset mouse
mov ax,1 //show mouse cursor
mov ax,2 //hide mouse cursor

mov ax,3 //get mouse coords & state
returns:
bx: button pressed (0=none,1-left,2=right,3=right or both)
cx: x coord
dx: y coord

mov ax,7 //restrict mouse movement on x axes
mov cx, left side
mov dx, right side


Humm, well, if you were using these functions then it should have worked since function 3 int 33h returns true coordinates (not mickeys). Unless you used decimal 33 instead of hex 33 in your interrupt call, you might want to check that, it''s a common mistake.

Here is a couple of things to remember with these functions. If you use the show function more than once, then you will have to use the hide function the same amount of times to hide the cursor (does anybody know why they cursor functions today still do the same thing? you think they would have fixed that by now). If you want to set the position of the mouse to a specific spot on the screen, you can use a technique called "nudging" to PUSH the cursor where you want it: use the restrict mouse (function 7 int 33h) to set the horizontal and vertical X & Y coords to the position on the screen you want. This "pushes" the mouse to where you want it, then you run function 7 again and restrict the coords to the full screen size (unrestrict).

mov ax,8 //restrict mouse movement on y axes
mov cx, top
mov dx, bottom
Well guys, Now i am really confused about my code...

Like you have said the function 3 return true values, and i have tested my function this way:

I simple made a line of code with PRINTF command to put on the screen the x and y values everytime the mouse enter in a certain area, Doing this, i prove that my function works, and are returning the correct values, but the problem is, when i try to do something like that:

if (mouse_x()>=30 && mouse_x()<=100){ do shit;}

And i have seen the problem, it´s with the number of times i use the mouse_x() function call. For example, if i just say something like that:

if(mouse_x()=10){printf(fklds);}

it works, but if i use a more complex code with if like the other code i show before, nothing happens...

i wanna know wwwwwwwwwhhhhhhhhhyyyyyyyyyyyy!!!!!!

PLEASE HELP!
To code is to make things come to life ;)
Alright, I have had problems with multi-conditional if statements before, the problem lies in the way that the if statement deciphers the conditional ( <=, ==, >=, !=, ect.). Try specifying which conditionals belong to eachother by placing parenthesis around each statement like so:

if ( (mouse_x()>=30) && (mouse_x()<=100) )

also, for speed and less foul-ups, assign the value of mouse_x() to a local function variable before you use the if statements so that if the value of mouse_x() changes from one call to the next it won''t screw up the check, like so:

UINT localx=mouse_x();
UINT localy=mouse_y();

if ( (localx()>=30) && (localx()<=100) )

and one more thing, in your last example, you use an if statement which actually assigns a value instead of checking it:

if(mouse_x()=10)

you should you a == for conditionals, I don''t know if this was a typo or not, you might want to check your code to see if you have done this in a few places. This can really cause problems since if you do this:

if (localx=10)

then the condition will always be TRUE since you are assigning the value of 10 to the variable durring the check.



I have tried this before, but i will try again just to be sure!

Keep thinking guys and thank''s.. But it still don''t work!
To code is to make things come to life ;)

This topic is closed to new replies.

Advertisement