'=============================================================== 
' A F l i b   I I I   W a t e r f a l l   E x a m p l e
'=============================================================== 
'In this program for AFlib III, you will discover how REAL cool
'it is to implement a really silky-smooth "waterfall" effect in
'any 24- or 32-bit graphics mode of your choice!!!  (^-^)v !
'Also here, you can test it in certain resolutions up to a
'1024x768 mode as well!!
' 
'Hope you enjoy this one!!!  :D
' 
' 
'                                        - Adigun Azikiwe Polack 
'                               One of the Founders of Aura Flow 
'                                       Developer of "AFlib III" 
'---------------------------------------------------------------


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

Dim Full_or_Windowed as integer = 0 '<----- Pass '0' for Windowed Mode; or
                                    '            '1' for Fullscreen Mode.



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 ) 

Declare Sub Waterfall_Test


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

Randomize Timer

Dim Shared as integer scale_the_falls, horiz, flowctrl, flowmove
Dim Shared As Any Ptr Waterfall_map

Dim Shared as integer sx1, sx2, sy1, sy2, col_table, timepast
Dim Shared array_size as Integer 

Dim Shared as Integer SCR_WID, SCR_HEI, CurrentFPS, BitDepth, TimeforFPStoDisplay

ScreenRes 424, 72 , , 0
Windowtitle "AFlib III -- Waterfall Test"
Color 15, 1: ? "          Please select your color depth!!!          "
Locate 4: Color 15, 0
Locate , 17: Color 10: ? "[1] ";: Color 14: ? "- 24-bit color": ?
Locate , 17: Color 10: ? "[2] ";: Color 14: ? "- 32-bit color"

Do
  Select case Inkey$
    Case "1": BitDepth = 24: Exit Do
    Case "2": BitDepth = 32: Exit Do
  End Select
Loop

Dim as String Path
path = ""

flowctrl = 180
SCR_WID = 320
SCR_HEI = 200
ScreenRes SCR_WID, SCR_HEI, BitDepth, 2, Full_or_Windowed

ScreenSet 1, 0
AFlibIII_PrepareCharTrans 0, 0
AFlibIII_DisplayAllChars 0, 0, 0, &hffffff, 0, 17
AFlibIII_OptimizeFontSet 0, 0, 1
ScreenSet 0, 0


'-------------------------------------------------------
Waterfall_map = imagecreate( 1024, 1024 )
bload "AF3_Waterfall.bmp", Waterfall_map
'-------------------------------------------------------


AFlibIII_ClearDisplay 0

Dim as integer FPSresult (1 to 8)

Waterfall_Test
FPSresult(1) = CurrentFPS
CurrentFPS = 0

SCR_WID = 320
SCR_HEI = 240
ScreenRes SCR_WID, SCR_HEI, BitDepth, 2, Full_or_Windowed
Waterfall_Test
FPSresult(2) = CurrentFPS
CurrentFPS = 0

SCR_WID = 400
SCR_HEI = 300
ScreenRes SCR_WID, SCR_HEI, BitDepth, 2, Full_or_Windowed
Waterfall_Test
FPSresult(3) = CurrentFPS
CurrentFPS = 0

SCR_WID = 512
SCR_HEI = 384
ScreenRes SCR_WID, SCR_HEI, BitDepth, 2, Full_or_Windowed
Waterfall_Test
FPSresult(4) = CurrentFPS
CurrentFPS = 0

SCR_WID = 640
SCR_HEI = 400
ScreenRes SCR_WID, SCR_HEI, BitDepth, 2, Full_or_Windowed
Waterfall_Test
FPSresult(5) = CurrentFPS
CurrentFPS = 0

SCR_WID = 640
SCR_HEI = 480
ScreenRes SCR_WID, SCR_HEI, BitDepth, 2, Full_or_Windowed
Waterfall_Test
FPSresult(6) = CurrentFPS
CurrentFPS = 0

SCR_WID = 800
SCR_HEI = 600
ScreenRes SCR_WID, SCR_HEI, BitDepth, 2, Full_or_Windowed
Waterfall_Test
FPSresult(7) = CurrentFPS
CurrentFPS = 0

SCR_WID = 1024
SCR_HEI = 768
ScreenRes SCR_WID, SCR_HEI, BitDepth, 2, Full_or_Windowed
Waterfall_Test
FPSresult(8) = CurrentFPS
CurrentFPS = 0

ScreenCopy
ScreenRes 440, 144, 8, 0, 0
Windowtitle "AFlib2 Remixed Waterfall Test Results!"
Locate 1, 1
Color 15, 1: ? "---------- AFlib III Waterfall Test Results: ----------"
?
Locate , 14: Color 14, 0: ? " 320x200 - ";: Color 15, 0: ? FPSresult(1); "fps"
Locate , 14: Color 14, 0: ? " 320x240 - ";: Color 15, 0: ? FPSresult(2); "fps"
Locate , 14: Color 14, 0: ? " 400x300 - ";: Color 15, 0: ? FPSresult(3); "fps"
Locate , 14: Color 14, 0: ? " 512x384 - ";: Color 15, 0: ? FPSresult(4); "fps"
Locate , 14: Color 14, 0: ? " 640x400 - ";: Color 15, 0: ? FPSresult(5); "fps"
Locate , 14: Color 14, 0: ? " 640x480 - ";: Color 15, 0: ? FPSresult(6); "fps"
Locate , 14: Color 14, 0: ? " 800x600 - ";: Color 15, 0: ? FPSresult(7); "fps"
Locate , 14: Color 14, 0: ? "1024x768 - ";: Color 15, 0: ? FPSresult(8); "fps"
Locate 17, 1: ? "Press any key to end, please."


