DQBjoyMove
FUNCTION

Prototype

DECLARE FUNCTION DQBjoyMove (BYVAL JoyNum, BYVAL Direction)

Parameters

JoyNum - Joystick number to retrieve status of

Direction - Direction to check, see below

Returns

True if the joystick is moved into the given direction, otherwise false

Description

Call this function to know where the joystick has been moved. About the JoyNum parameter refer to the DQBjoyDetected function. The Direction parameter is an integer that must be set to:

- 0 to check if the joystick has been moved up - 1 to check if the joystick has been moved down - 2 to check if the joystick has been moved left - 3 to check if the joystick has been moved right

There are of course four constants for this parameter, named UP, DOWN, LEFT and RIGHT, declared into the file DIRECTQB.BI, and explained into appendix A.

Notes:

none

Example

*****************************************************************************

' All integers for speed
DEFINT A-Z

'$INCLUDE:'DIRECTQB.BI'
DIM X, Y, Col

' Let's initialize the library with one extra layer and no sounds nor EMS
IF DQBinit(1, 0, 0) THEN DQBclose: PRINT DQBerror$: END

IF NOT DQBjoyDetected(JOY1) THEN
    PRINT "Joystick 1 not detected, program aborted."
    DQBclose
    END
END IF

DQBinitVGA

X = 150: Y = 90

DO
    ' Polls joystick 1
    DQBpollJoy JOY1
    
    ' Checks movements
    IF DQBjoyMove(JOY1, UP) THEN Y = Y - 1      ' Joystick 1 up

    IF DQBjoyMove(JOY1, DOWN) THEN Y = Y + 1    ' Joystick 1 down

    IF DQBjoyMove(JOY1, LEFT) THEN X = X - 1    ' Joystick 1 left

    IF DQBjoyMove(JOY1, RIGHT) THEN X = X + 1   ' Joystick 1 right

    ' Adjust coordinates
    IF X < 0 THEN X = 0
    IF X > 299 THEN X = 299
    IF Y < 0 THEN Y = 0
    IF Y > 179 THEN Y = 179

    ' Resets box color to white
    Col = 15

    ' If button A is pressed, change color to red
    IF DQBjoyFire(JOY1, BUTA) THEN Col = 40

    ' If button B is pressed, change color to green
    IF DQBjoyFire(JOY1, BUTB) THEN Col = 2

    ' Clears the contents of layer 1
    DQBclearLayer 1

    ' Draws the box
    DQBboxf 1, X, Y, (X + 19), (Y + 19), Col

    ' Waits for vertical retrace 1 time
    DQBwait 1

    ' Copies out layer to the screen
    DQBcopyLayer 1, VIDEO

    ' Prints a message
    LOCATE 1
    PRINT "  Joystick demo - press a key to exit!"

LOOP WHILE INKEY$ = ""

' Ends program
DQBclose

*****************************************************************************