'=============================================================== 
' A F l i b   I I I   F l o w i n g   S e a   E x a m p l e
'=============================================================== 
'In this program for AFlib III, get ready to witness and be
'jawdroppingly awed by a very special tile-mapping effect in
'which I took a "Mode-7"-based perspective and successfully
'programmed/developed it into a beautifully flowing endless sea
'from the top and/or bottom sides... and the wildest thing about
'it is that you can make it as watery or as thickly viscous as
'you'd like, from any .BMP file you like that is higher than an
'8-bit color depth, with the maps themselves being up to a
'whopping 4096x4096 IN SIZE!!! 
' 
'Please enjoy this one immensely, and thank you ever so very
'much, especially!!!
' 
' 
'                                        - Adigun Azikiwe Polack 
'                               One of the Founders of Aura Flow 
'                                       Developer of "AFlib III" 
'---------------------------------------------------------------


#include "AFlib3_Sprite.bi"
#include "AFlib3_Font.bi"
#include "AFlib3_Screen.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 FlowingSea_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 scalx = 200, scaly = 200, scalz = 80, horiz, ang, cx, cy
Dim Shared as integer PlasmaSwitch = 0, PlasmaKeyDelay
Dim Shared As Any Ptr FlowingSea_Top_map, FlowingSea_Bottom_map

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

Dim Shared as Integer SCR_WID, SCR_HEI, CurrentFPS, BitDepth

ScreenRes 424, 72 , , 0
Windowtitle "AFlib III -- Flowing Sea 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 = ""

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


'-------------------------------------------------------
FlowingSea_Top_map = imagecreate( 2048, 2048 )
bload "AF3_Cloud2048.bmp", FlowingSea_Top_map

FlowingSea_Bottom_map = imagecreate( 2048, 2048 )
bload "AF3_Water2048.bmp", FlowingSea_Bottom_map
'-------------------------------------------------------


AFlibIII_ClearDisplay 0

Dim as integer FPSresult (1 to 8)

FlowingSea_Test
FPSresult(1) = CurrentFPS

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

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

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

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

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

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

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

'----------------------------------------------------
ImageDestroy ( FlowingSea_Top_map )
ImageDestroy ( FlowingSea_Bottom_map )
AFlibIII_RemoveFontSet 1
'----------------------------------------------------

ScreenCopy
ScreenRes 416, 144, 8, 0, 0
Windowtitle "AFlib III Flowing Sea Test Results!"
Locate 1, 1
Color 15, 1: ? " ------- AFlib III Flowing Sea 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 Flowing Sea 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

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


'__________________________________________________________________________ 
Sub FlowingSea_Test ()

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

horiz = 1
AFlibIII_CaptureScreen 1

Static flowctrl as Integer

