' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2024.09.09.00.00]) on 2025.02.13 at 23:05 (Coordinated Universal Time)
' This program by Charlie Veniot
' based on the MSX program by VampierMSX (https://www.youtube.com/watch?v=Lyj5NmVQDWQ)

' 🟠🟠🟠 Declarations

  CONST botCount% = 150

  DIM posture$( 1 TO botCount% ), _
      xpos%( 1 TO botCount% ), _
      ypos%( 1 TO botCount% ), _
      c%( 1 TO botCount% )
      
  DIM beat% = 1

' 🟠🟠🟠 Main program

  SCREEN _NEWIMAGE( 240, 160, 13 )
  _INITAUDIO
  _SNDWAVE "SQUARE"
  GOSUB 🔷CreateBotPostures
  GOSUB 🔷InitBots
  _DISPLAY
  
  ➔LoopStart:
    GOSUB 🔷PrintBots
    SLEEP 1
    GOSUB 🔷ShiftPostures
  GOTO ➔LoopStart

  END

' 🟠🟠🟠 GOSUB Routines

🔷CreateBotPostures:
    LETCHR$( 0, "...XX..." _
              + "...XX..." _
              + ".X......" _
              + ".XXXXXX." _
              + "...XX.X." _
              + "...XX.X." _
              + ".XXXXX.." _
              + "XX..XX.." )
    LETCHR$( 1, "...XX..." _
              + "...XX..." _
              + "......X." _
              + ".XXXXXX." _
              + ".X.XX..." _
              + ".X.XX..." _
              + "..XXXXX." _
              + "..XX..XX" )
  RETURN

🔷InitBots:
    FOR i = 1 TO botCount%
        posture$(i) = CHR$( INT( RND * 2 ) )
        xpos%(i) = INT( RND * ( _WIDTH / 8 )  ) + 1
        ypos%(i) = INT( RND * ( ( _HEIGHT - 16 ) / 8 ) ) + 2
        c%(i) = INT( RND * 64 ) + 1
    NEXT i
  RETURN

🔷PrintBots:
    FOR i = 1 TO botCount%
        COLOR c%(i)
        LOCATE ypos%(i), xpos%(i)
        PRINT posture$(i);
    NEXT i
    _DISPLAY
  RETURN
  
🔷ShiftPostures:
    FOR i = 1 TO botCount%
        IF INT(RND*2) = 1 THEN posture$(i) = IFF( posture$(i) = CHR$(0), CHR$(1), CHR$(0) )
    NEXT i
    IF beat% = 1 THEN GOSUB 🪘BeatOne ELSE IF beat% = 3 THEN GOSUB 🪘BeatThree ELSE GOSUB 🪘BeatOther
    beat% = beat% + 1 : IF beat% > 4 THEN beat% = 1
  RETURN
  
🪘BeatOne:
    SOUND 32.703, 2
    SOUND 1, 5
    SOUND 32.703, 2
  RETURN

🪘BeatThree:
  SOUND 73.416, 2
  RETURN

🪘BeatOther:
  SOUND 48.999, 2
  RETURN