DECLARE SUB dinput (a!, b!, b2!, c!)
DECLARE SUB printto (a$, row!, column!)
DECLARE SUB pause ()
DECLARE SUB efxload (a$)

DIM SHARED ball(144)
DIM SHARED brick(384)
DIM x(100)
DIM y(100)

efxload "Bricks.efx"

CALL pause

CLS
PALETTE

a = TIMER




FOR a = 1 TO 100
x(a) = 0
y(a) = 0
NEXT a

should.be = 0
added = 0

RANDOMIZE TIMER
SCREEN 13
COLOR 15

PRINT "Calculating Computer Speed"

a = TIMER

FOR b = 1 TO 100000
        PSET ((b / 320), 11), INT(b / 255)
        PSET ((b / 320), 12), INT(b / 255)
        PSET ((b / 320), 13), INT(b / 255)
        PSET ((b / 320), 14), INT(b / 255)
        PSET ((b / 320), 15), INT(b / 255)
NEXT b

b = TIMER

speed = (a / b) / 2

main.thingy:



SCREEN 0
COLOR , 12
CLS

FOR a = 1 TO 15
COLOR a
printto "Brick Jumper!", 5, a
SOUND 0, 1
NEXT a
PRINT

COLOR 15
PRINT
SOUND 0, 1
COLOR (INT(RND * 15) + 1)
PRINT "What you want to do?"
SOUND 0, 1
COLOR (INT(RND * 15) + 1)
PRINT "1. Play the game!"
SOUND 0, 1
COLOR (INT(RND * 15) + 1)
PRINT "2. Tell me about the game!"
SOUND 0, 1
COLOR (INT(RND * 15) + 1)
PRINT "3. See who is the best of the best!"
SOUND 0, 1
COLOR (INT(RND * 15) + 1)
PRINT "4. Leave the game!"
COLOR (INT(RND * 15) + 1)
PRINT "I want to do #"



DO
SELECT CASE INKEY$
        CASE IS = "1"
                PRINT
                SOUND 0, 1
                PRINT "1. Wussy"
                SOUND 0, 1
                PRINT "2. Average"
                SOUND 0, 1
                PRINT "3. Cool"
                SOUND 0, 1
                PRINT "4. Rising fast"
                SOUND 0, 1
                PRINT "5. Arrgh!"
       
                PRINT "I Will Play on Difficulty Level #"

                DO
                SELECT CASE INKEY$
                        CASE IS = "1"
                                should.be = 1000
                                added = should.be
                                GOTO start
                        CASE IS = "2"
                                should.be = 750
                                added = should.be
                                GOTO start
                        CASE IS = "3"
                                should.be = 500
                                added = should.be
                                GOTO start
                                difficulty = difficulty + 3
                        CASE IS = "4"
                                should.be = 250
                                added = should.be
                                GOTO start
                                difficulty = difficulty + 5
                        CASE IS = "5"
                                should.be = 100
                                added = should.be
                                difficulty = difficulty + 8
                                GOTO start
                END SELECT
                LOOP

        CASE IS = "2"
                PRINT
                PRINT "That's what the readme"
                SOUND 0, 1
                PRINT "is for dolt!"
                CALL pause
                GOTO main.thingy

        CASE IS = "3"
               
                CLS
               
                SELECT CASE INT(RND * 9) + 1
                        CASE IS = 1
                                PRINT "The Champ!"
                                PRINT STRING$(10, "*")
                        CASE IS = 2
                                PRINT "Da Bomb!"
                                PRINT STRING$(7, "*")
                        CASE IS = 3
                                PRINT "Ultimate!"
                                PRINT STRING$(8, "*")
                        CASE IS = 4
                                PRINT "Best of the Best!"
                                PRINT STRING$(17, "*")
                        CASE IS = 5
                                PRINT "Best Brick Jumper!"
                                PRINT STRING$(18, "*")
                        CASE IS = 6
                                PRINT "Brick Jumper King!"
                                PRINT STRING$(18, "*")
                        CASE IS = 7
                                PRINT "Top Player!"
                                PRINT STRING$(11, "*")
                        CASE IS = 8
                                PRINT "Highest Score!"
                                PRINT STRING$(14, "*")
                        CASE IS = 9
                                PRINT "Best Player!"
                                PRINT STRING$(12, "*")
                        CASE IS = 10
                                PRINT "Raven Award for Best Player!"
                                PRINT STRING$(28, "*")
                END SELECT
               
                OPEN "BrickDat.brk" FOR BINARY AS #1
              
                a$ = STRING$(27, " ")
              
                GET #1, 1, a$
              
                PRINT
             
                COLOR (INT(RND * 14) + 1)
                PRINT a$
               
                PRINT
                CLOSE #1
                CALL pause
                GOTO main.thingy

        CASE IS = "4"
                PRINT
                PRINT "Ta ta!"
                CALL pause
                CLS
                END
