Author Topic: Reseting the mouse?  (Read 727 times)

unseenmachine

  • Hero Member
  • *****
  • Posts: 3285
  • A fish, a fish, a fishy o!
Reseting the mouse?
« on: September 13, 2010, 06:25:15 AM »
I am working on my mario game maker. When i place an enemy, if i choose to move using Set Distance (an option in the program) once i place my enemy, the program asks for a move to posisiton, once i click on it, my program nearly allways puts another enemy in the same place as the move to block. As far as i can tell, this is beacause the program runs so fast, it sees my 1 mouse click as more than one.

I need a way of ensuring (in certain situations) that once the lmb is pressed, the program waits until it is depressed before continuing.

Anyone have any ideas?

Too see what i mean, you can download the .bas and image files needed here http://dl.dropbox.com/u/8822351/MarioMaker.zip unzipp to the folder on your HDD containing qb64.

Start a New Game and choose one of the 3 enemies. Set the initial direction and movement type (Set this to 2) and then add your enemy to the game grid. You should see a red box appear, use this to select the distance your enemy moves.

If you click the "Build Game" button, the program will create mwmbdtmp.bas, compiile and launch it! so be warned (CLIPPY!!!!)

codeguy

  • Hero Member
  • *****
  • Posts: 3555
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Reseting the mouse?
« Reply #1 on: September 13, 2010, 07:42:05 AM »
detects only single clicks:
Code: [Select]
SCREEN _SCREENIMAGE
mcc = 0
DO
    DO
        IF _MOUSEINPUT THEN
            lmb = _MOUSEBUTTON(1)
            IF lmb THEN
                mouseclicked% = -1
                lmbca = -1
                DO
                    IF _MOUSEINPUT THEN
                        lmbca = _MOUSEBUTTON(1)
                    END IF
                LOOP UNTIL lmbca = 0
            END IF
        ELSE
            EXIT DO
        END IF
    LOOP
    IF mouseclicked% THEN
        mcc = mcc + 1
        PRINT "mouseclick detected"; mcc
        mouseclicked% = 0
    END IF
LOOP UNTIL INKEY$ > ""
detects double clicks:
Code: [Select]
SCREEN _SCREENIMAGE
msc = 0
mdc = 0
lastclicktime# = -1
doubleclickthreshhold# = .25
DO
    DO
        IF _MOUSEINPUT THEN
            lmb = _MOUSEBUTTON(1)
            IF lmb THEN
                mouseclicked% = -1
                lmbca = -1
                DO
                    IF _MOUSEINPUT THEN
                        lmbca = _MOUSEBUTTON(1)
                    END IF
                LOOP UNTIL lmbca = 0
            END IF
        ELSE
            EXIT DO
        END IF
    LOOP
    IF mouseclicked% THEN
        tclick# = TIMER
        IF ABS(tclick# - lastclicktime#) < doubleclickthreshhold# THEN
            mdc = mdc + 1
            PRINT "double click detected"; mdc
        ELSE
            msc = msc + 1
            PRINT "mouseclick detected"; msc
        END IF
        mouseclicked% = 0
        lastclicktime# = tclick#
    END IF
LOOP UNTIL INKEY$ > ""
this last edit was to keep zom-b from KILLING me for changing his screen resolution. copies windows' current screen into a new screen for a funky effect!
this is poor a$$ form, but it just might work for ya!
« Last Edit: September 13, 2010, 08:04:19 AM by codeguy »

Pete

  • Moderator
  • Hero Member
  • *****
  • Posts: 6263
  • Cuz I sez so varmint!
Re: Reseting the mouse?
« Reply #2 on: September 13, 2010, 08:06:14 AM »

There are two ways to do this.

1) As codeguy suggested, make it wait in a loop until the then mouse button is 0 again,

2) Set a variable that triggers a time delay in the program loop. This means that your action takes place immediately when the lbm is pressed, but a delay also takes place, before the computer can move your opponent.

The advantage of 2 over 1 is that the user might learn he can just hold down the mouse button to pause the action.

Mouse routines use status checks to track if the mouse is pressed and released, as some functions work when the button is pressed, and other only kick in after it is released.

Good luck with your game,

Pete
It's only rocket science; it's not Linux!

Zom-B

  • Hero Member
  • *****
  • Posts: 545
Re: Reseting the mouse?
« Reply #3 on: September 13, 2010, 08:45:07 AM »
The examples codeguy posted actually wait until the mouse button is depressed, so nothing else can happen in that time.

A better way is to check if the button is pressed but was not pressed in the previous check. Use a single temp variable for this.

lastButton%=_MouseButton(1)
DO
  ' put your main program stuff here

  WHILE _MOUSEINPUT
    IF _MOUSEBUTTON(1) AND NOT lastButton% THEN
      ' Place your enemy
    END IF
    lastButton% = _MOUSEBUTTON(1) ' Remember last value for next check
  WEND
LOOP
« Last Edit: September 13, 2010, 02:57:43 PM by Zom-B »

Clippy

  • Hero Member
  • *****
  • Posts: 16446
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Reseting the mouse?
« Reply #4 on: September 13, 2010, 09:02:51 AM »
That is EXACTLY why QB64 needs function AX = 5 and 6 type of reads!

Those Absolute or Interrupt functions tell you when a click was made and the location can be recorded. Then you wait until the 6 function says that the button was released and if it is still on the button location.

So far, we don't even have a mouse MOVE function, which could AT LEAST get the mouse OFF of that button's location.

BTW ZomB, you used _MOUSEINPUT instead of _MOUSEBUTTON(1)  :D
« Last Edit: September 13, 2010, 09:32:11 AM by Clippy »
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

