#include "AFlib3_Miscellaneous.bi"
#include "AFlib3_ASCii.bi"

Dim as Integer TxtGfx_X = 80
Dim as Integer TxtGfx_Y = 60

AFlibIII_SetTextGFX TxtGfx_X, TxtGfx_Y, 24, 2, 0

Dim as Integer TunSize_X = TxtGfx_X
Dim as Integer TunSize_Y = TxtGfx_Y

Dim as Integer TunImgNo = 0, TunImgCycTime = 0
Dim as Single TunSpd
Dim as any ptr TunnelImage = imagecreate(256, 256)

AFlibIII_Initialize_ASCii
AFlibIII_ASCii_Tunnel_Init
AFlibIII_ASCii_Tunnel_GrabImage "Test256x256_1.bmp"
AFlibIII_ASCii_Tunnel_Tweak TunSize_X, TunSize_Y, 0, -90, 3, 1, 0
ScreenSet 1, 0

AFlibIII_ASCii_Mouse_ClickSetup
AFlibIII_ASCii_ApplyMouseCursor 

While not AFlibIII_Detect_CloseWindow
  AFlibIII_ASCii_GrabMouse 
  If MultiKey(&h01) then Exit While
  TunImgCycTime -= 1
  If TunImgCycTime < 0 then
    TunImgCycTime = 0
    If MultiKey(&h39) then
      TunImgNo += 1: If TunImgNo > 3 then TunImgNo = 0
      TunImgCycTime = 10
      Select Case TunImgNo
        Case 0: AFlibIII_ASCii_Tunnel_GrabImage "Test256x256_1.bmp"
        Case 1: AFlibIII_ASCii_Tunnel_GrabImage "Test256x256_2.bmp"
        Case 2: AFlibIII_ASCii_Tunnel_GrabImage "Test256x256_3.bmp"
        Case 3: AFlibIII_ASCii_Tunnel_GrabImage "Test256x256_4.bmp"
      End Select
    End if
  End if
  AFlibIII_ASCii_ClearDisplay RGB(0, 0, 0)
  AFlibIII_ASCii_Tunnel_Blit 0, 0, TunSpd, TunSpd, TunSize_X, TunSize_Y, 255

  AFlibIII_ASCii_FilledBox chr(32), 0, 0, TxtGfx_X, 0, RGB(0, 0, 0), RGB(0, 0, 255), 1
  AFlibIII_ASCii_Print "ASCii-based TUNNEL TEST on AFlib III!!!", 5, 0, RGB(255, 255, 0), RGB(255, 0, 255), 4

  AFlibIII_ASCii_Line_alpha chr(32), 0, TxtGfx_Y - 1, TxtGfx_X, TxtGfx_Y - 1, RGB(0, 0, 0), RGB(0, 0, 0), 168, 1
  AFlibIII_ASCii_Print "Press [Space] to cycle through the images, or [ESC] to exit.", 7, TxtGfx_Y - 1, RGB(255, 255, 255), RGB(255, 0, 255), 17
  TunSpd += 1: If TunSpd > 255 then TunSpd = 0
  AFlibIII_ASCii_DisplayMouseCursor 
  AFlibIII_Customsync 70
  ScreenCopy
Wend

AFlibIII_ASCii_Tunnel_Destroy
AFlibIII_DeInit_ASCii
Screen 0: end









    'SPECIAL THANKS to D.J. Peters!!!
    