END SELECT
LOOP



start:
SCREEN 13
CLS


FOR x = 1 TO 12
        FOR y = 1 TO 12
                READ z
                PSET (x, y), z
        NEXT y
NEXT x
GET (1, 1)-(12, 12), ball

CLS

FOR y = 1 TO 12
        FOR x = 1 TO 32
                READ z
                PSET (x, y), z
        NEXT x
NEXT y

GET (1, 1)-(32, 12), brick
CLS

x = 100
y = 10
score = 0
level = 1


FOR c = 1 TO 10
x(c) = INT(RND * 211) + 1
y(c) = 112


PUT (x(c), y(c)), brick

NEXT c


LINE (1, 132)-(250, 132), 15
FOR a = 1 TO 50
        LINE (1, a + 132)-(250, a + 132), 6
NEXT a

LINE (1, 132)-(1, 1), 15
LINE (250, 132)-(250, 1), 15

how.high = 132
should.be = 500


main:

SOUND 0, speed

printto "SCORE", 3, 35
printto "LEVEL", 5, 35



DO

a$ = INKEY$
        SELECT CASE a$
               
                CASE IS = "a"
                        IF x <= 1 THEN
                                GOTO main
                        END IF
                       
                        FOR a = 1 TO 11
                                IF POINT(x, y + a) = 6 THEN
                                        GOTO main
                                END IF
                        NEXT a

                        PUT (x, y), ball
                        x = x - 2
                        PUT (x, y), ball
                        a$ = ""

                CASE IS = "d"
                        IF x >= 235 THEN
                                GOTO main
                        END IF
                       
                        FOR a = 1 TO 11
                                IF POINT(x + 12, y + a) = 6 THEN
                                        GOTO main
                                END IF
                        NEXT a
                       
                        PUT (x, y), ball
                        x = x + 2
                        PUT (x, y), ball
                       
                        a$ = ""
                END SELECT

        
       
        printto STR$(score), 4, 35
       
        printto STR$(level), 6, 35

       
        IF score >= should.be THEN
                how.high = how.high - 1
                level = level + 1
                should.be = should.be + added
                LINE (1, how.high)-(250, how.high), 15
                score = score + (difficulty * 5)
        END IF


        IF y <= 5 THEN GOTO ende
        FOR c = 1 TO 10
                IF y(c) >= 12 THEN
                        PUT (x(c), y(c)), brick
                        y(c) = y(c) - 1
                        PUT (x(c), y(c)), brick

                ELSE
                        x(c) = INT(RND * 211) + 1
                        y(c) = INT(RND * 10) + how.high

                END IF
        NEXT c
       


        IF y >= 120 THEN
        y = 120
        GOTO main
        END IF

        FOR a = 0 TO 12
                IF POINT(x + a, y + 12) = 6 THEN
                PUT (x, y), ball
                y = y - 1
                PUT (x, y), ball
                GOTO main
                END IF
        NEXT a

        FOR a = 0 TO 12
                IF POINT(x + a, y + 13) = 15 THEN
                GOTO ende
                END IF
        NEXT a


        PUT (x, y), ball
        y = y + 1
        PUT (x, y), ball
        
        score = INT(score + difficulty * 1.5)

a$ = ""

GOTO main

LOOP



ende:
printto "OH NO!", 10, 15
PLAY "L18 MF O2 G# G G- D# D D-"

DO UNTIL INKEY$ <> ""
LOOP

CLS
FOR a = 1 TO 9
printto "Game Over!", 5, a
SOUND 0, .2
NEXT a
SOUND 0, 4

FOR a = 1 TO 11
printto "Final Score", 6, a
SOUND 0, .2
NEXT a

a$ = "" + STR$(score)

FOR a = 1 TO 13
printto a$, 7, a
SOUND 0, .2
NEXT a

OPEN "BrickDat.brk" FOR BINARY AS #1
a$ = STRING$(10, " ")
GET #1, 16, a$
a = VAL(a$)