codeguy

  • Hero Member
  • *****
  • Posts: 3555
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Reseting the mouse?
« Reply #5 on: September 13, 2010, 10:02:52 AM »
check this code out. it does not waste inordinate amounts of time in loop! and keeps track of changes in the major mouse functions (movements of cursor, mouse clicks (l+r) and mouse wheel) also has individual elapsed time threshholds for (l,r,(l+r))mouse button clicks. this is the original code i modified for pete's program. it is rather plain, but is a demo to show this code works correctly. this is the code you should use and modify for your programs. i find it rather more efficient just to "inject" program execution at the end of this code (replace the text display with your own code). this eliminates the potential problem of passing and declaring shared/common variables to begin with. correctly tracks single and double clicks, drags with the left or right mouse buttons. and other nice things. check out the type declarations to get a good picture of what this program tracks. nothing but the BEST from this hero member (codeguy)
Code: [Select]
const MouseLB%=1
const MouseRb%=2
const Mousebb%=3
const CursorActX=1
const CursorActY=2
const DragLmb%=1
const DragRmb%=2
const DragBoth%=3
TYPE Mouserecord
LmbPressed AS DOUBLE
RmbPressed AS DOUBLE
BothPressed AS DOUBLE
lmbThreshhold AS DOUBLE
rmbthreshhold AS DOUBLE
boththreshhold AS DOUBLE
lmbdblclickthreshhold AS DOUBLE
rmbdblclickthreshhold AS DOUBLE
bothdblclickthreshhold AS DOUBLE
countrmbsingle AS LONG
countlmbsingle AS LONG
countbothsingle AS LONG
countlmbdouble AS LONG
countrmbdouble AS LONG
countbothdouble AS LONG
dbllmb AS INTEGER
dblrmb AS INTEGER
dblboth AS INTEGER
MouseX AS INTEGER
MouseY AS INTEGER
ActionX AS INTEGER
ActionY AS INTEGER
MouseStateLmb AS INTEGER
MouseStateRmb AS INTEGER
MouseStateBoth AS INTEGER
MouseDragLmbXStart AS INTEGER
MouseDragLmbYStart AS INTEGER
MouseDragLmbXEnd AS INTEGER
MouseDragLmbYEnd AS INTEGER
MouseDragRmbXStart AS INTEGER
MouseDragRmbYStart AS INTEGER
MouseDragRmbXEnd AS INTEGER
MouseDragRmbYEnd AS INTEGER
MouseDragBothXStart AS INTEGER
MouseDragBothYStart AS INTEGER
MouseDragBothXEnd AS INTEGER
MouseDragBothYEnd AS INTEGER
Mwheeldirect AS INTEGER
END TYPE
DIM CMouseRec AS Mouserecord
DIM OMouseRec AS Mouserecord
CMouseRec.LmbPressed = 0
CMouseRec.RmbPressed = 0
CMouseRec.BothPressed = 0
CMouseRec.lmbThreshhold = .25
CMouseRec.rmbthreshhold = .25
CMouseRec.boththreshhold = .25
CMouseRec.lmbdblclickthreshhold = .20
CMouseRec.rmbdblclickthreshhold = .20
CMouseRec.bothdblclickthreshhold = .20
CursorAction% = 0
SCREEN _SCREENIMAGE
DO
    DO
        mousert& = mousert& + 1
        IF _MOUSEINPUT THEN
            CMouseRec.MouseX = _MOUSEX
            CMouseRec.MouseY = _MOUSEY
            wheel% = _MOUSEWHEEL
            IF wheel% THEN
                CMouseRec.Mwheeldirect = CMouseRec.Mwheeldirect + wheel%
            END IF
            IF CMouseRec.Mwheeldirect <> OMouseRec.Mwheeldirect OR CMouseRec.Mwheeldirect <> 0 THEN
                '* put your mousewheel handling code here
                IF CMouseRec.Mwheeldirect < OMouseRec.Mwheeldirect THEN
                ELSE
                END IF
                OMouseRec.Mwheeldirect = CMouseRec.Mwheeldirect
            END IF
            IF CMouseRec.MouseX <> OMouseRec.MouseX THEN
                CMouseRec.ActionX = Cursoractx
                deltamousex% = CMouseRec.MouseX - OMouseRec.MouseX
                OMouseRec.MouseX = CMouseRec.MouseX
                CursorAction% = Cursoractx
            END IF
            IF CMouseRec.MouseY <> OMouseRec.MouseY THEN
                CMouseRec.ActionY = Cursoracty
                deltamousey% = CMouseRec.MouseY - OMouseRec.MouseY
                OMouseRec.MouseY = CMouseRec.MouseY
                CursorAction% = Cursoracty
            END IF
            IF CursortAction% THEN
                '* put your mouse cursor movement code here
                CursorAction% = 0
            END IF
            anybuttonpressed% = 0
            TimeHold# = TIMER

            mb3% = _MOUSEBUTTON(3)
            IF mb3% THEN
                anybuttonpressed% = Mousebb%
                CMouseRec.BothPressed = TimeHold#
                CMouseRec.MouseStateBoth = mb3%
            ELSE
                mb1% = _MOUSEBUTTON(1)
                IF mb1% THEN
                    anybuttonpressed% = Mouselb%
                    CMouseRec.LmbPressed = TimeHold#
                    CMouseRec.MouseStateLmb = mb1%
                END IF
                mb2% = _MOUSEBUTTON(2)
                IF mb2% THEN
                    anybuttonpressed% = Mouserb%
                    CMouseRec.RmbPressed = TimeHold#
                    CMouseRec.MouseStateRmb = mb2%
                END IF
            END IF

            SELECT CASE anybuttonpressed%
                CASE Mousebb%
                    IF ABS(CMouseRec.BothPressed - OMouseRec.BothPressed) > CMouseRec.boththreshhold THEN
                        CMouseRec.dblboth = 0
                        CMouseRec.countbothsingle = CMouseRec.countbothsingle + 1
                        OMouseRec.MouseStateBoth = NOT (CMouseRec.MouseStateBoth)
                        CMouseRec.MouseDragBothXStart = -1
                        CMouseRec.MouseDragBothYStart = -1
                    ELSE
                        IF ABS(CMouseRec.BothPressed - OMouseRec.BothPressed) >= CMouseRec.bothdblclickthreshhold THEN
                            CMouseRec.dblboth = -1
                            CMouseRec.countbothdouble = CMouseRec.countbothdouble + 1
                        ELSE
                            IF CMouseRec.MouseStateBoth <> OMouseRec.MouseStateBoth OR -1 THEN
                                IF CMouseRec.MouseStateBoth = OMouseRec.MouseStateBoth THEN
                                    IF CMouseRec.MouseDragBothXStart = -1 THEN
                                        CMouseRec.MouseDragBothXStart = CMouseRec.MouseX
                                        CMouseRec.MouseDragBothYStart = CMouseRec.MouseY
                                    ELSE
                                        CMouseRec.MouseDragBothXEnd = CMouseRec.MouseX
                                        CMouseRec.MouseDragBothYEnd = CMouseRec.MouseY
                                    END IF
                                    LOCATE 4, 1
                                    PRINT USING "sb(x####:y####) eb(x####:y####)"; CMouseRec.MouseDragBothXStart, CMouseRec.MouseDragBothYStart, CMouseRec.MouseDragBothXEnd, CMouseRec.MouseDragBothYEnd
                                ELSE
                                    OMouseRec.MouseStateBoth = CMouseRec.MouseStateBoth
                                    CMouseRec.MouseDragBothXStart = -1
                                    CMouseRec.MouseDragBothYStart = -1
                                END IF
                            END IF
                        END IF
                    END IF
                    OMouseRec.BothPressed = TimeHold#
                CASE Mouselb%
                    IF ABS(CMouseRec.LmbPressed - OMouseRec.LmbPressed) > CMouseRec.lmbThreshhold THEN
                        CMouseRec.dbllmb = 0
                        CMouseRec.countlmbsingle = CMouseRec.countlmbsingle + 1
                        OMouseRec.MouseStateLmb = NOT (CMouseRec.MouseStateLmb)
                        CMouseRec.MouseDragLmbXStart = -1
                        CMouseRec.MouseDragLmbYStart = -1
                    ELSE
                        IF ABS(CMouseRec.LmbPressed - OMouseRec.LmbPressed) >= CMouseRec.lmbdblclickthreshhold THEN
                            CMouseRec.dbllmb = -1
                            CMouseRec.countlmbdouble = CMouseRec.countlmbdouble + 1
                        ELSE
                            IF CMouseRec.MouseStateLmb <> OMouseRec.MouseStateLmb OR -1 THEN
                                IF CMouseRec.MouseStateLmb = OMouseRec.MouseStateLmb THEN
                                    IF CMouseRec.MouseDragLmbXStart = -1 THEN
                                        CMouseRec.MouseDragLmbXStart = CMouseRec.MouseX
                                        CMouseRec.MouseDragLmbYStart = CMouseRec.MouseY
                                    ELSE
                                        CMouseRec.MouseDragLmbXEnd = CMouseRec.MouseX
                                        CMouseRec.MouseDragLmbYEnd = CMouseRec.MouseY
                                    END IF
                                    LOCATE 5, 1
                                    PRINT USING "sl(x####:y####) el(x####:y####)"; CMouseRec.MouseDragLmbXStart, CMouseRec.MouseDragLmbYStart, CMouseRec.MouseDragLmbXEnd, CMouseRec.MouseDragLmbYEnd
                                ELSE
                                    OMouseRec.MouseStateLmb = CMouseRec.MouseStateLmb
                                    CMouseRec.MouseDragLmbXStart = -1
                                    CMouseRec.MouseDragLmbYStart = -1
                                END IF
                            END IF
                        END IF
                    END IF
                    OMouseRec.LmbPressed = TimeHold#
                CASE Mouserb%
                    IF ABS(CMouseRec.RmbPressed - OMouseRec.RmbPressed) > CMouseRec.rmbthreshhold THEN
                        CMouseRec.dblrmb = 0
                        CMouseRec.countrmbsingle = CMouseRec.countrmbsingle + 1
                        OMouseRec.MouseStateRmb = NOT (CMouseRec.MouseStateRmb)
                        CMouseRec.MouseDragRmbXStart = -1
                        CMouseRec.MouseDragRmbYStart = -1
                    ELSE
                        IF ABS(CMouseRec.RmbPressed - OMouseRec.RmbPressed) >= CMouseRec.rmbdblclickthreshhold THEN
                            CMouseRec.dblrmb = -1
                            CMouseRec.countrmbdouble = CMouseRec.countrmbdouble + 1
                        ELSE
                            IF CMouseRec.MouseStateRmb <> OMouseRec.MouseStateRmb OR -1 THEN
                                IF CMouseRec.MouseStateRmb = OMouseRec.MouseStateRmb THEN
                                    IF CMouseRec.MouseDragRmbXStart = -1 THEN
                                        CMouseRec.MouseDragRmbXStart = CMouseRec.MouseX
                                        CMouseRec.MouseDragRmbYStart = CMouseRec.MouseY
                                    ELSE
                                        CMouseRec.MouseDragRmbXEnd = CMouseRec.MouseX
                                        CMouseRec.MouseDragRmbYEnd = CMouseRec.MouseY
                                    END IF
                                    LOCATE 6, 1
                                    PRINT USING "sr(x####:y####) er(x####:y####)"; CMouseRec.MouseDragRmbXStart, CMouseRec.MouseDragRmbYStart, CMouseRec.MouseDragRmbXEnd, CMouseRec.MouseDragRmbYEnd
                                ELSE
                                    OMouseRec.MouseStateRmb = CMouseRec.MouseStateRmb
                                    CMouseRec.MouseDragRmbXStart = -1
                                    CMouseRec.MouseDragRmbYStart = -1
                                END IF
                            END IF
                        END IF
                    END IF
                    OMouseRec.RmbPressed = TimeHold#
                CASE ELSE
                    EXIT DO
            END SELECT
        ELSE
            EXIT DO
        END IF
    LOOP
    execute& = execute& + 1
    LOCATE 2, 1: PRINT USING "executed ################: mouse #################"; execute&; mousert&;
    LOCATE 7, 1
    PRINT USING "(x####:y####)"; CMouseRec.MouseX; CMouseRec.MouseY
    LOCATE 8, 1
    PRINT USING "double-clicks l(#######) r(######) both(######) "; CMouseRec.countlmbdouble, CMouseRec.countrmbdouble, CMouseRec.countbothdouble
    LOCATE 9, 1
    PRINT USING "single-clicks l(#######) r(######) both(######) "; CMouseRec.countlmbsingle, CMouseRec.countrmbsingle, CMouseRec.countbothsingle
    LOCATE 10, 1
    PRINT USING "Mouse Wheel(#####)"; CMouseRec.Mwheeldirect
    LOCATE 11, 1
    PRINT USING "d(x####:y####)"; deltamousex%, deltamousey%
