    nomainwin

    ON ERROR GOTO [errorhandler]

    'Global variables - amend to suite
    global collisionname$, cname$, list$, name$, check, sx, sy, cx, cy, px, py

    WindowWidth = 646
    WindowHeight = 516
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    graphicbox #main.header, 0, 0, 640, 20
    graphicbox #main.graph, 0, 20, 640, 460

    open  "Graphic Window" for window_nf as #main
    print #main.header, "down; fill black; flush"
    print #main.header, "font times_new_roman 14"
    print #main.graph, "fill black; flush"
    #main.graph, "getbmp blankscreen 0 0 640 480";
    print #main.graph, "setfocus"
    print #main.graph, "when characterInput [keyactions]"
    print #main, "trapclose [checkclose]"
    'print #main.graph, "when mouseMove [putsprite]"

[start]
    level = 1

    'Dimension pathnodes
    dim movement(30,2)

    'Set Global variables
    gosub [setvariables]

    'open game level
    FilePathName$ = DefaultDir$ + "\" + textfile$ + ".txt"
    gosub [openwork]

[nextlevelstart]
'load next level
    if (nextlevel = 1) then
        nextlevel = 0
        level = level + 1
        if (level > levels) then
                notice "End of Game"
                close #main
                end
        end if
        FilePathName$ = DefaultDir$ + "\" + textfile$ + str$(level) + ".txt"
        goto [openwork]
    end if

wait

[loop]
wait

[checkclose]
    confirm "Exit Game Y/N?"; response$
    if(response$ = "Yes") or (response$ = "yes") then close #main : end
wait

[errorhandler]
    notice "Error has ocurred : " + chr$(34) + Err$ + chr$(34)
    if (Err = 53) then notice "Check the TEXTFILE name in your .BAS file"
    if (Err = 53) then
        close #main
        end
    end if
goto [loop]


[openwork]
[nextlevel]
    if FilePathName$<>"" then
        open FilePathName$ for input as #1
    else
        notice "file " + FilePathName$ + " not found!"
        close #main
    end
    end if

    if (level = 1) then
        textfile$ = ""
        for n = len(FilePathName$)-5 to 1 step -1
            if(Mid$(FilePathName$,n,1) <> "\") then textfile$ = Mid$(FilePathName$,n,1)+textfile$
            if(Mid$(FilePathName$,n,1) = "\") then exit for
        next n
    end if

    node = 0
    p = 0
    while eof(#1) = 0
        line input #1, text$
[pass]
        select case text$
         case "LOADED BMPS"
                p = 1
                line input #1, text$
         case "ACTIVE BACKGROUND"
                p = 2
                line input #1, text$
         case "ACTIVE SPRITES"
                p = 3
                line input #1, text$
         case "KEYS SELECTED"
                p = 4
                line input #1, text$
         case "SET PATH NODES"
                p = 5
                line input #1, text$
         case "OPTION VALUES"
                p = 6
                'line input #1, text$
        end select
         if p = 1 then
            if (text$ = "ACTIVE BACKGROUND") then goto [pass]
            SpriteName$ = ""
            loadpath$ = ""
            for n = len(text$)-5 to 1 step -1
                if(Mid$(text$,n,1) <> "\") then SpriteName$ = Mid$(text$,n,1) + SpriteName$
                if(Mid$(text$,n,1) = "\") then exit for
            next n
            drv$ = left$(DefaultDir$,3)
            check = instr(text$, drv$)
            loadpath$ = Mid$(text$, check, len(text$)-check)
            loadbmp SpriteName$, loadpath$
            SpriteName$ = ""
         end if
         if p = 2 then
            if (text$ = "ACTIVE SPRITES") then goto [pass]
            bn$ = mid$(text$, 21, len(text$)-21)
            #main.graph, bn$
         end if
         if p = 3 then
            if (text$ = "KEYS SELECTED") then goto [pass]
                SpriteName$ = ""
            for n = 31 to len(text$)
                if(Mid$(text$,n,1) <> " ") then SpriteName$ = SpriteName$ + Mid$(text$,n,1)
                if(Mid$(text$,n,1) = " ") then exit for
            next n

            p$ = Mid$(text$,21,14)

            bn$ = mid$(text$, 21, len(text$)-21)
            #main.graph, bn$
            #main.graph, "drawsprites"
         end if
         if p = 4 then
            if (text$ = "SET PATH NODES") then goto [pass]
            'keys = keys+1
            'keyboard$(keys) = text$
            'setkey$(keys-6) = Mid$(text$,7,1) + Mid$(text$,17,len(text$)-16)
         end if
         if p = 5 then
            if (text$ = "OPTION VALUES") then goto [pass]
            node = node+1
            movement(node,1) = val(text$)
            line input #1, text$
            movement(node,2) = val(text$)
         end if
         if p = 6 then
            if (text$ = "END") then EXIT WHILE
                line input #1, text$
                    jumpheight = val(text$)
                line input #1, text$
                    jumpdistance = val(text$)
                line input #1, text$
                    gravity = val(text$)
                line input #1, text$
                    leftspeed = val(text$)
                line input #1, text$
                    rightspeed = val(text$)
                line input #1, text$
                    upspeed = val(text$)
                line input #1, text$
                    downspeed = val(text$)
                line input #1, text$
                    pauselength = val(text$)
                line input #1, text$
                    top = val(text$)
                line input #1, text$
                    bottom = val(text$)
                line input #1, text$
                    left = val(text$)
                line input #1, text$
                    right = val(text$)
                line input #1, text$
                    if (level = 1) then levels = val(text$)
                line input #1, text$
                    spriteheight = val(text$)
                line input #1, text$
                    spritewidth = val(text$)
                for n = 1 to 11
                    line input #1, text$
                    if (text$ = "End of Collision Names") then exit for
                    collisionname$(n) = text$
                next n
                line input #1, text$
                    SpriteName$ = text$
                line input #1, text$
                    animation$ = text$
                line input #1, text$
                    turnsprite$ = text$
                line input #1, text$
                    ground = val(text$)
                line input #1, text$
                    bounce$ = text$
                line input #1, text$
                    parachute$ = text$
                line input #1, text$
                    freemovement$ = text$
                line input #1, text$
                    ladder$ = text$
                line input #1, text$
                    moveall$ = text$
                line input #1, text$
                    runpath$ = text$
                line input #1, text$
                    pathsprite$ = text$
                for n = 1 to 11
                    line input #1, text$
                    if (text$ = "End of MoveObject Names") then exit for
                    moveobject$(n) = text$
                next n
                for n = 1 to 11
                    line input #1, text$
                    if (text$ = "End of MoveAllObject Names") then exit for
                    moveallobj$(n) = text$
                next n
                line input #1, text$
                    livesname1$ = text$
                line input #1, text$
                    livesname2$ = text$
                line input #1, text$
                    livespos$ = text$
                line input #1, text$
                    panel$ = text$
                line input #1, text$
                    if (level = 1) then livesnum1 = val(text$)
                line input #1, text$
                    if (level = 1) then livesnum2 = val(text$)
            end if
    wend

[endload]
    close #1
    gosub [userinfo]
    gosub [drawlives]


wait






