Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
kind of works? reading multiple mice: any c programmers want to look at this?
#47
(09-12-2022, 09:25 PM)Spriggsy Wrote: System won't print anything, it just exits the program with that code. The function is basically being called by STR$. Not sure what you're asking for on the other question, though. The events are all there to run the window created by CreateWindow and the callback function is registered with RegisterClass.

I see now that you mean line 381. Anyways, there's no way for it to be firing anything after WinMain because System kills the program. Everything is a bit out of order anyways. You wouldn't want your test outside of the loop that is displaying the window.

Let me step back a second and present a more concreate example (see below). 
Just a simple skeleton for a Pong game that draws some stuff that gets moved around with the mouse. 
How would we merge in the API code so the program does the exact same thing, 
except instead of _MouseX, _MouseY, it gets 8 seperate mouse coordinates from RawInput? 

Hopefully this clarifies the kind of use case I am looking to get input for... 
I very much appreciate your help!

Code: (Select All)
Const FALSE = 0
Const TRUE = Not FALSE

' UDT TO HOLD THE INFO FOR EACH MOUSE
Type MouseInfoType
    ID As String ' mouse device ID

    c As String ' text cursor character
    x As Integer ' text x position
    y As Integer ' text y position

    xPos As Long ' hires x position
    yPos As Long ' hires y position

    dx As Long ' dx
    dy As Long ' dy

    wheel As Integer ' mouse wheel value
    LeftDown As Integer ' tracks left mouse button state, TRUE=down
    MiddleDown As Integer ' tracks middle mouse button state, TRUE=down
    RightDown As Integer ' tracks right mouse button state, TRUE=down

    'OldLeftDown As Integer ' tracks left mouse button state, TRUE=down
    'OldMiddleDown As Integer ' tracks middle mouse button state, TRUE=down
    'OldRightDown As Integer ' tracks right mouse button state, TRUE=down

    LeftCount As Integer ' counts left clicks
    MiddleCount As Integer ' counts middle clicks
    RightCount As Integer ' counts right clicks

    px As Long
    py As Long
    pwidth As Integer
    pheight As Integer
    pcolor As _Unsigned Long
End Type ' MouseInfoType

Dim Shared m_arrMouseInfo(8) As MouseInfoType ' STORES INFO FOR EACH MOUSE / PLAYER

game