LOOP UNTIL INKEY$ > ""
« Last Edit: September 16, 2010, 01:37:11 AM by codeguy »

Pete

  • Moderator
  • Hero Member
  • *****
  • Posts: 6263
  • Cuz I sez so varmint!
Re: Reseting the mouse?
« Reply #6 on: September 13, 2010, 10:51:58 AM »
Hey UNSEEN... It's a shame you left SCREEN 0 !!!!

Something I just cooked up...

Code: [Select]
DECLARE SUB mouse (ex%)

REM Type decalar for CALL ABSOLUTE mouse
TYPE RegType
    AX AS INTEGER
    BX AS INTEGER
    CX AS INTEGER
    DX AS INTEGER
    BP AS INTEGER
    SI AS INTEGER
    DI AS INTEGER
    FLAGS AS INTEGER
    DS AS INTEGER
    ES AS INTEGER
END TYPE

DIM SHARED Registers AS RegType
DIM SHARED lb%, rb%

REM Size Window
style$ = "MONOSPACE"
fontsize% = 21
fontpath$ = ENVIRON$("SYSTEMROOT") + "\fonts\lucon.ttf" 'Find Windows Folder Path.
currentf& = _LOADFONT(fontpath$, fontsize%, style$)
_FONT currentf&

REM Print Playing Surface.
CLS
LOCATE , , 0, 7, 0
LOCATE 1, 30: PRINT "Super Mario Only Child"
LOCATE 25, 1: PRINT " Press Left Mouse Button to Jump Happy Over or On Top of the Bombs. Esc = Quit.";
LOCATE 10, 20: PRINT CHR$(148); : LOCATE 10, 35: PRINT CHR$(148); : LOCATE 10, 50: PRINT CHR$(148); : LOCATE 10, 65: PRINT CHR$(148);
LOCATE 5, 77: COLOR 9: PRINT CHR$(8); : COLOR 7: PRINT "|"
LOCATE 6, 77: PRINT " |"
LOCATE 7, 76: PRINT "^ | ^";
LOCATE 8, 76: PRINT CHR$(176); CHR$(176); CHR$(176); CHR$(176); CHR$(176);
LOCATE 9, 76: PRINT CHR$(176); CHR$(176); CHR$(176); CHR$(176); CHR$(176);
LOCATE 10, 76: PRINT "|"; CHR$(176); CHR$(239); CHR$(176); "|";
COLOR 4: LOCATE 11, 1: PRINT STRING$(80, 196);
COLOR 7
LOCATE 10, 3: PRINT CHR$(2);
LOCATE 10, 3
SLEEP 2

REM Initiate and Show Mouse
ex% = 1: CALL mouse(ex%)

REM Play
DO
    ex% = 2: CALL mouse(ex%)
    SELECT CASE lb%
        CASE 1: IF mousestatus% = 0 THEN mousestatus% = -1 ELSE mousestatus% = 1
        CASE 0: mousestatus% = 0
    END SELECT

    REM Unremark if you want to view mousestatus%
    REM xx = CSRLIN: yy = POS(1): LOCATE 3, 1: PRINT mousestatus%: LOCATE xx, yy

    REM If left Mouse Button is Pressed, Jump!
    IF mousestatus% = -1 THEN
        IF jump% = 0 THEN
            jump% = -2: junpheight% = -1
            LOCATE , POS(1) - 1: PRINT " "; : LOCATE 8
        END IF
    END IF

    REM If Time Elapsed, Move!
    IF playermove% = -1 THEN
        playermove% = 0
        IF POS(1) < 2 THEN i% = 0 ELSE i% = 1
        LOCATE 10 + junpheight%, POS(1) - i%: PRINT " " + CHR$(2);

        REM If in Air, Descend!
        IF jump% < 0 THEN
            jump% = jump% + 1
            IF jump% = 0 THEN junpheight% = 0: LOCATE , POS(1) - 1: PRINT " ";
        END IF

        REM Winner!
        IF POS(1) > 75 THEN LOCATE 15, 37: PRINT "You Won!": EXIT DO
    END IF

    REM Evaluate
    IF POS(1) >= 20 THEN
        xy% = SCREEN(CSRLIN, POS(1), 0)
        IF xy% <> 32 THEN
            SELECT CASE jump%
                CASE 0
                    LOCATE 15, 36: PRINT "Game Over!": EXIT DO
                CASE ELSE

            END SELECT
        END IF
    END IF

    REM Time Delay
    IF ABS(z1 - TIMER) > .2 THEN playermove% = -1: z1 = TIMER
    _LIMIT 100
