'=============================================================== 
' A F l i b   I I I   G a m e p a d   B u t t o n   T e s t
'=============================================================== 
'In this AFlib III test, we will detect your joystick or
'gamepad to let you so accurately test the button presses of UP
'TO 16 BUTTONS AT ONCE!!!  They will help you out *tremendously*
'in creating your next awesome game in FreeBASIC now, you got
'that?  ;) !
'       
'Catch 'ya later, and prepare to be motivated richly right
'here!!!  (^-^)v
'
' 
'                                        - Adigun Azikiwe Polack 
'                               One of the Founders of Aura Flow 
'                                       Developer of "AFlib III" 
'---------------------------------------------------------------


#include "AFlib3_Sprite.bi"
#include "AFlib3_Font.bi"
#include "AFlib3_Starfield.bi"
#include "AFlib3_Gamepad.bi"
#include "AFlib3_Miscellaneous.bi"
#include "AFlib3_Constants.bi"

Declare Sub ShadowPrint ( Byref text as String, _ 
                          Byval x as Integer, Byval y as Integer, _ 
                          Byval col as Integer, Byval sh_x as Integer, _ 
                          Byval sh_y as Integer, Byval sh_col as Integer, _ 
                          Byval chara_id as Integer ) 

'========================================================================== 
'/////// S T A R T   O F   M A I N   P O R T I O N 
'========================================================================== 

WindowTitle "AFlib III Gamepad Button Test!!" 

' Set video mode (2 pages) and enter loop 

Dim as Any Ptr AFlib3_title
Dim as Integer GFX_h, GFX_v

ScreenRes 640, 480, 32, 2, 0
ScreenInfo GFX_h, GFX_v 

ScreenSet 1, 0 

SetMouse , , 0

AFlibIII_PrepareCharTrans 0, 0
AFlibIII_DisplayAllChars 0, 0, &hffffff, &hffffff, 0, 4
AFlibIII_OptimizeFontSet 0, 0, 1 

AFlibIII_ClearDisplay 0

AFlib3_title = imagecreate( 376, 140 )
bload "AF3_logo400x300.bmp", AFlib3_title

AFlibIII_StarInit 324 