Do
  AFlibIII_ClearDisplay RGBA(0, 0, 0, 0)
  If BitDepth >= 24 then
    For BlitMul as Integer = 0 to 31 step 1
      Line (0, ((SCR_HEI / 2) - BlitMul)) - (SCR_WID, ((SCR_HEI / 2) - BlitMul)), rgba(0, 0, 0, 255 - (BlitMul * 8))
      Line (0, ((SCR_HEI / 2) + BlitMul)) - (SCR_WID, ((SCR_HEI / 2) + BlitMul)), rgba(0, 0, 0, 255 - (BlitMul * 8))
    Next
  End if
  AFlibIII_UpdateScreen 1
  
  'For the Whole Screen!
  '==========================
  AFlibIII_ClearDisplay RGB(0, 0, 0)
  AFlibIII_FlowingSea_top ( scalx, scaly, scalz, horiz, ang, cx, cy, (SCR_HEI / 2), (SCR_HEI / 2), FlowingSea_Top_map, 1, PlasmaSwitch ) 
  Flowctrl += 2
  If Flowctrl >= 1 then
    AFlibIII_FlowingSea_bottom ( scalx, scaly, scalz, horiz, ang, cx, cy, (SCR_HEI / 2), ((SCR_HEI / 2) - 1), FlowingSea_Bottom_map, 1, PlasmaSwitch )
    Flowctrl = 0
  else
    AFlibIII_FlowingSea_bottom ( scalx, scaly, scalz, horiz, ang, cx, cy, (SCR_HEI / 2), ((SCR_HEI / 2) - 1), FlowingSea_Bottom_map, 0, PlasmaSwitch )
  end if
  AFlibIII_BlitScreen_alpha 0, 0, -1, 1
  
  ShadowPrint "Scale X", 0, 0, rgb(255,255,0), 1, 1, rgb(0,0,0), 1: ShadowPrint "(keys Z, X):", 64, 0, rgb(255,174,45), 1, 1, rgb(0,0,0), 1: ShadowPrint LTRIM$(STR$(scalx)), 168, 0, rgb(255,255,255), 1, 1, rgb(0,0,0), 1
  ShadowPrint "Scale Y", 0, 8, rgb(255,255,0), 1, 1, rgb(0,0,0), 1: ShadowPrint "(keys A, S):", 64, 8, rgb(255,174,45), 1, 1, rgb(0,0,0), 1: ShadowPrint LTRIM$(STR$(scaly)), 168, 8, rgb(255,255,255), 1, 1, rgb(0,0,0), 1
  ShadowPrint "Scale Z", 0, 16, rgb(255,255,0), 1, 1, rgb(0,0,0), 1: ShadowPrint "(keys C, V):", 64, 16, rgb(255,174,45), 1, 1, rgb(0,0,0), 1: ShadowPrint LTRIM$(STR$(scalz)), 168, 16, rgb(255,255,255), 1, 1, rgb(0,0,0), 1
  ShadowPrint "Horiz", 0, 24, rgb(255,255,0), 1, 1, rgb(0,0,0), 1: ShadowPrint "(keys D, F):", 48, 24, rgb(255,174,45), 1, 1, rgb(0,0,0), 1: ShadowPrint LTRIM$(STR$(horiz)), 152, 24, rgb(255,255,255), 1, 1, rgb(0,0,0), 1
  ShadowPrint "Angle", 0, 32, rgb(255,255,0), 1, 1, rgb(0,0,0), 1: ShadowPrint "(keys Q, W):", 48, 32, rgb(255,174,45), 1, 1, rgb(0,0,0), 1: ShadowPrint LTRIM$(STR$(ang)), 152, 32, rgb(255,255,255), 1, 1, rgb(0,0,0), 1
  ShadowPrint "Camera X", 0, 40, rgb(255,255,0), 1, 1, rgb(0,0,0), 1: ShadowPrint "(keys " + CHR$(27) + ", " + CHR$(26) + "):", 72, 40, rgb(255,174,45), 1, 1, rgb(0,0,0), 1: ShadowPrint LTRIM$(STR$(cx)), 172, 40, rgb(255,255,255), 1, 1, rgb(0,0,0), 1
  ShadowPrint "Camera Y", 0, 48, rgb(255,255,0), 1, 1, rgb(0,0,0), 1: ShadowPrint "(keys " + CHR$(24) + ", " + CHR$(25) + "):", 72, 48, rgb(255,174,45), 1, 1, rgb(0,0,0), 1: ShadowPrint LTRIM$(STR$(cy)), 172, 48, rgb(255,255,255), 1, 1, rgb(0,0,0), 1
  ShadowPrint "Plasma Effect", 0, 56, rgb(255,255,0), 1, 1, rgb(0,0,0), 1: ShadowPrint "(ENTER / RETURN key):", 112, 56, rgb(255,174,45), 1, 1, rgb(0,0,0), 1: ShadowPrint LTRIM$(STR$(PlasmaSwitch)), 288, 56, 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, 72, rgb(255,255,255), 1, 1, rgb(0,0,0), 1

  If MultiKey(&h2C) then scalx += 1 
  If MultiKey(&h2D) then scalx -= 1: If scalx < 1 then scalx = 1 

  If MultiKey(&h1E) then scaly += 1 
  If MultiKey(&h1F) then scaly -= 1: If scaly < 1 then scaly = 1 

  If MultiKey(&h2E) then scalz += 1 
  If MultiKey(&h2F) then scalz -= 1: If scalz < 1 then scalz = 1 

  If MultiKey(&h20) then horiz += 1 
  If MultiKey(&h21) then horiz -= 1: If horiz < 1 then horiz = 1 

  If MultiKey(&h10) then ang += 1 
  If MultiKey(&h11) then ang -= 1: If ang < 1 then ang = 1 

  If MultiKey(&h4D) then cx += 3 
  If MultiKey(&h4B) then cx -= 3: If cx < 1 then cx = 1 

  If MultiKey(&h48) then cy += 3 
  If MultiKey(&h50) then cy -= 3: If cy < 1 then cy = 1 

  PlasmaKeyDelay -= 1
  If MultiKey(&h1C) then
    If PlasmaKeyDelay <= 0 then
      PlasmaSwitch += 1: If PlasmaSwitch > 1 then PlasmaSwitch = 0
      PlasmaKeyDelay = 15
    end if
  end if
  
  CurrentFPS = AFlibIII_ShowFPS
  WaitControl -= 1
  If WaitControl < 0 then WaitControl = 0
  AFlibIII_CustomSync fps_OPTIMAL
  ScreenCopy
loop until WaitControl <=0 and MultiKey(&h01)    ' <------------ Press "ESC" key to exit the loop.
WaitControl = 105
AFlibIII_RemoveScreen 1
End Sub