LOOP UNTIL INKEY$ = CHR$(27)
ex% = -1: CALL mouse(ex%)

END


SUB mouse (ex%)
STATIC mousestate%

REM INITIATE MOUSE
IF moustact = 0 THEN
    Registers.AX = 0: GOSUB calli
    mousestate% = 1
END IF

IF ex% = 1 THEN
    Registers.AX = 1: GOSUB calli
    EXIT SUB
END IF

IF ex% = -1 THEN
    REM HIDES MOUSE IF A KEY WAS PRESSED FOR NEXT MOUSE LOOP
    Registers.AX = 2: GOSUB calli
    EXIT SUB
END IF

Registers.AX = 3: GOSUB calli

DX = Registers.DX
CX = Registers.CX
REM MOUSE LOCATION (USES X AND Y TO CONVERT TO 25 * 80 SCREEN SIZE)
x = DX \ 8 + 1: y = CX \ 8 + 1

REM MOUSE BUTTONS
lb% = Registers.BX AND 1
rb% = (Registers.BX AND 2) \ 2
EXIT SUB

calli:
CALL INTERRUPT(&H33, Registers, Registers)
RETURN

END SUB

--------------------------------

I was looking for an example, and figured I could code one faster than I could find one... Besides, I hate to look, and I love to code.

Pete  ;D
It's only rocket science; it's not Linux!

unseenmachine

  • Hero Member
  • *****
  • Posts: 3285
  • A fish, a fish, a fishy o!
Re: Reseting the mouse?
« Reply #7 on: September 13, 2010, 10:59:04 AM »
Thanks for all the replies, i am going to try them out tonight.

Quote
The advantage of 2 over 1 is that the user might learn he can just hold down the mouse button to pause the action.

Mouse routines use status checks to track if the mouse is pressed and released, as some functions work when the button is pressed, and other only kick in after it is released.

Good luck with your game,

Thanks pete, but it's not a game. Though it does make mario games, or it will do when i finish it. I should have the eidtor done within the next week or so, then i can work on the actual code for the game that the editor makes, gonna be a lot of PRINT #1!!!!!. Here's a screen shot of the editor

