Ce code va vous permettre d'activer la croix directionnelle de votre joypad. Testé sur:
-> 360controller: tout va bien.
-> dual shock: cela fonctionne, mais il y a un petit blème avec l'affichage de çà:
Code : Tout sélectionner
zut$= Str(*info\dwPOV) ; faut pas avoir peur, voyez. C'est comme çà, la vie est parfois compliqué, voyez.
FrontColor ( RGB (154,154,154)):DrawText (1+1,120+1, "croix directionnelle: " +zut$)
FrontColor ( RGB (234,234,234)):DrawText (1,120, "croix directionnelle: " +zut$)
http://fr.wikipedia.org/wiki/DualShock
-> grosse manette arcade pour ps1: cela fonctionne aussi, mais même petit blème qu'avec la dual shock.
Code : Tout sélectionner
; ------------------------------------------------------------
; test - PC - windaube xp
; joypad: croix directionnelle - 2008 - source PureBasic 4.10
; pseudo: flype - Djes - beauregard
; objectif: attribuer aux variables croixX et croixY, les valeurs renvoyés par la croix directionelle
; d'un joypad munis de stick analogique.
; ------------------------------------------------------------
If InitMouse ()=0 Or InitKeyboard ()=0 Or InitSprite ()=0 Or InitSprite3D ()=0
MessageRequester ( "Error" , "Can't open DirectX 7 or later" , 0)
End
EndIf
If InitJoystick():manette=1:EndIf
;KeyboardMode(#PB_Keyboard_International)
UsePNGImageDecoder()
; °°°°°°°°°°°°°°°°°°°° fonte °°°°°°°°°°°°°°°°°°°°°°°°°°
LoadFont ( 0 , "Comic Sans Ms" ,12, #PB_Font_Bold)
LoadFont ( 1 , "Comic Sans Ms" ,20, #PB_Font_Bold)
; °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
Enumeration ; ici, on donne un petit nom à nos sprites( non, chuis pas un numéro, voyez !):
#repere
;- obscur1:
#JOYCAPS_HASZ = 1
#JOYCAPS_HASR = 2
#JOYCAPS_HASU = 4
#JOYCAPS_HASV = 8
#JOYCAPS_HASPOV = 16
#JOYCAPS_POV4DIR = 32
#JOYCAPS_POVCTS = 64
EndEnumeration
Declare croix(joyCaps,joyInfoEx)
Declare testfinis()
; on ouvre une fenetre:
If OpenWindow ( 0 , 0, 0, 512+48, 384+48, "test" , #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar|#PB_Window_ScreenCentered )
OpenWindowedScreen ( WindowID ( 0 ), 23, 23, 512, 384, 0, 1, 1) ; ici, voyez, on fabrique un écran ecran graphique dans la fenêtre.
EndIf
; repere ( utilisé uniquement par le programmeur):
CreateSprite ( #repere ,8,8, #PB_Sprite_Texture )
StartDrawing ( SpriteOutput ( #repere ))
BackColor ( RGB (0,0,0))
Box (0, 0, 8, 8, RGB (100,195,75)):Box (1, 1, 6, 6, RGB (100,125,75))
StopDrawing ()
Global croixX.l, croixY.l, Xrepere, Yrepere, zut.l
If manette; une condition inutile, mais on est jamais trop prudent, voyez.
;- obscur2:
joyInfoEx.JOYINFOEX
; joyInfoEx\dwFlags = #JOY_RETURNALL
joyInfoEx\dwSize = SizeOf(JOYINFOEX)
EndIf
; ******************************************************************************************************
Repeat ; Boucle principale
; ******************************************************************************************************
Event= WindowEvent ()
;ExamineMouse():
ExamineKeyboard ()
If manette:ExamineJoystick():EndIf
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
;- obscur3:
If joyGetPosEx_(#JOYSTICKID1,joyInfoEx) = #JOYERR_NOERROR And manette:croix(joyCaps,joyInfoEx):EndIf
If (manette=0 And KeyboardPushed ( #PB_Key_Up )) Or (manette And (JoystickAxisY()=-1 Or croixY=-1)); <-- voyez !
If Yrepere>-192:Yrepere-2:EndIf
EndIf
If (manette=0 And KeyboardPushed ( #PB_Key_Down )) Or (manette And (JoystickAxisY()=1 Or croixY=1)); <-- c'est comme çà, voyez !
If Yrepere<192-8:Yrepere+2:EndIf
EndIf
If (manette=0 And KeyboardPushed ( #PB_Key_Right )) Or (manette And (JoystickAxisX()=1 Or croixX=1)); <-- et faite bien attention...
If Xrepere<256-8:Xrepere+2:EndIf
EndIf
If (manette=0 And KeyboardPushed ( #PB_Key_Left )) Or (manette And (JoystickAxisX()=-1 Or croixX=-1)); <-- au nombre de parenthèses, voyez !
If Xrepere>-256:Xrepere-2:EndIf
EndIf
DisplayTransparentSprite( #repere , 256+Xrepere, 192+Yrepere)
If manette=0
StartDrawing ( ScreenOutput ())
DrawingMode (1):DrawingFont ( FontID (1)):BackColor ( RGB (0,0,0))
FrontColor ( RGB (154,154,154)):DrawText (24+2,120+2, "vous n'avez pas de joypad, voyez.")
FrontColor ( RGB (234,234,234)):DrawText (24,120, "vous n'avez pas de joypad, voyez.")
StopDrawing ()
EndIf
If KeyboardPushed ( #PB_Key_F ) And nbreis=0:nbreis+1:EndIf
If KeyboardPushed ( #PB_Key_F )=0 And nbreis=1:nbreis+1:EndIf
If KeyboardPushed ( #PB_Key_F ) And nbreis=2:nbreis+1:EndIf
If KeyboardPushed ( #PB_Key_F )=0 And nbreis=3:nbreis=0:EndIf
Gosub fps ; nombre d'image par seconde ( à placer dans tout vos jolis programmes, voyez !)
; ******************************************************************************************************
Delay (1)
If Event= #PB_Event_CloseWindow Or KeyboardPushed ( #PB_Key_Escape ):testfinis():EndIf; si clique coin haut droit ou touche Esc, alors ferme fenêtre.
ForEver
fps:
If Val ( FormatDate ( "%ss" , Date ()))=sek ; regardez pas là, c'est trop compliqué voyez.
fps+1 ; Arrêtez j'vous dis, vous allez vous faire mal à la tête, voyez!
Else
FPS$= Str (fps)
fps=0
EndIf
sek= Val ( FormatDate ( "%ss" , Date ()))
StartDrawing ( ScreenOutput ())
DrawingMode (1)
FrontColor ( RGB (255,255,255))
If nbreis=1 Or nbreis=2:DrawText (1,1, "FPS: " +FPS$):EndIf
StopDrawing ()
Return
;- obscur4:
Procedure.l croix(*caps.JOYCAPS, *info.JOYINFOEX);une petite procédure à placer dans vos jeux( un grand merci à flype).
croixX=0:croixY=0
StartDrawing ( ScreenOutput ())
DrawingMode (1):DrawingFont ( FontID (0)):BackColor ( RGB (0,0,0))
zut$= Str(*info\dwPOV) ; faut pas avoir peur, voyez. C'est comme çà, la vie est parfois compliqué, voyez.
FrontColor ( RGB (154,154,154)):DrawText (1+1,120+1, "croix directionnelle: " +zut$)
FrontColor ( RGB (234,234,234)):DrawText (1,120, "croix directionnelle: " +zut$)
If *info\dwPOV=0 Or *info\dwPOV=4500 Or *info\dwPOV=31500:croixY=-1:EndIf; haut
If *info\dwPOV=18000 Or *info\dwPOV=22500 Or *info\dwPOV=13500:croixY=1:EndIf; bas
If *info\dwPOV=9000 Or *info\dwPOV=4500 Or *info\dwPOV=13500:croixX=1:EndIf; droite
If *info\dwPOV=27000 Or *info\dwPOV=31500 Or *info\dwPOV=22500:croixX=-1:EndIf; gauche
StopDrawing ()
EndProcedure
Procedure.l testfinis()
If IsImage(#repere):FreeImage(#repere):EndIf ; là, une bonne habitude à prendre, voyez.
End
EndProcedure