AFlibIII_ConsoleEdit_Open
AFlibIII_ConsoleEdit_Print "---------- AFlib III Waterfall Test Results: ----------"
AFlibIII_ConsoleEdit_Print ""
AFlibIII_ConsoleEdit_Print ""
AFlibIII_ConsoleEdit_Print "Color Depth Selected:"
AFlibIII_ConsoleEdit_Print Ltrim(Str$(BitDepth)) + "-bit color"
AFlibIII_ConsoleEdit_Print ""
AFlibIII_ConsoleEdit_Print " 320x200 - " + Ltrim(Str$(FPSresult(1))) + "fps"
AFlibIII_ConsoleEdit_Print " 320x240 - " + Ltrim(Str$(FPSresult(2))) + "fps"
AFlibIII_ConsoleEdit_Print " 400x300 - " + Ltrim(Str$(FPSresult(3))) + "fps"
AFlibIII_ConsoleEdit_Print " 512x384 - " + Ltrim(Str$(FPSresult(4))) + "fps"
AFlibIII_ConsoleEdit_Print " 640x400 - " + Ltrim(Str$(FPSresult(5))) + "fps"
AFlibIII_ConsoleEdit_Print " 640x480 - " + Ltrim(Str$(FPSresult(6))) + "fps"
AFlibIII_ConsoleEdit_Print " 800x600 - " + Ltrim(Str$(FPSresult(7))) + "fps"
AFlibIII_ConsoleEdit_Print "1024x768 - " + Ltrim(Str$(FPSresult(8))) + "fps"
AFlibIII_ConsoleEdit_Close

AFlibIII_ClearKeyBuffer
Sleep

'----------------------------------------------------
ImageDestroy ( Waterfall_map )
AFlibIII_RemoveFontSet 1
'----------------------------------------------------

End


'==========================================================================
'/////// 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


'__________________________________________________________________________ 
Sub Waterfall_Test ()

Windowtitle "AFlib III " + Ltrim$(Str$(SCR_WID)) + "x" + Ltrim$(Str$(SCR_HEI)) + " Waterfall Test - (c)2016 Adigun Azikiwe Polack and Aura Flow."
ScreenSet 1, 0

scale_the_falls = 512
horiz = 1
timepast = 0

Do
  AFlibIII_ClearDisplay 0

  'For the Whole Screen!
  '==========================
  AFlibIII_Waterfall ( scale_the_falls, horiz, flowctrl, flowmove, -5, (SCR_HEI - 2), Waterfall_map, 7 )

  ShadowPrint "Falls Scale", 0, 0, rgb(255,255,0), 1, 1, rgb(0,0,0), 1: ShadowPrint "(keys A, S):", 96, 0, rgb(255,174,45), 1, 1, rgb(0,0,0), 1: ShadowPrint LTRIM$(STR$(scale_the_falls)), 200, 0, rgb(255,255,255), 1, 1, rgb(0,0,0), 1
  ShadowPrint "Horiz", 0, 8, rgb(255,255,0), 1, 1, rgb(0,0,0), 1: ShadowPrint "(keys D, F):", 48, 8, rgb(255,174,45), 1, 1, rgb(0,0,0), 1: ShadowPrint LTRIM$(STR$(horiz)), 152, 8, rgb(255,255,255), 1, 1, rgb(0,0,0), 1
  ShadowPrint "Flow Control", 0, 16, rgb(255,255,0), 1, 1, rgb(0,0,0), 1: ShadowPrint "(keys Q, W):", 104, 16, rgb(255,174,45), 1, 1, rgb(0,0,0), 1: ShadowPrint LTRIM$(STR$(flowctrl)), 208, 16, rgb(255,255,255), 1, 1, rgb(0,0,0), 1
  ShadowPrint "Flow Movement", 0, 24, rgb(255,255,0), 1, 1, rgb(0,0,0), 1: ShadowPrint "(keys " + CHR$(27) + ", " + CHR$(26) + "):", 112, 24, rgb(255,174,45), 1, 1, rgb(0,0,0), 1: ShadowPrint LTRIM$(STR$(flowmove)), 216, 24, rgb(255,255,255), 1, 1, rgb(0,0,0), 1
  ShadowPrint ltrim$(str((scr_wid))) + "x" + ltrim$(str((scr_hei)))+ "x" + ltrim$(str((bitdepth))) + " Graphics Mode", 0, 40, rgb(255,255,255), 1, 1, rgb(0,0,0), 1
  
  If MultiKey(&h1E) then scale_the_falls += 1                                                    ' <---- "A" key
  If MultiKey(&h1F) then scale_the_falls -= 1: If scale_the_falls < 1 then scale_the_falls = 1   ' <---- "S" key

  If MultiKey(&h20) then horiz += 1                                         ' <------------------------- "D" key
  If MultiKey(&h21) then horiz -= 1: If horiz < 1 then horiz = 1            ' <------------------------- "F" key

  If MultiKey(&h10) then flowctrl += 1                                      ' <------------------------- "Q" key
  If MultiKey(&h11) then flowctrl -= 1: If flowctrl < 1 then flowctrl = 1   ' <------------------------- "W" key

  If MultiKey(&h4D) then flowmove += 1                                      ' <------------------------- "Right" key
  If MultiKey(&h4B) then flowmove -= 1: If flowmove < 1 then flowmove = 1   ' <------------------------- "Left" key

  timepast +=1: If timepast > 70 then
    CurrentFPS = AFlibIII_ShowFPS
    timepast = 70
  End if
  
  TimeforFPStoDisplay += 1
  AFlibIII_CustomSync fps_OPTIMAL
  ScreenCopy
loop until TimeforFPStoDisplay > 60 and MultiKey(&h01)    ' <------------ Press "ESC" key to exit the loop.
TimeforFPStoDisplay = 0
End Sub