(http://img266.imageshack.us/img266/1051/mariomakerscrnshot1.th.png)
 

Pete

  • Moderator
  • Hero Member
  • *****
  • Posts: 6263
  • Cuz I sez so varmint!
Re: Reseting the mouse?
« Reply #8 on: September 13, 2010, 11:03:15 AM »

That looks really, really, good. Well, try my mouse routine, as it does incorporate a way to register a mouse click and not register it again until the mouse button is released, all while letting the program flow continue.

Pete

PS Please don't be jealous that my SCREEN 0 Mario will always look better than any graphics screen version imaginable. SCREEN 0 Rules!  ;D
It's only rocket science; it's not Linux!

Clippy

  • Hero Member
  • *****
  • Posts: 16446
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Reseting the mouse?
« Reply #9 on: September 13, 2010, 11:12:11 AM »
Nevermind

I was wondering how you got that smiley, but then I saw the font.

« Last Edit: September 13, 2010, 12:00:19 PM by Clippy »
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

Pete

  • Moderator
  • Hero Member
  • *****
  • Posts: 6263
  • Cuz I sez so varmint!
Re: Reseting the mouse?
« Reply #10 on: September 13, 2010, 11:19:30 AM »
It was totally worth posting that comment, just to have Clippy nearly speechless.

Pete ;D
It's only rocket science; it's not Linux!

codeguy

  • Hero Member
  • *****
  • Posts: 3555
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Reseting the mouse?
« Reply #11 on: September 13, 2010, 12:33:50 PM »
this one does the whole shebang:
left and right and both (code still in here but uncalled. mouse buttons, dragging and clicking. it's a friggin' monster. i felt like i was writing at least an entire mouse driver. this one now shows the CORRECT mousewheel accumulator too. holy cr@p, what a complicated mess! and i think contrary to Zom-B's opinion, i think the numbers would be unequal if it spent time looping in the mouse detection routine while dragging. try holding down the mousebutton and "dragging," which if it acted as zom-b states, the balance of the execution numbers (mousert&, execute&) would change pretty drastically. i designed this to be as non-modal as possible so it wouldn't unnecessarily slow execution of the other code, which in this case is simply a labeled numerical display.
Code: [Select]
const MouseLB%=1
const MouseRb%=2
const Mousebb%=3
const CursorActX=1
const CursorActY=2
const DragLmb%=1
const DragRmb%=2
const DragBoth%=3
TYPE Mouserecord
LmbPressed AS DOUBLE
RmbPressed AS DOUBLE
BothPressed AS DOUBLE
lmbThreshhold AS DOUBLE
rmbthreshhold AS DOUBLE
boththreshhold AS DOUBLE
lmbdblclickthreshhold AS DOUBLE
rmbdblclickthreshhold AS DOUBLE
bothdblclickthreshhold AS DOUBLE
countrmbsingle AS LONG
countlmbsingle AS LONG
countbothsingle AS LONG
countlmbdouble AS LONG
countrmbdouble AS LONG
countbothdouble AS LONG
dbllmb AS INTEGER
dblrmb AS INTEGER
dblboth AS INTEGER
MouseX AS INTEGER
MouseY AS INTEGER
ActionX AS INTEGER
ActionY AS INTEGER
MouseStateLmb AS INTEGER
MouseStateRmb AS INTEGER
MouseStateBoth AS INTEGER
MouseDragLmbXStart AS INTEGER
MouseDragLmbYStart AS INTEGER
MouseDragLmbXEnd AS INTEGER
MouseDragLmbYEnd AS INTEGER
MouseDragRmbXStart AS INTEGER
MouseDragRmbYStart AS INTEGER
MouseDragRmbXEnd AS INTEGER
MouseDragRmbYEnd AS INTEGER
MouseDragBothXStart AS INTEGER
MouseDragBothYStart AS INTEGER
MouseDragBothXEnd AS INTEGER
MouseDragBothYEnd AS INTEGER
Mwheeldirect AS INTEGER
END TYPE
DIM CMouseRec AS Mouserecord
DIM OMouseRec AS Mouserecord
CMouseRec.LmbPressed = 0
CMouseRec.RmbPressed = 0
CMouseRec.BothPressed = 0
CMouseRec.lmbThreshhold = .25
CMouseRec.rmbthreshhold = .25
CMouseRec.boththreshhold = .25
CMouseRec.lmbdblclickthreshhold = .20
CMouseRec.rmbdblclickthreshhold = .20
CMouseRec.bothdblclickthreshhold = .20
CursorAction% = 0
SCREEN _SCREENIMAGE
DO
    DO
        mousert& = mousert& + 1
        IF _MOUSEINPUT THEN
            CMouseRec.MouseX = _MOUSEX
            CMouseRec.MouseY = _MOUSEY
            wheel% = _MOUSEWHEEL
            IF wheel% THEN
                CMouseRec.Mwheeldirect = CMouseRec.Mwheeldirect + wheel%
            END IF
            IF CMouseRec.Mwheeldirect <> OMouseRec.Mwheeldirect OR CMouseRec.Mwheeldirect <> 0 THEN
                '* put your mousewheel handling code here
                IF CMouseRec.Mwheeldirect < OMouseRec.Mwheeldirect THEN
                ELSE
                END IF
                OMouseRec.Mwheeldirect = CMouseRec.Mwheeldirect
            END IF
            IF CMouseRec.MouseX <> OMouseRec.MouseX THEN
                CMouseRec.ActionX = Cursoractx
                deltamousex% = CMouseRec.MouseX - OMouseRec.MouseX
                OMouseRec.MouseX = CMouseRec.MouseX
                CursorAction% = Cursoractx
            END IF
            IF CMouseRec.MouseY <> OMouseRec.MouseY THEN
                CMouseRec.ActionY = Cursoracty
                deltamousey% = CMouseRec.MouseY - OMouseRec.MouseY
                OMouseRec.MouseY = CMouseRec.MouseY
                CursorAction% = Cursoracty
            END IF
            IF CursortAction% THEN
                '* put your mouse cursor movement code here
                CursorAction% = 0
            END IF
            anybuttonpressed% = 0
            TimeHold# = TIMER

            mb3% = _MOUSEBUTTON(3)
            IF mb3% THEN
                anybuttonpressed% = Mousebb%
                CMouseRec.BothPressed = TimeHold#
                CMouseRec.MouseStateBoth = mb3%
            ELSE
                mb1% = _MOUSEBUTTON(1)
                IF mb1% THEN
                    anybuttonpressed% = Mouselb%
                    CMouseRec.LmbPressed = TimeHold#
                    CMouseRec.MouseStateLmb = mb1%
                END IF
                mb2% = _MOUSEBUTTON(2)
                IF mb2% THEN
                    anybuttonpressed% = Mouserb%
                    CMouseRec.RmbPressed = TimeHold#
                    CMouseRec.MouseStateRmb = mb2%
                END IF
            END IF

            SELECT CASE anybuttonpressed%
                CASE Mousebb%
                    IF ABS(CMouseRec.BothPressed - OMouseRec.BothPressed) > CMouseRec.boththreshhold THEN
                        CMouseRec.dblboth = 0
                        CMouseRec.countbothsingle = CMouseRec.countbothsingle + 1
                        OMouseRec.MouseStateBoth = NOT (CMouseRec.MouseStateBoth)
                        CMouseRec.MouseDragBothXStart = -1
                        CMouseRec.MouseDragBothYStart = -1
                    ELSE
                        IF ABS(CMouseRec.BothPressed - OMouseRec.BothPressed) >= CMouseRec.bothdblclickthreshhold THEN
                            CMouseRec.dblboth = -1
                            CMouseRec.countbothdouble = CMouseRec.countbothdouble + 1
                        ELSE
                            IF CMouseRec.MouseStateBoth <> OMouseRec.MouseStateBoth OR -1 THEN
                                IF CMouseRec.MouseStateBoth = OMouseRec.MouseStateBoth THEN
                                    IF CMouseRec.MouseDragBothXStart = -1 THEN
                                        CMouseRec.MouseDragBothXStart = CMouseRec.MouseX
                                        CMouseRec.MouseDragBothYStart = CMouseRec.MouseY
                                    ELSE
                                        CMouseRec.MouseDragBothXEnd = CMouseRec.MouseX
                                        CMouseRec.MouseDragBothYEnd = CMouseRec.MouseY
                                    END IF
                                    LOCATE 4, 1
                                    PRINT USING "sb(x####:y####) eb(x####:y####)"; CMouseRec.MouseDragBothXStart, CMouseRec.MouseDragBothYStart, CMouseRec.MouseDragBothXEnd, CMouseRec.MouseDragBothYEnd
                                ELSE
                                    OMouseRec.MouseStateBoth = CMouseRec.MouseStateBoth
                                    CMouseRec.MouseDragBothXStart = -1
                                    CMouseRec.MouseDragBothYStart = -1
                                END IF
                            END IF
                        END IF
                    END IF
                    OMouseRec.BothPressed = TimeHold#
                CASE Mouselb%
                    IF ABS(CMouseRec.LmbPressed - OMouseRec.LmbPressed) > CMouseRec.lmbThreshhold THEN
                        CMouseRec.dbllmb = 0
                        CMouseRec.countlmbsingle = CMouseRec.countlmbsingle + 1
                        OMouseRec.MouseStateLmb = NOT (CMouseRec.MouseStateLmb)
                        CMouseRec.MouseDragLmbXStart = -1
                        CMouseRec.MouseDragLmbYStart = -1
                    ELSE
                        IF ABS(CMouseRec.LmbPressed - OMouseRec.LmbPressed) >= CMouseRec.lmbdblclickthreshhold THEN
                            CMouseRec.dbllmb = -1
                            CMouseRec.countlmbdouble = CMouseRec.countlmbdouble + 1
                        ELSE
                            IF CMouseRec.MouseStateLmb <> OMouseRec.MouseStateLmb OR -1 THEN
                                IF CMouseRec.MouseStateLmb = OMouseRec.MouseStateLmb THEN
                                    IF CMouseRec.MouseDragLmbXStart = -1 THEN
                                        CMouseRec.MouseDragLmbXStart = CMouseRec.MouseX
                                        CMouseRec.MouseDragLmbYStart = CMouseRec.MouseY
                                    ELSE
                                        CMouseRec.MouseDragLmbXEnd = CMouseRec.MouseX
                                        CMouseRec.MouseDragLmbYEnd = CMouseRec.MouseY
                                    END IF
                                    LOCATE 5, 1
                                    PRINT USING "sl(x####:y####) el(x####:y####)"; CMouseRec.MouseDragLmbXStart, CMouseRec.MouseDragLmbYStart, CMouseRec.MouseDragLmbXEnd, CMouseRec.MouseDragLmbYEnd
                                ELSE
                                    OMouseRec.MouseStateLmb = CMouseRec.MouseStateLmb
                                    CMouseRec.MouseDragLmbXStart = -1
                                    CMouseRec.MouseDragLmbYStart = -1
                                END IF
                            END IF
                        END IF
                    END IF
                    OMouseRec.LmbPressed = TimeHold#
                CASE Mouserb%
                    IF ABS(CMouseRec.RmbPressed - OMouseRec.RmbPressed) > CMouseRec.rmbthreshhold THEN
                        CMouseRec.dblrmb = 0
                        CMouseRec.countrmbsingle = CMouseRec.countrmbsingle + 1
                        OMouseRec.MouseStateRmb = NOT (CMouseRec.MouseStateRmb)
                        CMouseRec.MouseDragRmbXStart = -1
                        CMouseRec.MouseDragRmbYStart = -1
                    ELSE
                        IF ABS(CMouseRec.RmbPressed - OMouseRec.RmbPressed) >= CMouseRec.rmbdblclickthreshhold THEN
                            CMouseRec.dblrmb = -1
                            CMouseRec.countrmbdouble = CMouseRec.countrmbdouble + 1
                        ELSE
                            IF CMouseRec.MouseStateRmb <> OMouseRec.MouseStateRmb OR -1 THEN
                                IF CMouseRec.MouseStateRmb = OMouseRec.MouseStateRmb THEN
                                    IF CMouseRec.MouseDragRmbXStart = -1 THEN
                                        CMouseRec.MouseDragRmbXStart = CMouseRec.MouseX
                                        CMouseRec.MouseDragRmbYStart = CMouseRec.MouseY
                                    ELSE
                                        CMouseRec.MouseDragRmbXEnd = CMouseRec.MouseX
                                        CMouseRec.MouseDragRmbYEnd = CMouseRec.MouseY
                                    END IF
                                    LOCATE 6, 1
                                    PRINT USING "sr(x####:y####) er(x####:y####)"; CMouseRec.MouseDragRmbXStart, CMouseRec.MouseDragRmbYStart, CMouseRec.MouseDragRmbXEnd, CMouseRec.MouseDragRmbYEnd
                                ELSE
                                    OMouseRec.MouseStateRmb = CMouseRec.MouseStateRmb
                                    CMouseRec.MouseDragRmbXStart = -1
                                    CMouseRec.MouseDragRmbYStart = -1
                                END IF
                            END IF
                        END IF
                    END IF
                    OMouseRec.RmbPressed = TimeHold#
                CASE ELSE
                    EXIT DO
            END SELECT
        ELSE
            EXIT DO
        END IF
    LOOP
    execute& = execute& + 1
    LOCATE 2, 1: PRINT USING "executed ################: mouse #################"; execute&; mousert&;
    LOCATE 7, 1
    PRINT USING "(x####:y####)"; CMouseRec.MouseX; CMouseRec.MouseY
    LOCATE 8, 1
    PRINT USING "double-clicks l(#######) r(######) both(######) "; CMouseRec.countlmbdouble, CMouseRec.countrmbdouble, CMouseRec.countbothdouble
    LOCATE 9, 1
    PRINT USING "single-clicks l(#######) r(######) both(######) "; CMouseRec.countlmbsingle, CMouseRec.countrmbsingle, CMouseRec.countbothsingle
    LOCATE 10, 1
    PRINT USING "Mouse Wheel(#####)"; CMouseRec.Mwheeldirect
    LOCATE 11, 1
    PRINT USING "d(x####:y####)"; deltamousex%, deltamousey%
LOOP UNTIL INKEY$ > ""
the only change with this version is the addition of a parameter for double-click time. of course, simultaneous mousebutton presses are not captured, as i suspected all along, but i just wanted to include the code just in case someone asked. i think this is a thorough enough program that it could be made into a sub or function and used somehow or pasted as is. this was a complicated mess and i knew of no simpler way without using interrupts. the double-click delays for left and right buttons can be set individually. take out out references to both-button mouse parameters and the prints and such and this is a working program ready to be made into a sub!
« Last Edit: September 13, 2010, 02:58:27 PM by codeguy »

Pete

  • Moderator
  • Hero Member
  • *****
  • Posts: 6263
  • Cuz I sez so varmint!
Re: Reseting the mouse?
« Reply #12 on: September 13, 2010, 12:59:27 PM »

Yes, drag is a drag! That was one of the last mouse features I added. Eventually, you end up with a Windows mouse clone.

Now if we could just get Galleon to make a _SCREEN 0, that included the same lines of resolution as SCREEN 12, wow, how cool would that be?  8) 8) 8)