Sub game
    Dim screen_color~&: screen_color~& = cBlack
    Dim wall_color~&: wall_color~& = cWhite
    ReDim arrColors(-1) As _Unsigned Long
    Dim width%
    Dim height%
    Dim x%, x1%, x2%
    Dim y%, y1%, y2%
    Dim dColor~&
    Dim message$
    Dim player_1_score%
    Dim player_2_score%
    Dim iLoop As Integer
    Dim xMin%, xMax%, yMin%, yMax%
   
    x% = 64
    y% = 64
    For iLoop = 1 To 8
        m_arrMouseInfo(iLoop).px = x%
        m_arrMouseInfo(iLoop).py = y%
        m_arrMouseInfo(iLoop).pwidth = 8
        m_arrMouseInfo(iLoop).pheight = 64
        x% = x% + 32
        y% = y% + 32
    Next iLoop
    m_arrMouseInfo(1).pcolor = cRed
    m_arrMouseInfo(2).pcolor = cOrange
    m_arrMouseInfo(3).pcolor = cYellow
    m_arrMouseInfo(4).pcolor = cLime
    m_arrMouseInfo(5).pcolor = cCyan
    m_arrMouseInfo(6).pcolor = cBlue
    m_arrMouseInfo(7).pcolor = cPurple
    m_arrMouseInfo(8).pcolor = cMagenta
   
    width% = 1024
    height% = 768
    xMin% = 1
    xMax% = width% - 8
    yMin% = 45
    yMax% = height% - (54 + 64 + 1)
   
    Screen _NewImage(width%, height%, 32) ' graphics screen
    '_FULLSCREEN _SQUAREPIXELS
   
    ' PAINT BACKGROUND COLOR
    Line (0, 0)-(width%, height%), screen_color~&, BF
   
    ' DRAW WALLS AROUND EDGES
    For x% = 7 To width% Step 20
        Line (x%, 40)-(x% + 10, 44), wall_color~&, BF
        Line (x%, height% - 50)-(x% + 10, height% - 54), wall_color~&, BF
    Next x%
   
    ' DRAW CENTER LINE
    For y% = 44 To (height% - 48) Step 20
        Line ((width% / 2) - 2, y%)-((width% / 2) + 2, y% + 10), wall_color~&, BF
    Next y%
   
    ' DRAW PLAYERS
    For iLoop = 1 To 8
        x1% = m_arrMouseInfo(iLoop).px
        y1% = m_arrMouseInfo(iLoop).py
        x2% = m_arrMouseInfo(iLoop).px + m_arrMouseInfo(iLoop).pwidth
        y2% = m_arrMouseInfo(iLoop).py + m_arrMouseInfo(iLoop).pheight
        Line (x1%, y1%)-(x2%, y2%), m_arrMouseInfo(iLoop).pcolor, BF ' Draw a solid box
        'LOCATE 1,1:PRINT "(" + cstr$(player_1_x1%) + "," + cstr$(player_1_y1%) + ") (" + cstr$(player_1_x2%) + "," + cstr$(player_1_y2%) + ")" + " (" + cstr$(player_1_color~&) + ")";
    Next iLoop
   
    ' PRINT INSTRUCTIONS, TEXT SCREEN AT 1024X768 IS 48 LINES X 128 CHARACTERS WIDE
    message$ = "AVOID MISSING BALL FOR HIGH SCORE"
    Locate 1, 64 - (Len(message$) / 2): Print message$;
   
    ' PRINT INITIAL SCORE
    Locate 2, 32: Print "0";
    Locate 2, 96: Print "0";
   
    ' SHOW MORE INSTRUCTIONS
    message$ = "PRESS <ESC> TO EXIT"
    Locate 47, 64 - (Len(message$) / 2): Print message$;
   
    Do
        ' ERASE PLAYER'S OLD POSITIONS
        For iLoop = 1 To 8
            x1% = m_arrMouseInfo(iLoop).px
            y1% = m_arrMouseInfo(iLoop).py
            x2% = m_arrMouseInfo(iLoop).px + m_arrMouseInfo(iLoop).pwidth
            y2% = m_arrMouseInfo(iLoop).py + m_arrMouseInfo(iLoop).pheight
            Line (x1%, y1%)-(x2%, y2%), screen_color~&, BF ' Draw a solid box
            'LOCATE 1,1:PRINT "(" + cstr$(player_1_x1%) + "," + cstr$(player_1_y1%) + ") (" + cstr$(player_1_x2%) + "," + cstr$(player_1_y2%) + ")" + " (" + cstr$(player_1_color~&) + ")";
        Next iLoop
           
        ' (RE)DRAW CENTER LINE
        For y% = 44 To (height% - 48) Step 20
            Line ((width% / 2) - 2, y%)-((width% / 2) + 2, y% + 10), wall_color~&, BF
        Next y%
       
        ' GET INPUT AND DRAW PLAYERS IN NEW POSITION
        For iLoop = 1 To 8
           
            ' READ MOUSE
            ' *** UPDATE TO READ SEPERATE MOUSE FOR EACH PLAYER
            While _MouseInput ' get latest mouse information
            Wend
            x% = _MouseX
            y% = _MouseY
           
            ' MAKE SURE VALUES DON'T EXCEED BOUNDS
            If x% < xMin% Then
                x% = xMin%
            ElseIf x% > xMax% Then
                x% = xMax%
            End If
            If y% < yMin% Then
                y% = yMin%
            ElseIf y% > yMax% Then
                y% = yMax%
            End If
           
            ' SAVE VALUES
            m_arrMouseInfo(iLoop).px = x%
            m_arrMouseInfo(iLoop).py = y%
           
            ' DRAW
            x1% = m_arrMouseInfo(iLoop).px
            y1% = m_arrMouseInfo(iLoop).py
            x2% = m_arrMouseInfo(iLoop).px + m_arrMouseInfo(iLoop).pwidth
            y2% = m_arrMouseInfo(iLoop).py + m_arrMouseInfo(iLoop).pheight
            Line (x1%, y1%)-(x2%, y2%), m_arrMouseInfo(iLoop).pcolor, BF ' Draw a solid box
            'LOCATE 1,1:PRINT "(" + cstr$(player_1_x1%) + "," + cstr$(player_1_y1%) + ") (" + cstr$(player_1_x2%) + "," + cstr$(player_1_y2%) + ")" + " (" + cstr$(player_1_color~&) + ")";
        Next iLoop
       
        ' PRINT SCORE
        Locate 2, 32: Print "PLAYER 1: 0"
        Locate 2, 96: Print "PLAYER 2: 0"
       
        ' UPDATE SCREEN
        _Display ' update screen with changes
       
        ' SET GAME SPEED IN FPS
        _Limit 60
    Loop Until _KeyHit = 27 ' ESCAPE to quit
   
    'IF _FULLSCREEN = 0 THEN _FULLSCREEN _OFF
End Sub ' game

Sub AddColor (ColorValue As _Unsigned Long, arrColor() As _Unsigned Long)
    ReDim _Preserve arrColor(0 To UBound(arrColor) + 1) As _Unsigned Long
    arrColor(UBound(arrColor)) = ColorValue
End Sub ' AddColor

Function cRed~& ()
    cRed = _RGB32(255, 0, 0)
End Function

Function cOrange~& ()
    cOrange = _RGB32(255, 165, 0)
End Function ' cOrange~&

Function cYellow~& ()
    cYellow = _RGB32(255, 255, 0)
End Function ' cYellow~&

Function cLime~& ()
    cLime = _RGB32(0, 255, 0)
End Function ' cLime~&

Function cCyan~& ()
    cCyan = _RGB32(0, 255, 255)
End Function ' cCyan~&

Function cBlue~& ()
    cBlue = _RGB32(0, 0, 255)
End Function ' cBlue~&

Function cPurple~& ()
    cPurple = _RGB32(128, 0, 255)
End Function ' cPurple~&

Function cMagenta~& ()
    cMagenta = _RGB32(255, 0, 255)
End Function ' cMagenta~&

Function cBlack~& ()
    cBlack = _RGB32(0, 0, 0)
End Function ' cBlack~&

Function cGray~& ()
    cGray = _RGB32(128, 128, 128)
End Function ' cGray~&

Function cWhite~& ()
    cWhite = _RGB32(255, 255, 255)
    'cWhite = _RGB32(254, 254, 254)
End Function ' cWhite~&

Function cEmpty~& ()
    'cEmpty~& = -1
    cEmpty = _RGB32(0, 0, 0, 0)
End Function ' cEmpty~&
Reply


Messages In This Thread
RE: kind of works? reading multiple mice: any c programmers want to look at this? - by madscijr - 09-12-2022, 10:44 PM



Users browsing this thread: 35 Guest(s)