Do 
  AFlibIII_ClearDisplay 0

  AFlibIII_StarMotion 324, -1, 0, 255
  AFlibIII_StarMove 324, AF3_Down, 5

  AFlibIII_SprBlit_alpha 1, 1, 30, AFlib3_title
  AFlibIII_SprBlit_add 0, 0, 255, AFlib3_title


  ' Let's grab Joystick ID 0, assuming that it is the very first
  ' joystick/gamepad that it detects on your computer, of
  ' course!!  ;)
  '----------------------------------------------------------------
  AFlibIII_GrabJoystick 0

  If not AFlibIII_Joy_Active then 
    ShadowPrint "I am sorry, but Joystick 0 is not active.", 0, 144, rgb(255, 255, 255), 1, 1, rgb(85, 85, 85), 1
    ShadowPrint "Please press any key to exit.", 0, 160, rgb(252, 200, 72), 1, 1, rgb(112, 88, 20), 1
  else 
    
    ShadowPrint "Now Testing Joystick 0.....", 0, 144, rgb(252, 200, 72), 1, 1, rgb(112, 88, 20), 1
    Line (0, 153)-(GFX_h, 153), rgb(0, 0, 200): Line (0, 154)-(GFX_h, 154), rgb(0, 0, 112)

    ShadowPrint "(Normal/Left Analogue)", 216, 160, rgb(255, 0, 0), 1, 1, rgb(112, 0, 0), 1
    ShadowPrint "X = " + str$(AFlibIII_Joy_Left_X_axis), 240, 168, rgb(252, 252, 180), 1, 1, rgb(112, 112, 20), 1
    ShadowPrint "Y = " + str$(AFlibIII_Joy_Left_Y_axis), 240, 176, rgb(252, 252, 180), 1, 1, rgb(112, 112, 20), 1

    ShadowPrint "(Right Analogue)", 216, 192, rgb(255, 0, 0), 1, 1, rgb(112, 0, 0), 1
    ShadowPrint "X = " + str$(AFlibIII_Joy_Right_X_axis), 240, 200, rgb(252, 252, 180), 1, 1, rgb(112, 112, 20), 1
    ShadowPrint "Y = " + str$(AFlibIII_Joy_Right_Y_axis), 240, 208, rgb(252, 252, 180), 1, 1, rgb(112, 112, 20), 1
    
    ShadowPrint "Throttle: " + str$(AFlibIII_Joy_Throttle_axis), 216, 224, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1

    ' Now, we test all of the (16) joystick buttons to make sure they 
    ' work in AFlib III!!!  ^_-=b
    '--------------------------------------------------------------------- 
    If AFlibIII_Joy_Trigger1 = Active then 
      ShadowPrint "Button 1 Pressed!", 32, 160, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 1 not pressed", 32, 160, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger2 = Active then 
      ShadowPrint "Button 2 Pressed!", 32, 168, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 2 not pressed", 32, 168, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger3 = Active then 
      ShadowPrint "Button 3 Pressed!", 32, 176, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 3 not pressed", 32, 176, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger4 = Active then 
      ShadowPrint "Button 4 Pressed!", 32, 184, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 4 not pressed", 32, 184, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger5 = Active then 
      ShadowPrint "Button 5 Pressed!", 32, 192, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 5 not pressed", 32, 192, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger6 = Active then 
      ShadowPrint "Button 6 Pressed!", 32, 200, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 6 not pressed", 32, 200, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger7 = Active then 
      ShadowPrint "Button 7 Pressed!", 32, 208, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 7 not pressed", 32, 208, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger8 = Active then 
      ShadowPrint "Button 8 Pressed!", 32, 216, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 8 not pressed", 32, 216, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger9 = Active then 
      ShadowPrint "Button 9 Pressed!", 32, 224, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 9 not pressed", 32, 224, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger10 = Active then 
      ShadowPrint "Button 10 Pressed!", 32, 232, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 10 not pressed", 32, 232, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger11 = Active then 
      ShadowPrint "Button 11 Pressed!", 32, 240, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 11 not pressed", 32, 240, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger12 = Active then 
      ShadowPrint "Button 12 Pressed!", 32, 248, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 12 not pressed", 32, 248, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger13 = Active then 
      ShadowPrint "Button 13 Pressed!", 32, 256, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 13 not pressed", 32, 256, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger14 = Active then 
      ShadowPrint "Button 14 Pressed!", 32, 264, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 14 not pressed", 32, 264, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger15 = Active then 
      ShadowPrint "Button 15 Pressed!", 32, 272, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 15 not pressed", 32, 272, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

    If AFlibIII_Joy_Trigger16 = Active then 
      ShadowPrint "Button 16 Pressed!", 32, 280, rgb(255, 255, 255), 1, 1, rgb(125, 125, 125), 1
    else 
      ShadowPrint "Button 16 not pressed", 32, 280, rgb(135, 135, 135), 1, 1, rgb(45, 45, 45), 1
    End if 

  End if 

AFlibIII_CustomSync fps70
ScreenCopy 

Loop While Inkey$ = "" 

imagedestroy( AFlib3_title )
AFlibIII_RemoveFontSet 1

AFlibIII_EndProgram




'========================================================================== 
'/////// E N D   O F   M A I N   P O R T I O N 
'========================================================================== 




'__________________________________________________________________________ 
Sub ShadowPrint ( Byref text as String, _ 
                  Byval x as Integer, Byval y as Integer, _ 
                  Byval col as Integer, Byval sh_x as Integer, _ 
                  Byval sh_y as Integer, Byval sh_col as Integer, _ 
                  Byval chara_id as Integer ) 

AFlibIII_OptimizedPrint_color text, x + sh_x, y + sh_y, chara_id, 0, sh_col
AFlibIII_OptimizedPrint_color text, x, y, chara_id, 0, col

End Sub