IF score > a THEN
PRINT "You have gotten a high score!"
PRINT "Please enter your name!"
CALL dinput(15, 15, 1, 15)

IF LEN(output$) < 15 THEN
DO UNTIL LEN(output$) = 15
output$ = output$ + " "
LOOP
END IF

PUT #1, 1, output$

score$ = STR$(score)
IF LEN(score$) < 10 THEN
DO UNTIL LEN(score$) = 10
score$ = score$ + " "
LOOP
PUT #1, 16, score$
END IF
PRINT "Congratulations!"
END IF

PALETTE

CALL pause
CLS
CLOSE
END




'ball
DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
DATA 0, 0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0
DATA 0, 0, 0, 4, 12, 12, 12, 12, 4, 0, 0, 0
DATA 0, 0, 4, 12, 12, 12, 12, 12, 12, 4, 0, 0
DATA 0, 4, 12, 12, 12, 12, 12, 12, 12, 12, 4, 0
DATA 0, 4, 12, 12, 12, 12, 12, 12, 12, 12, 4, 0
DATA 0, 4, 12, 12, 12, 12, 12, 12, 12, 12, 4, 0
DATA 0, 4, 12, 12, 12, 12, 12, 12, 12, 12, 4, 0
DATA 0, 0, 4, 12, 12, 12, 12, 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 0
DATA 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 0
DATA 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 0
DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

SUB dinput (a, b, b2, c)
  SHARED output$

  output$ = ""
  I$ = ""

  lin = CSRLIN
  min = POS(0)
  max = a + min
  IF max > 80 THEN PRINT "DInput failed - String line too long"

IF max < 81 THEN
  clr = b
  bckclr = b2
  csrclr = c
  length = a
  current = 0

  WHILE I$ <> CHR$(13)
    COLOR csrclr
    LOCATE lin, min + current
    PRINT "_"

    COLOR clr
    I$ = ""
    WHILE I$ = ""
      I$ = INKEY$
    WEND
    IF ASC(I$) > 31 AND ASC(I$) < 127 AND current <> length THEN
      LOCATE lin, min + current
      PRINT I$
      output$ = output$ + I$
      current = current + 1
    END IF
    IF ASC(I$) = 8 AND current > 0 THEN
      current = current - 1
      output$ = LEFT$(output$, LEN(output$) - 1)
      LOCATE lin, min + current + 1
      PRINT " "
    END IF

  WEND

LOCATE lin, min + current
PRINT " "
END IF
COLOR clr

END SUB

SUB efxload (a$)
DEFINT A-Z
DIM Prefix(4095), Suffix(4095), OutStack(4095), shiftout%(8)
DIM Ybase AS LONG, powersof2(11) AS LONG, WorkCode AS LONG

FOR a% = 0 TO 7: shiftout%(8 - a%) = 2 ^ a%: NEXT a%
FOR a% = 0 TO 11: powersof2(a%) = 2 ^ a%: NEXT a%
IF a$ = "" THEN INPUT "efx file"; a$: IF a$ = "" THEN END
IF INSTR(a$, ".") = 0 THEN a$ = a$ + ".efx"
OPEN a$ FOR BINARY AS #1
a$ = "      ": GET #1, , a$

GET #1, , TotalX: GET #1, , TotalY: GOSUB GetByte
NumColors = 2 ^ ((a% AND 7) + 1): NoPalette = (a% AND 128) = 0
GOSUB GetByte: Background = a%
GOSUB GetByte: IF a% <> 0 THEN PRINT "Bad screen descriptor.": END
IF NoPalette = 0 THEN P$ = SPACE$(NumColors * 3): GET #1, , P$
DO
    GOSUB GetByte
    IF a% = 44 THEN
        EXIT DO
    ELSEIF a% <> 33 THEN
        PRINT "Unknown extension type.": END
    END IF
    GOSUB GetByte
    DO: GOSUB GetByte: a$ = SPACE$(a%): GET #1, , a$: LOOP UNTIL a% = 0
LOOP
GET #1, , XStart: GET #1, , YStart: GET #1, , XLength: GET #1, , YLength
XEnd = XStart + XLength: YEnd = YStart + YLength: GOSUB GetByte
IF a% AND 128 THEN PRINT "Can't handle local colormaps.": END
Interlaced = a% AND 64: PassNumber = 0: PassStep = 8
GOSUB GetByte
ClearCode = 2 ^ a%
EOSCode = ClearCode + 1
FirstCode = ClearCode + 2: NextCode = FirstCode
StartCodeSize = a% + 1: CodeSize = StartCodeSize
StartMaxCode = 2 ^ (a% + 1) - 1: MaxCode = StartMaxCode

