' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2023.11.19.18.55]) on 2023.11.24 at 21:52 (Coordinated Universal Time)
' BAM port and mod of Jason Anthony's QB64 program (https://sourceforge.net/projects/fish-screensaver-for-win-10/)

OPTION EXPLICIT

' 🟠🟠🟠 Declarations

  DECLARE SUB InitFish(f%)
  DECLARE SUB MoveFish(f%)
  DECLARE SUB DrawFishBit(f%, x1%, y1%, x2%, y2%)

  DIM sw% = 640, sh% = 360

  TYPE tFish
    x% : y%
    color%
    direction%
    counter%
    speed%
  END TYPE

  fish_directions: CONST LEFT% = -1, RIGHT% = +1

  DIM i%, fish_count%
  fish_count% = MAX(VAL(NVL$(_PROMPT( "How many fish in the aquarium?", "2"), "2")),2)
  DIM fish(1 TO fish_count%) as tFish

' 🟠🟠🟠 Initialisation

  FOR i% = 1 TO fish_count%
      InitFish(i%)
  NEXT i%

  SCREEN _NEWIMAGE(sw%, sh%, 17)

' 🟠🟠🟠 Main program

  🏁StartMoveFishCycle: 'Starts main loop
      CLS 'Erases old image after new image appears to avoid trail of images
      _DELAY 0.01 ' 2
      FOR i% = 1 TO fish_count%
          MoveFish(i%)
      NEXT i%
      _DISPLAY 'New simpler version of pcopy - Eliminates screen flicker from partial screen refresh frames
  🏁EndMoveFishCycle: GOTO 🏁StartMoveFishCycle

' 🟠🟠🟠 Subroutines

  SUB InitFish(f%)
      fish(f%).direction% = CHOOSE(INT(RND*2)+1,LEFT%,RIGHT%)
      fish(f%).x% = IFF(fish(f%).direction% = LEFT%, sw% , 0) - RND * sw% * fish(f%).direction% 'Starting point for Right moving fish
      fish(f%).y% = ( sh% - 40 )  * RND + 10
      fish(f%).color% = RND*63 + 1 'Starting color for Right moving fish
      fish(f%).counter% = RND * 20
      fish(f%).speed% = IFF(INT(RND * 5 + 1) = 5, 2, 1)
  END SUB

  SUB DrawFishBit(f%, x1%, y1%, x2%, y2%)
      LINE (fish(f%).x% - x1% * fish(f%).direction%, fish(f%).y% + y1%) _
        TO (fish(f%).x% - x2% * fish(f%).direction%, fish(f%).y% + y2%), fish(f%).color%, BF
  END SUB

  SUB MoveFish(f%)
   
      DrawFishBit(f%, 13, 0, 18,  2)
      DrawFishBit(f%,  8, 2, 13,  4)
      DrawFishBit(f%, 18, 2, 23,  4)
      fish(f%).counter% = fish(f%).counter% + 1
      IF fish(f%).counter% = 21 _
         THEN fish(f%).counter% = 0
      IF fish(f%).counter% < 20 * .7 _
         THEN DrawFishBit(f%, 33, 2, 35, 4) : DrawFishBit(f%, 33, 16, 35, 18)
      DrawFishBit(f%,  5, 4,  8,  6)
      DrawFishBit(f%, 23, 4, 25,  6)
      DrawFishBit(f%, 30, 4, 33,  6)
      DrawFishBit(f%,  3, 6,  5,  8)
      DrawFishBit(f%,  9, 6, 11,  8)
      DrawFishBit(f%, 23, 6, 30,  8)
      DrawFishBit(f%,  0, 8,  3, 10)
      IF fish(f%).counter% < 20 * .5  _
         THEN DrawFishBit(f%, 15, 8, 18, 10) : DrawFishBit(f%, 15, 10, 18, 12)
      DrawFishBit(f%, 28,  8, 30, 10)
      DrawFishBit(f%,  0, 10,  3, 12)
      DrawFishBit(f%, 13, 10, 15, 12)
      DrawFishBit(f%, 28, 10, 30, 12)
      DrawFishBit(f%,  3, 12,  8, 14)
      DrawFishBit(f%, 23, 12, 30, 14)
      DrawFishBit(f%,  5, 14,  8, 16)
      DrawFishBit(f%, 23, 14, 25, 16)
      DrawFishBit(f%, 30, 14, 33, 16)
      DrawFishBit(f%,  8, 16, 13, 18)
      DrawFishBit(f%, 18, 16, 23, 18)
      DrawFishBit(f%, 13, 18, 18, 20)

      fish(f%).x% = fish(f%).x% + ( fish(f%).direction% * fish(f%).speed% )
      IF (fish(f%).direction% = LEFT% AND fish(f%).x% < -100) _
         OR (fish(f%).direction% = RIGHT% AND fish(f%).x% > XMAX+100) THEN Initfish(f%)
  END SUB