Pete

 - This post was brought to you by: Members for Screw ON KEY and make _SCREEN 0 (MSOMS-0)
It's only rocket science; it's not Linux!

codeguy

  • Hero Member
  • *****
  • Posts: 3555
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Reseting the mouse?
« Reply #13 on: September 13, 2010, 06:08:53 PM »
and this is pete's game with MY routine: to prove it's fast enough for prime time. it took a while to write this program and get it debugged. in the process, i eliminated some unnecessary variables and made this thing pretty efficient. if you take a look at the code, you'll find that it does a nice job of g]etting things done, even with the extraneous double-button code. now available as an individual sub. this sub allows detection of left or right mouse button based drag! my pain, your gain! please download the unmodified version above as this one had a few mods to run pete's code.
'* CGMouseSub.bi
Code: [Select]
const MouseLB%=1
const MouseRb%=2
const Mousebb%=3
const CursorActX=1
const CursorActY=2
const DragLmb%=1
const DragRmb%=2
const DragBoth%=3
TYPE Mouserecord
LmbPressed AS DOUBLE
RmbPressed AS DOUBLE
BothPressed AS DOUBLE
lmbThreshhold AS DOUBLE
rmbthreshhold AS DOUBLE
boththreshhold AS DOUBLE
lmbdblclickthreshhold AS DOUBLE ' \
rmbdblclickthreshhold AS DOUBLE '  * time-delay to detect double-mouse clicks
bothdblclickthreshhold AS DOUBLE '/
countrmbsingle AS LONG ' \
countlmbsingle AS LONG '   * counts number of times double-clicks are detected
countbothsingle AS LONG '/
countlmbdouble AS LONG
countrmbdouble AS LONG
countbothdouble AS LONG
dbllmb AS INTEGER ' \
dblrmb AS INTEGER '   *  whether press type is left, right or (left+right) simultaneous
dblboth AS INTEGER '/
MouseX AS INTEGER '* current mouse (x,y) coords
MouseY AS INTEGER
ActionX AS INTEGER '* type of mouse movement x or y direction
ActionY AS INTEGER
MouseStateLmb AS INTEGER '* current state of the left mouse button
MouseStateRmb AS INTEGER '* current state of the right mouse button
MouseStateBoth AS INTEGER '* current state of the (left+right) simultaneous mouse button: not yet implemented
MouseDragLmbXStart AS INTEGER '* starting (x,y) coords for dragging using left mouse button
MouseDragLmbYStart AS INTEGER
MouseDragLmbXEnd AS INTEGER '* ending (x,y) coords for dragging using left mouse button
MouseDragLmbYEnd AS INTEGER
MouseDragRmbXStart AS INTEGER '* starting (x,y) coords for dragging using right mouse button
MouseDragRmbYStart AS INTEGER
MouseDragRmbXEnd AS INTEGER '* ending (x,y) coords for dragging using right mouse button
MouseDragRmbYEnd AS INTEGER
MouseDragBothXStart AS INTEGER '* starting (x,y) coords for dragging using (left+right) simultaneous mouse button: not yet implemented
MouseDragBothYStart AS INTEGER
MouseDragBothXEnd AS INTEGER '* ending (x,y) coords for dragging using (left+right) simultaneous mouse button: not yet implemented
MouseDragBothYEnd AS INTEGER
MWheelAccumulator AS INTEGER '* may be useful for scrolling screens & dialog boxes
END TYPE
DIM SHARED CursorAction%, mouselb%, mouserb%, mousebb%, deltamousex%, deltmousey%
DIM SHARED CMouseRec AS Mouserecord
DIM SHARED OMouseRec AS Mouserecord
'* profiling variables
DIM SHARED tsols#, tsolf#, tsils#, tsilf#, execute&, mousert&
CMouseRec.LmbPressed = 0 '* last time left mouse button was pressed
CMouseRec.RmbPressed = 0 '* last time right mouse button was pressed
CMouseRec.BothPressed = 0 '* last time both mouse buttons were pressed simultaneously -- might make a handy shortcut: not yet implemented
CMouseRec.lmbThreshhold = .25 '\
CMouseRec.rmbthreshhold = .25 '  * programmer-adjustable delays for detecting left,right and double mouse button single clicks
CMouseRec.boththreshhold = .25 '/
CMouseRec.lmbdblclickthreshhold = .20 '* programmer-adjustable delays for detecting left,right and double mouse button double clicks
CMouseRec.rmbdblclickthreshhold = .20
CMouseRec.bothdblclickthreshhold = .20
CursorAction% = 0
'*** end of CGMouseSub.bi
'* The Start of PETE'S program!
Code: [Select]
SCREEN 0
REM Print Playing Surface.
REM Size Window
style$ = "MONOSPACE"
fontsize% = 15
fontpath$ = ENVIRON$("SYSTEMROOT") + "\fonts\lucon.ttf" 'Find Windows Folder Path.
currentf& = _LOADFONT(fontpath$, fontsize%, style$)
_FONT currentf&
CLS
LOCATE , , 0, 7, 0
LOCATE 1, 30: PRINT "Super Mario Only Child"
LOCATE 25, 1: PRINT " Press Left Mouse Button to Jump Happy Over or On Top of the Bombs. Esc = Quit.";
LOCATE 10, 20: PRINT CHR$(148);: LOCATE 10, 35: PRINT CHR$(148);: LOCATE 10, 50: PRINT CHR$(148);: LOCATE 10, 65: PRINT CHR$(148);
LOCATE 5, 77: COLOR 9: PRINT CHR$(8);: COLOR 7: PRINT "|"
LOCATE 6, 77: PRINT " |"
LOCATE 7, 76: PRINT "^ | ^";
LOCATE 8, 76: PRINT CHR$(176); CHR$(176); CHR$(176); CHR$(176); CHR$(176);
LOCATE 9, 76: PRINT CHR$(176); CHR$(176); CHR$(176); CHR$(176); CHR$(176);
LOCATE 10, 76: PRINT "|"; CHR$(176); CHR$(239); CHR$(176); "|";
COLOR 4: LOCATE 11, 1: PRINT STRING$(80, 196);
COLOR 7
LOCATE 10, 3: PRINT CHR$(2);
LOCATE 10, 3
SLEEP 2