BitsIn = 0: BlockSize = 0: BlockPointer = 1
x% = XStart: y% = YStart: Ybase = y% * 320&

SCREEN 13: DEF SEG = &HA000
IF NoPalette = 0 THEN
    OUT &H3C7, 0: OUT &H3C8, 0
    FOR a% = 1 TO NumColors * 3: OUT &H3C9, ASC(MID$(P$, a%, 1)) \ 4: NEXT a%
END IF
LINE (0, 0)-(319, 199), Background, BF
DO
    GOSUB GetCode
    IF Code <> EOSCode THEN
        IF Code = ClearCode THEN
            NextCode = FirstCode
            CodeSize = StartCodeSize
            MaxCode = StartMaxCode
            GOSUB GetCode
            CurCode = Code: LastCode = Code: LastPixel = Code
            IF x% < 320 THEN POKE x% + Ybase, LastPixel
            x% = x% + 1: IF x% = XEnd THEN GOSUB NextScanLine
        ELSE
            CurCode = Code: StackPointer = 0
            IF Code > NextCode THEN EXIT DO
            IF Code = NextCode THEN
                CurCode = LastCode
                OutStack(StackPointer) = LastPixel
                StackPointer = StackPointer + 1
            END IF

            DO WHILE CurCode >= FirstCode
                OutStack(StackPointer) = Suffix(CurCode)
                StackPointer = StackPointer + 1
                CurCode = Prefix(CurCode)
            LOOP

            LastPixel = CurCode
            IF x% < 320 THEN POKE x% + Ybase, LastPixel
            x% = x% + 1: IF x% = XEnd THEN GOSUB NextScanLine

            FOR a% = StackPointer - 1 TO 0 STEP -1
                IF x% < 320 THEN POKE x% + Ybase, OutStack(a%)
                x% = x% + 1: IF x% = XEnd THEN GOSUB NextScanLine
            NEXT a%

            IF NextCode < 4096 THEN
                Prefix(NextCode) = LastCode
                Suffix(NextCode) = LastPixel
                NextCode = NextCode + 1
                IF NextCode > MaxCode AND CodeSize < 12 THEN
                    CodeSize = CodeSize + 1
                    MaxCode = MaxCode * 2 + 1
                END IF
            END IF
            LastCode = Code
        END IF
    END IF
LOOP UNTIL DoneFlag OR Code = EOSCode
'BEEP
'A$ = INPUT$(1)
CLOSE #1
EXIT SUB

GetByte: a$ = " ": GET #1, , a$: a% = ASC(a$): RETURN

NextScanLine:
    IF Interlaced THEN
        y% = y% + PassStep
        IF y% >= YEnd THEN
            PassNumber = PassNumber + 1
            SELECT CASE PassNumber
            CASE 1: y% = 4: PassStep = 8
            CASE 2: y% = 2: PassStep = 4
            CASE 3: y% = 1: PassStep = 2
            END SELECT
        END IF
    ELSE
        y% = y% + 1
    END IF
    x% = XStart: Ybase = y% * 320&: DoneFlag = y% > 199
RETURN
GetCode:
    IF BitsIn = 0 THEN GOSUB ReadBufferedByte: LastChar = a%: BitsIn = 8
    WorkCode = LastChar \ shiftout%(BitsIn)
    DO WHILE CodeSize > BitsIn
        GOSUB ReadBufferedByte: LastChar = a%
        WorkCode = WorkCode OR LastChar * powersof2(BitsIn)
        BitsIn = BitsIn + 8
    LOOP
    BitsIn = BitsIn - CodeSize
    Code = WorkCode AND MaxCode
RETURN
ReadBufferedByte:
    IF BlockPointer > BlockSize THEN
        GOSUB GetByte: BlockSize = a%
        a$ = SPACE$(BlockSize): GET #1, , a$
        BlockPointer = 1
    END IF
    a% = ASC(MID$(a$, BlockPointer, 1)): BlockPointer = BlockPointer + 1
RETURN

END SUB

DEFSNG A-Z
SUB pause
DO UNTIL INKEY$ <> ""
LOOP
END SUB

SUB printto (a$, row, column)
LOCATE row, column
PRINT a$
END SUB

