' FIRE.BAS - Run in MS QBasic 1.1
' baochan120 1/10/21

DECLARE SUB GenerateBottomRow ()
DECLARE SUB BubbleUp ()
DECLARE SUB DrawScreen ()
DECLARE SUB CreateLookups ()

RANDOMIZE TIMER

DIM SHARED GfxLookup(0 TO 100) AS STRING * 1
DIM SHARED ColorLookup(0 TO 100) AS INTEGER
DIM SHARED ScreenGrid(0 TO 23, 0 TO 79) AS INTEGER

CreateLookups

CLS

DO
  GenerateBottomRow
  BubbleUp
  DrawScreen
LOOP WHILE INKEY$ = ""

SUB BubbleUp

FOR CurrentRow% = 0 TO 22
  FOR CurrentCol% = 1 TO 78
    NewVal! = 0!
    NewVal! = NewVal! + ScreenGrid(CurrentRow% + 1, CurrentCol% - 1)
    NewVal! = NewVal! + ScreenGrid(CurrentRow% + 1, CurrentCol%)
    NewVal! = NewVal! + ScreenGrid(CurrentRow% + 1, CurrentCol% + 1)
    NewVal! = NewVal! / 3.6
    ScreenGrid(CurrentRow%, CurrentCol%) = NewVal!
  NEXT CurrentCol%
NEXT CurrentRow%

END SUB

SUB CreateLookups

LevelZero = 2
LevelOne = 5
LevelTwo = 10
LevelThree = 20

LevelGrey = 4
LevelRed = 7
LevelLightRed = 13
LevelYellow = 35

FOR i = 0 TO LevelZero
  GfxLookup(i) = " "
NEXT i

FOR i = LevelZero + 1 TO LevelOne
  GfxLookup(i) = CHR$(176)
NEXT i

FOR i = LevelOne + 1 TO LevelTwo
  GfxLookup(i) = CHR$(177)
NEXT i

FOR i = LevelTwo + 1 TO LevelThree
  GfxLookup(i) = CHR$(178)
NEXT i

FOR i = LevelThree + 1 TO 100
  GfxLookup(i) = CHR$(219)
NEXT i

FOR i = 0 TO LevelGrey
  ColorLookup(i) = 8
NEXT i

FOR i = LevelGrey + 1 TO LevelRed
  ColorLookup(i) = 4
NEXT i

FOR i = LevelRed + 1 TO LevelLightRed
  ColorLookup(i) = 12
NEXT i

FOR i = LevelLightRed + 1 TO LevelYellow
  ColorLookup(i) = 14
NEXT i

FOR i = LevelYellow + 1 TO 100
  ColorLookup(i) = 15
NEXT i

END SUB

SUB DrawScreen
 
  LOCATE 1, 1
 
  FOR CurrentRow% = 0 TO 22
    FOR CurrentCol% = 0 TO 79
      PixelIndex% = ScreenGrid(CurrentRow%, CurrentCol%)
      COLOR ColorLookup(PixelIndex%)
      PRINT GfxLookup(PixelIndex%);
    NEXT CurrentCol%
  NEXT CurrentRow%

END SUB

SUB GenerateBottomRow

  FOR CurrentCol% = 0 TO 79
   
    IF RND > .85 THEN
      ' Toggle current pixel between 0<->75
      ScreenGrid(23, CurrentCol%) = (ScreenGrid(23, CurrentCol%) * -1) + 75
    END IF
 
  NEXT CurrentCol%

END SUB