DO
    tsols# = TIMER
'$include: 'GetMouseParams.bm'
    GetMouseParams
    execute& = execute& + 1
    IF testing THEN
        LOCATE 2, 1: PRINT USING "executed ################: mouse #################"; execute&; mousert&;
        LOCATE 7, 1
        PRINT USING "(x####:y####)"; CMouseRec.MouseX; CMouseRec.MouseY;
        LOCATE 8, 1
        PRINT USING "double-clicks l(#######) r(######) both(######) "; CMouseRec.countlmbdouble, CMouseRec.countrmbdouble, CMouseRec.countbothdouble;
        LOCATE 9, 1
        PRINT USING "single-clicks l(#######) r(######) both(######) "; CMouseRec.countlmbsingle, CMouseRec.countrmbsingle, CMouseRec.countbothsingle;
        LOCATE 10, 1
        PRINT USING "Mouse Wheel(#####)"; CMouseRec.MWheelAccumulator;
        LOCATE 11, 1
        PRINT USING "d(x####:y####)"; deltamousex%, deltamousey%;
        tsolf# = TIMER
        accout# = accout# - tsols# + tsolf#
        LOCATE 12, 1
        PRINT USING "Outer Loop execution #####.############ inner loop execution #####.###############"; accout#; accout# - tsols# + tsolf#;
        LOCATE 13, 1
        PRINT USING "LMB ## RMB ## L+R ##"; CMouseRec.MouseStateLmb; CMouseRec.MouseStateRmb; CMouseRec.MouseStateBoth;
    END IF

    SELECT CASE CMouseRec.MouseStateLmb
        CASE 0
            mousestatus% = 0
        CASE ELSE
            IF mousestatus% = 0 THEN mousestatus% = -1 ELSE mousestatus% = 1
    END SELECT
    time# = TIMER
    IF time# - last# > .2 THEN
        playerMove% = -1
        last# = time#
    END IF
    IF mousestatus% THEN
        IF jump% = 0 THEN
            jump% = -2: junpheight% = -1
            LOCATE , POS(1) - 1: PRINT " ";: LOCATE 8
        END IF
        mousestatus% = 0
    ELSE
        IF jump% < 0 THEN
            jump% = jump% + 1
            IF jump% = 0 THEN junpheight% = 0: LOCATE , POS(1) - 1: PRINT " ";
        END IF
    END IF
    REM If Time Elapsed, Move!
    IF playerMove% = -1 THEN
        playerMove% = 0
        IF POS(1) < 2 THEN i% = 0 ELSE i% = 1
        LOCATE 10 + junpheight%, POS(1) - i%: PRINT " " + CHR$(2);

        REM If in Air, Descend!

        REM Winner!
        IF POS(1) > 75 THEN LOCATE 15, 37: PRINT "You Won!": EXIT DO
    END IF

    REM Evaluate
    IF POS(1) >= 20 THEN
        xy% = SCREEN(CSRLIN, POS(1), 0)
        IF xy% <> 32 THEN
            SELECT CASE jump%
                CASE 0
                    LOCATE 15, 36: PRINT "Game Over!": EXIT DO
                CASE ELSE

            END SELECT
        END IF
    END IF
    '_LIMIT 1000
