• Print

Author Topic: Text To Binary.  (Read 360 times)

Prithak

  • Jr. Member
  • **
  • Posts: 87
  • Programmer: A machine turns Coffee into Code.
Re: Text To Binary.
« Reply #15 on: April 24, 2018, 06:43:49 am »
Quote from: bplus on April 23, 2018, 08:52:39 am
Oh cool, the screen size is set by numbers from file (if it exists) and the MouseClick function seems fine now! (once I realized that was a button I was supposed to click to get started).

I might of used shared variables for CenterX and CenterY instead of functions but is great practice program!

In fact, I am having a little trouble with a similar getClick sub and might try your simpler code than what I have.  :)

Would you mind posting the code of the functions? I am in a hunt for useful libraries  ;D

-Prithak  :)
Q: 0 is False and 1 is True, right?
A: 1

bplus

  • Hero Member
  • *****
  • Posts: 738
  • B = B + _
Re: Text To Binary.
« Reply #16 on: April 24, 2018, 08:14:59 am »
Here something I find handy for a board game PLUS it shows an example of _LIMIT saving the fan from going on so often (CPU running hot).
Code: [Select]
_TITLE "Mouse click on grid test  by bplus 2018-04-24"
'QB64 version 2017 1106/82 (the day before they switched to version 1.2)


'   Some handy code for board games, requested by Prithak,
'   also a STOP THE FAN !!! example to lower CPU usage


CONST xmax = 800
CONST ymax = 600
SCREEN _NEWIMAGE(xmax, ymax, 32)
_SCREENMOVE 360, 60

xOffSet = 300: yOffSet = 200: squareSize = 40: nSquaresPerSide = 5
LOCATE 3, 40: PRINT "Press escape to quit..."
LOCATE 5, 16: PRINT "Notice this will report the square you released the left mouse button on."
BoxColumn = 0: BoxRow = 0: escape = 0
k$ = " "
drawGrid xOffSet, yOffSet, squareSize, nSquaresPerSide
WHILE 1
    getClick xOffSet, yOffSet, squareSize, nSquaresPerSide, BoxColumn, BoxRow, escape
    IF escape THEN CLS: END
    LINE (0, 160)-(xmax, 200), &HFF, BF 'black out last report
    LOCATE 11, 38: PRINT "Grid (x, y) click is (" + LTRIM$(STR$(BoxColumn)) + "," + STR$(BoxRow) + ")"
WEND

'want the board square bx, by from board with grid xoff, yoff, sq pixels, n x n square board
SUB getClick (xoff, yoff, sq, n, bx, by, escape)
    WHILE 1
        test$ = INKEY$
        IF LEN(test$) THEN
            IF ASC(test$) = 27 THEN escape = -1: EXIT SUB
        END IF

        ' get players move
        ' by mouse
        'this might NOT be too intuitive but proper mouse catching demands we wait for mouse button release
        m = _MOUSEINPUT: mb = _MOUSEBUTTON(1): mx = _MOUSEX: my = _MOUSEY
        IF mb THEN 'get last place mouse button was down
            mb = _MOUSEBUTTON(1): mx = _MOUSEX: my = _MOUSEY
            WHILE mb 'left button down, wait for mouse button release before doing anything as a "click"
                'this updates mx, my while waiting for button release
                m = _MOUSEINPUT: mb = _MOUSEBUTTON(1): mx = _MOUSEX: my = _MOUSEY
            WEND
            row = (my - yoff) / sq
            IF row > 0 AND row < n THEN
                by = INT(row)
                col = (mx - xoff) / sq
                IF col > 0 AND col < n THEN
                    bx = INT(col)
                    EXIT WHILE
                ELSE
                    BEEP
                END IF
            ELSE
                BEEP
            END IF
        END IF
        _LIMIT 1000 'STOP THE FAN !!!!!!!!!!!!!!!!!!!   try this with _LIMIT commented out
    WEND
END SUB

SUB drawGrid (x, y, sq, n)
    d = sq * n
    FOR i = 0 TO n
        LINE (x + sq * i, y)-(x + sq * i, y + d)
        LINE (x, y + sq * i)-(x + d, y + sq * i)
    NEXT
END SUB
« Last Edit: April 24, 2018, 08:22:28 am by bplus »
Will you still love me, will you still need me, when I'm (QB) 64?

  • Print