CODE SAMPLE:
[code=thinbasic]'
' TBDI Demoscript : Read Joystick Version 1.2 & X-PLOD
'
' Original code by, Michael Hartlef 2007
' Reduced code by, Jason DAngelo 2009
' (Reduced code is specific to X-BOX, X-PLOD Guitar, USB, as a Joystick.)
'
DECLARE FUNCTION WinBeep LIB "KERNEL32.DLL" ALIAS "Beep" (BYVAL dwFreq AS DWORD, BYVAL dwDuration AS DWORD) AS LONG
Uses "TBGL"
Uses "UI"
Uses "TBDI"
dim hWnd as dword
hWnd = TBGL_CreateWindow("Read Joystick - press ESC to quit") ' Creates OpenGL window, it returns handle
TBGL_ShowWindow ' Shows the window
TBGL_LoadBMPFont "TBGL_Font.bmp",40 ' Loads texture for font
GetAsyncKeyState(%VK_ESCAPE) ' Resets ESC key status before checking
TBDI_Init(hWnd)
TBDI_joysetdeadzonexyz(0, 0)
while IsWindow(hWnd)
TBGL_ClearFrame ' Prepares clear frame
TBGL_Camera 0,0,5,0,0,0 ' Setups camera to look from 0,0,5 to 0,0,0
TBGL_ResetMatrix ' Important before printing on screen !
' POV is also the N-NE-E-SE-S-SW-W direction pad. {STRUM Up,Down}
TBGL_Color 255,255,255
TBGL_printBMP "WHAMMY= "+str$(TBDI_joyrX(0)),1,2
TBGL_Color 128,128,128
TBGL_printBMP "STRUM= "+str$(TBDI_joypov(0,1)),1,4
TBGL_Color 128,128,0
TBGL_printBMP "STAR POWER= "+str$(TBDI_joyrY(0)),1,6
TBGL_Color 0,128,128
TBGL_printBMP "HORIZONTAL= "+str$(TBDI_joyz(0)),1,8
' Two actions complete the full range of sound, or either one can make half the range.
' The two time delays 1 or 30 were to hear which was which.
if TBDI_joypov(0,1) = 18000 then
WinBeep ((TBDI_joyrX(0)*0.5)+(TBDI_joyrY(0)*0.5)+1064,1)
elseif TBDI_joypov(0,1) = 0 then
WinBeep ((TBDI_joyrX(0)*0.5)+(TBDI_joyrY(0)*0.5)+1064,30)
end if
' I just added some notes, in addition to the colors.
' They play in order, due to the BEEP limitation.
' Take note of the order (1,2,4,3,5)
' START ( and BACK (7) were left-out of code.
TBGL_Color 0,255,0
if TBDI_joybutton(0,1) then
TBGL_printBMP "XXX",1,10
WinBeep (3135,5)
end if
TBGL_Color 255,0,0
if TBDI_joybutton(0,2) then
TBGL_printBMP "XXX",1,11
WinBeep (2793,5)
end if
TBGL_Color 255,255,0
if TBDI_joybutton(0,4) then
TBGL_printBMP "XXX",1,12
WinBeep (2637,5)
end if
TBGL_Color 0,0,255
if TBDI_joybutton(0,3) then
TBGL_printBMP "XXX",1,13
WinBeep (2349,5)
end if
TBGL_Color 255,128,0
if TBDI_joybutton(0,5) then
TBGL_printBMP "XXX",1,14
WinBeep (2093,5)
end if
TBGL_DrawFrame ' Swaps the buffers - displays rendered image
if GetAsyncKeyState(%VK_ESCAPE) then exit while
wend
TBGL_DestroyWindow ' Closes OpenGL window[/code]
Bookmarks