LOOP UNTIL INKEY$ = CHR$(27)
END
'* GetMouseParams.bm
Code: [Select]
SUB GetMouseParams
DO
    tsils# = TIMER
    mousert& = mousert& + 1
    IF _MOUSEINPUT THEN
        CMouseRec.MouseX = _MOUSEX
        CMouseRec.MouseY = _MOUSEY
        wheel% = _MOUSEWHEEL
        IF wheel% THEN
            CMouseRec.MWheelAccumulator = CMouseRec.MWheelAccumulator + wheel%
            IF CMouseRec.MWheelAccumulator <> OMouseRec.MWheelAccumulator THEN
                '* put your mousewheel handling code here
                IF CMouseRec.MWheelAccumulator < OMouseRec.MWheelAccumulator THEN
                ELSE
                END IF
                OMouseRec.MWheelAccumulator = CMouseRec.MWheelAccumulator
            END IF
        END IF
        CursorAction% = 0
        IF CMouseRec.MouseX <> OMouseRec.MouseX THEN
            CMouseRec.ActionX = Cursoractx
            deltamousex% = CMouseRec.MouseX - OMouseRec.MouseX
            OMouseRec.MouseX = CMouseRec.MouseX
        END IF
        IF CMouseRec.MouseY <> OMouseRec.MouseY THEN
            CMouseRec.ActionY = Cursoracty
            deltamousey% = CMouseRec.MouseY - OMouseRec.MouseY
            OMouseRec.MouseY = CMouseRec.MouseY
        END IF
        TimeHold# = TIMER
        CMouseRec.MouseStateLmb = _MOUSEBUTTON(1)
        CMouseRec.MouseStateRmb = _MOUSEBUTTON(2)
        CMouseRec.MouseStateBoth = _MOUSEBUTTON(3)
        anybuttonpressed% = 0
        IF CMouseRec.MouseStateBoth THEN
            anybuttonpressed% = mousebb%
            CMouseRec.BothPressed = TimeHold#
        ELSE
            IF CMouseRec.MouseStateLmb THEN
                anybuttonpressed% = mouselb%
                CMouseRec.LmbPressed = TimeHold#
            END IF

            IF CMouseRec.MouseStateRmb THEN
                anybuttonpressed% = mouserb%
                CMouseRec.RmbPressed = TimeHold#
            END IF
        END IF
        SELECT CASE anybuttonpressed%
            CASE mousebb%
                IF ABS(CMouseRec.BothPressed - OMouseRec.BothPressed) > CMouseRec.boththreshhold THEN
                    CMouseRec.dblboth = 0
                    CMouseRec.countbothsingle = CMouseRec.countbothsingle + 1
                    OMouseRec.MouseStateBoth = NOT (CMouseRec.MouseStateBoth)
                    CMouseRec.MouseDragBothXStart = -1
                    CMouseRec.MouseDragBothYStart = -1
                ELSE
                    IF ABS(CMouseRec.BothPressed - OMouseRec.BothPressed) >= CMouseRec.bothdblclickthreshhold THEN
                        CMouseRec.dblboth = -1
                        CMouseRec.countbothdouble = CMouseRec.countbothdouble + 1
                    ELSE
                        IF CMouseRec.MouseStateBoth <> OMouseRec.MouseStateBoth OR -1 THEN
                            IF CMouseRec.MouseStateBoth = OMouseRec.MouseStateBoth THEN
                                IF CMouseRec.MouseDragBothXStart = -1 THEN
                                    CMouseRec.MouseDragBothXStart = CMouseRec.MouseX
                                    CMouseRec.MouseDragBothYStart = CMouseRec.MouseY
                                ELSE
                                    CMouseRec.MouseDragBothXEnd = CMouseRec.MouseX
                                    CMouseRec.MouseDragBothYEnd = CMouseRec.MouseY
                                END IF
                                '* LOCATE 4, 1
                                '* PRINT USING "sb(x####:y####) eb(x####:y####)"; CMouseRec.MouseDragBothXStart, CMouseRec.MouseDragBothYStart, CMouseRec.MouseDragBothXEnd, CMouseRec.MouseDragBothYEnd;
                            ELSE
                                OMouseRec.MouseStateBoth = CMouseRec.MouseStateBoth
                                CMouseRec.MouseDragBothXStart = -1
                                CMouseRec.MouseDragBothYStart = -1
                            END IF
                        END IF
                    END IF
                END IF
                OMouseRec.BothPressed = TimeHold#
            CASE mouselb%
                IF ABS(CMouseRec.LmbPressed - OMouseRec.LmbPressed) > CMouseRec.lmbThreshhold THEN
                    CMouseRec.dbllmb = 0
                    CMouseRec.countlmbsingle = CMouseRec.countlmbsingle + 1
                    OMouseRec.MouseStateLmb = NOT (CMouseRec.MouseStateLmb)
                    CMouseRec.MouseDragLmbXStart = -1
                    CMouseRec.MouseDragLmbYStart = -1
                ELSE
                    IF ABS(CMouseRec.LmbPressed - OMouseRec.LmbPressed) >= CMouseRec.lmbdblclickthreshhold THEN
                        CMouseRec.dbllmb = -1
                        CMouseRec.countlmbdouble = CMouseRec.countlmbdouble + 1
                    ELSE
                        IF CMouseRec.MouseStateLmb <> OMouseRec.MouseStateLmb OR -1 THEN
                            IF CMouseRec.MouseStateLmb = OMouseRec.MouseStateLmb THEN
                                IF CMouseRec.MouseDragLmbXStart = -1 THEN
                                    CMouseRec.MouseDragLmbXStart = CMouseRec.MouseX
                                    CMouseRec.MouseDragLmbYStart = CMouseRec.MouseY
                                ELSE
                                    CMouseRec.MouseDragLmbXEnd = CMouseRec.MouseX
                                    CMouseRec.MouseDragLmbYEnd = CMouseRec.MouseY
                                END IF
                                '* LOCATE 5, 1
                                '* PRINT USING "sl(x####:y####) el(x####:y####)"; CMouseRec.MouseDragLmbXStart, CMouseRec.MouseDragLmbYStart, CMouseRec.MouseDragLmbXEnd, CMouseRec.MouseDragLmbYEnd;
                            ELSE
                                OMouseRec.MouseStateLmb = CMouseRec.MouseStateLmb
                                CMouseRec.MouseDragLmbXStart = -1
                                CMouseRec.MouseDragLmbYStart = -1
                            END IF
                        END IF
                    END IF
                END IF
                OMouseRec.LmbPressed = TimeHold#
            CASE mouserb%
                IF ABS(CMouseRec.RmbPressed - OMouseRec.RmbPressed) > CMouseRec.rmbthreshhold THEN
                    CMouseRec.dblrmb = 0
                    CMouseRec.countrmbsingle = CMouseRec.countrmbsingle + 1
                    OMouseRec.MouseStateRmb = NOT (CMouseRec.MouseStateRmb)
                    CMouseRec.MouseDragRmbXStart = -1
                    CMouseRec.MouseDragRmbYStart = -1
                ELSE
                    IF ABS(CMouseRec.RmbPressed - OMouseRec.RmbPressed) >= CMouseRec.rmbdblclickthreshhold THEN
                        CMouseRec.dblrmb = -1
                        CMouseRec.countrmbdouble = CMouseRec.countrmbdouble + 1
                    ELSE
                        IF CMouseRec.MouseStateRmb <> OMouseRec.MouseStateRmb OR -1 THEN
                            IF CMouseRec.MouseStateRmb = OMouseRec.MouseStateRmb THEN
                                IF CMouseRec.MouseDragRmbXStart = -1 THEN
                                    CMouseRec.MouseDragRmbXStart = CMouseRec.MouseX
                                    CMouseRec.MouseDragRmbYStart = CMouseRec.MouseY
                                ELSE
                                    CMouseRec.MouseDragRmbXEnd = CMouseRec.MouseX
                                    CMouseRec.MouseDragRmbYEnd = CMouseRec.MouseY
                                END IF
                                '* LOCATE 6, 1
                                '* PRINT USING "sr(x####:y####) er(x####:y####)"; CMouseRec.MouseDragRmbXStart, CMouseRec.MouseDragRmbYStart, CMouseRec.MouseDragRmbXEnd, CMouseRec.MouseDragRmbYEnd;
                            ELSE
                                OMouseRec.MouseStateRmb = CMouseRec.MouseStateRmb
                                CMouseRec.MouseDragRmbXStart = -1
                                CMouseRec.MouseDragRmbYStart = -1
                            END IF
                        END IF
                    END IF
                END IF
                OMouseRec.RmbPressed = TimeHold#
            CASE ELSE
                EXIT DO
        END SELECT
    ELSE
        EXIT DO
    END IF
LOOP
END SUB
« Last Edit: September 13, 2010, 10:16:29 PM by codeguy »

unseenmachine

  • Hero Member
  • *****
  • Posts: 3285
  • A fish, a fish, a fishy o!
Re: Reseting the mouse?
« Reply #14 on: September 13, 2010, 08:24:54 PM »
Congratulations! We expect nothing less than the best from our hero members!!! Thanks for the help also, i pretty much have it sorted out now. I am going to start work on my sprite sheets for my enemy animations, then more coding!! YIPPEE!! It's over 1000 lines now...no turning back!!!!