`Fast-Paced Gameplay Challenge
sync on
sync rate 60
autocam off
hide mouse
disable escapekey
 
`Varibales
type camspot
    x
    y
    z
    xa
    ya
endtype
type plyr
    b
    t
    g1
    g2
endtype
type npc_flash
    a
    b
endtype
 
global _SEED = 23098426374
 
global flash_fade = 0
global flash_stage
global nextFlashTimer
global mode = 0
dim walls(1)
global wall_count = 0
global hittingWall
global wallOverlap
global mouseLock
global map AS STRING
global scr_w
global scr_h
    scr_w = screen width()
    scr_h = screen height()
global inLSMenu
global p_velo#
 
global cam1 as camspot
    cam1.x = -1449
    cam1.y = 342
    cam1.z = -11
    cam1.xa = 14
    cam1.ya = 90
global cam2 as camspot
    cam2.x = -405
    cam2.y = 145
    cam2.z = -348
    cam2.xa = 17
    cam2.ya = 49
global play
 
global p as plyr
    p.b = 6
    p.t = 7
    p.g1 = 8
    p.g2 = 9
 
dim npc(5) as plyr
dim npc_wc(5)
dim mfo(30)
dim mfof(30)
dim npc_mf(5) as npc_flash
dim death_phrase(10) as string
 
dim npc_health(5)
    for i = 1 to 5
        npc_health(i) = 100
    next i
global p_health = 100
dim npc_rt(5)
 
`Death Phrases
death_phrase(1) = "You got killed."
death_phrase(2) = "Ouch."
death_phrase(3) = "Kaboom! You're dead."
death_phrase(4) = "You never had a chance."
death_phrase(5) = "Bummer."
death_phrase(6) = "You just lost to a bot."
death_phrase(7) = "Well, I don't suppose you ever had a chance..."
death_phrase(8) = "Owned."
death_phrase(9) = "You can't win against the BOTS."
death_phrase(10) = "Nice try."
 
`Make Environment
make object plain 4,500,500
xrotate object 4,270
 
    `Make Image
    create bitmap 1,512,512
    ink rgb(64, 64, 64),0
    box 0,0,512,512
 
    ink rgb(115, 115, 115),0
    box 0,0,10,512
    box 502,0,512,512
    box 0,0,512,10
    box 0,502,512,512
 
    get image 1,0,0,512,512
    delete bitmap 1
 
texture object 4,1 : scale object texture 4,50,50
set alpha mapping on 4,50
 
color backdrop 0
 
`Outside Sphere
make object sphere 2,-1000
color object 2,rgb(255, 128, 0)
 
`Flash Sphere
make object sphere 3,-900
 
    `Texture
    create bitmap 1,64,64
    set current bitmap 1
    ink 0,0
    box 0,0,64,64
 
    ink rgb(255,255,255),0
    box 8,8,40,16
 
    blur bitmap 1,6
    blur bitmap 1,6
    get image 2,0,0,64,64
    set current bitmap 0
    delete bitmap 1
 
texture object 3,2
ghost object on 3
`set object light 3,0
 
 
`Lights
for i = 1 to 7
    make light i
    position light i,rnd(1500)-750,rnd(1500)-750,rnd(1500)-750
    color light i,rnd(255),rnd(128),0
    set light range i,1000
next i
set ambient light 0
 
`levedit crosshair
create bitmap 1,16,16
set current bitmap 1
 
ink 0,0
box 0,0,16,16
 
ink rgb(255,255,255),0
box 0,0,16,2
box 0,0,2,16
box 0,14,16,16
box 14,0,16,16
 
get image 3,0,0,16,16
set current bitmap 0
delete bitmap 1
set image colorkey 0,0,0
 
`Placement Marker
    `Make Image
    create bitmap 1,512,512
    ink rgb(0,0,0),0
    box 0,0,512,512
 
    ink rgb(200,200,200),0
    box 0,0,10,512
    box 502,0,512,512
    box 0,0,512,10
    box 0,502,512,512
 
    get image 4,0,0,512,512
    delete bitmap 1
make object box 5,50,25,50
texture object 5,4
set object transparency 5,2
set object cull 5,0
 
`Make Player
make object box p.b,25,10,35 : `Treat as if it were 12
color object p.b,rgb(74, 74, 74)
 
make object box p.t,10,5,15
    `Create Texture
    create bitmap 1,128,128
    set current bitmap 1
 
    Blue = rgb(0, 128, 255)
    White = rgb(255,255,255)
    box 0,0,128,128,Blue,White,White,Blue
 
    ink rgb(128, 128, 128),0
    box 0,0,128,4
    box 0,0,4,128
    box 0,124,128,128
    box 124,0,128,128
 
    get image 5,0,0,128,128
    set current bitmap 0
    delete bitmap 1
texture object p.t,5
set object light p.t,0
set alpha mapping on p.t,50
 
make object box p.g1,1,1,35
color object p.g1,rgb(192, 192, 192)
make object box p.g2,1,1,35
color object p.g2,rgb(192, 192, 192)
 
`Muzzleflash Image
create bitmap 1,128,128
set current bitmap 1
ink 0,0
box 0,0,128,128
ink rgb(254, 231, 150),0
box 32,32,96,96
ink rgb(255,255,255),0
box 40,40,88,88
for i = 1 to 10
    blur bitmap 1,6
next i
get image 6,0,0,128,128
set current bitmap 0
delete bitmap 1
 
`NPC Muzzleflash
for i = 1 to 5
    npc_mf(i).a = freeObject()
    make object plain npc_mf(i).a,sqrt(15)+(15/4),sqrt(15)+(15/4)
    texture object npc_mf(i).a,6
    ghost object on npc_mf(i).a
    set object light npc_mf(i).a,0
    hide object npc_mf(i).a
 
    npc_mf(i).b = freeObject()
    make object plain npc_mf(i).b,sqrt(15)+(15/4),sqrt(15)+(15/4)
    texture object npc_mf(i).b,6
    ghost object on npc_mf(i).b
    set object light npc_mf(i).b,0
    hide object npc_mf(i).b
next i
 
`Make NPC
for i = 1 to 5
    npc(i).b = freeObject()
    make object box npc(i).b,25,10,35
    color object npc(i).b,rgb(74, 74, 74)
 
    npc(i).t = freeObject()
    make object box npc(i).t,10,5,15
    texture object npc(i).t,5
    set object light npc(i).t,0
    set alpha mapping on npc(i).t,50
 
    npc(i).g1 = freeObject()
    make object box npc(i).g1,1,1,35
    color object npc(i).g1,rgb(192, 192, 192)
 
    npc(i).g2 = freeObject()
    make object box npc(i).g2,1,1,35
    color object npc(i).g2,rgb(192, 192, 192)
 
    position object npc(i).b,rnd(500)-250,6,rnd(500)-250
    PositionObjectsAsNPC(npc(i).b,npc(i).t,npc(i).g1,npc(i).g2,i)
next i
for i = 1 to 5
    hide object npc(i).b
    hide object npc(i).t
    hide object npc(i).g1
    hide object npc(i).g2
next i
 
`Muzzleflash Objects
for i = 1 to 15
    mfo(i) = freeObject()
    make object plain mfo(i),sqrt(i)+(i/4),sqrt(i)+(i/4)
    texture object mfo(i),6
    ghost object on mfo(i)
    set object light mfo(i),0
    hide object mfo(i)
    mfof(i) = 0
next i
for i = 1 to 15
    mfo(i+15) = freeObject()
    make object plain mfo(i+15),sqrt(i)+(i/4),sqrt(i)+(i/4)
    texture object mfo(i+15),6
    ghost object on mfo(i+15)
    set object light mfo(i+15),0
    hide object mfo(i+15)
    mfof(i+15) = 0
next i
 
position object p.b,0,6,0
PositionObjectsAsPlayer(p.b,p.t,p.g1,p.g2)
 
set object smoothing p.b,100
set object smoothing p.t,100
 
hide object p.b
hide object p.t
hide object p.g1
hide object p.g2
 
`Cube Map Image
create bitmap 1,512,512
White = rgb(255, 255, 255)
Grey = rgb(192, 192, 192)
set current bitmap 1
box 0,0,512,512,Grey,White,White,Grey
get image 7,0,0,512,512
set current bitmap 0
delete bitmap 1
 
`PRESET CAMERA
position camera cam1.x,cam1.y,cam1.z
rotate camera cam1.xa,cam1.ya,0
 
`*****************************
`MAIN LOOP
`*****************************
do
_MainLoopStart:
 
    `CHOOSE A MODE
    gosub _chooseMode
 
    `EDITOR
    gosub _levelEditor
 
    `GAME
    if mode = 2
        hide object 5
 
        `No map set
        if map = ""
            show mouse
            position camera curvevalue(cam2.x,camera position x(),20),curvevalue(cam2.y,camera position y(),20),curvevalue(cam2.z,camera position z(),20)
            rotate camera curveangle(cam2.xa,camera angle x(),20),curveangle(cam2.ya,camera angle y(),20),0
 
            set text font "verdana"
            set text size 24
            if abs(camera position x() - cam2.x) < 5 and abs(camera position y() - cam2.y) < 5 and abs(camera position z() - cam2.z) < 5
                if loadMapFromFile = 0
                    if button(screen width()/2,300,"Use Default Map") = 2
                        map = "!"
                        if wall_count > 0
                            for i = 1 to wall_count
                                delete object i
                            next i
                            wall_count = 0
                        endif
                    endif
                    if button(screen width()/2,340,"Load Map from File") = 2
                        loadMapFromFile = 1
                        FinalString$ = ""
                        StaticString$ = ""
                        clear entry buffer
                    endif
 
                    if escapekey() = 1 then mode = 0
                endif
                if loadMapFromFile = 1
                    ink rgb(255,255,255),0
                    center text screen width()/2,320,"What file would you like to load?"
 
                    if returnkey() = 1
                        map = FinalString$
                        skipCheck = 1
                    endif
 
                    if skipCheck = 0
                        CharHit$ = inkey$()
                        if CharHit$ = chr$(8)
                            StaticString$ = StaticString$ + entry$()
                            StaticString$ = left$(StaticString$,len(StatingString$)-1)
                            clear entry buffer
                        endif
                        FinalString$ = StaticString$ + entry$()
                        ink rgb(0, 0, 0),0
                        center text screen width()/2,345,FinalString$
                    endif
 
                    if escapekey() = 1 then loadMapFromFile = 0
                endif
            endif
        endif
 
        `Default Map
        if map = "!" and play = 0
            play = 1
        endif
 
        `Load Up a Map
        if map <> "" and map <> "!" and play = 0
            if file exist(map) = 0
                map = ""
            endif
 
            open to read 1,map
            read string 1,txt$
            NumBlocks = val(txt$)
            for i = 1 to NumBlocks
                read string 1,txt$
                xPos# = val(txt$)
                read string 1,txt$
                zPos# = val(txt$)
                read string 1,txt$
                xSize# = val(txt$)
                read string 1,txt$
                zSize# = val(txt$)
 
                inc wall_count
                array insert at bottom walls(0)
                walls(wall_count) = freeObject()
 
                make object box walls(wall_count),xSize#,25,zSize#
                position object walls(wall_count),xPos#,12.5,zPos#
                color object walls(wall_count),rgb(62, 62, 62)
                set object smoothing walls(wall_count),100
                set cube mapping on walls(wall_count),7,7,7,7,7,7
            next i
            close file 1
            play = 1
        endif
 
        `*********************
        `PLAY THE GAME
        `*********************
        if play = 1
            `The player has yet to be initialized
            show object p.b
            show object p.t
            show object p.g1
            show object p.g2
 
            `Show NPCs
            for i = 1 to 5
                show object npc(i).b
                show object npc(i).t
                show object npc(i).g1
                show object npc(i).g2
            next i
 
            `Move him & NPCs to an open spot
            if wall_count > 0
                for i = 1 to wall_count
                    while object collision(p.b,walls(i)) > 0
                        valid = rnd(500)-250
                        position object p.b,valid,6,valid
                        PositionObjectsAsPlayer(p.b,p.t,p.g1,p.g2)
                    endwhile
                    for x = 1 to 5
                        while object collision(npc(x).b,walls(i)) > 0
                            valid = rnd(500)-250
                            position object npc(x).b,valid,6,valid
                            PositionObjectsAsNPC(npc(x).b,npc(x).t,npc(x).g1,npc(x).g2,x)
                        endwhile
                    next x
                next i
            endif
 
            if escapekey() = 1 then end
 
            play = 2
        endif
 
        if play = 2
            `The player's been initialized
            set camera to follow object position x(p.b),object position y(p.b),object position z(p.b),object angle y(p.b),50,35,25,0
 
            `Update All Other Limbs
            PositionObjectsAsPlayer(p.b,p.t,p.g1,p.g2)
            for i = 1 to 5
                PositionObjectsAsNPC(npc(i).b,npc(i).t,npc(i).g1,npc(i).g2,i)
            next i
 
            `Check for wall collision
            for i = 1 to wall_count
                if object collision(p.b,walls(i)) = 1
                    playerWallCollision = 1
                    exit
                else
                    playerWallCollision = 0
                endif
            next i
 
            `Check for NPC Collision
            for i = 1 to 5
                for w = 1 to wall_count
                    if object collision(npc(i).b,walls(w)) = 1
                        npc_wc(i) = 1
                        exit
                    else
                        npc_wc(i) = 0
                    endif
                next w
            next i
 
            `Movement
                if upkey() = 1 and playerWallCollision = 0
                    p_velo# = curvevalue(1,p_velo#,10)
                else
                    if downkey() = 1
                        p_velo# = curvevalue(-0.5,p_velo#,10)
                    else
                        p_velo# = curvevalue(0,p_velo#,10)
                    endif
                endif
                if leftkey() = 1
                    yrotate object p.b,wrapvalue(object angle y(p.b)-1)
                endif
                if rightkey() = 1
                    yrotate object p.b,wrapvalue(object angle y(p.b)+1)
                endif
                move object p.b,p_velo#
 
            `Shooting
            if spacekey() = 1
                `Show muzzleflash
                for i = 1 to 30
                    show object mfo(i)
                next i
                RollMF()
 
                `Check for collision
                sx# = object position x(p.b)
                sy# = object position y(p.b)
                sz# = object position z(p.b)
                move object p.b,2000
                nx# = object position x(p.b)
                ny# = object position y(p.b)
                nz# = object position z(p.b)
                move object p.b,-2000
 
                for i = 1 to 5
                    if intersect object(npc(i).b,sx#,sy#,sz#,nx#,ny#,nz#) > 0 and npc_health(i) > 0
                        npc_health(i) = npc_health(i) - 1
 
                        if npc_health(i) < 1
                            npc_rt(i) = timer() + 10000
                        endif
                    endif
                next i
            else
                `HIde muzzleflash
                for i = 1 to 30
                    hide object mfo(i)
                next i
            endif 
 
            `Enemy AI
            for i = 1 to 5
                if npc_health(i) > 0
                    randomize _SEED*i*timer()
                    ai_val = rnd(100) : `Percent change simulator
                    if ai_val > 1 and ai_turning = 0 and npc_wc(i) = 0
                        move object npc(i).b,1
                        PositionObjectsAsNPC(npc(i).b,npc(i).t,npc(i).g1,npc(i).g2,i)
                    endif
                    if (ai_val >= 0 and ai_val < 1) or (ai_turning > 0) or (object position x(npc(i).b) > 250 or object position x(npc(i).b) < -250 or object position z(npc(i).b) > 250 or object position z(npc(i).b) < -250) 
                        if ai_turning = 0
                            ai_turnthisfar = rnd(10)-5
                        endif
                        inc ai_turning
                        yrotate object npc(i).b,object angle y(npc(i).b)+ai_turning
                        if ai_turning > ai_turnthisfar
                            ai_turning = 0
                            ai_turnthisfar = 0
                        endif
                    endif
                    if ai_val <= 0
                        move object npc(i).b,-0.5
                        PositionObjectsAsNPC(npc(i).b,npc(i).t,npc(i).g1,npc(i).g2,i)
                    endif
                endif
            next i
            randomize timer()*_SEED  
 
            RollNPCMF()    
 
                `Enemy Firing
                for i = 1 to 5
                    if npc_health(i) > 0
                        sx# = object position x(npc(i).b)
                        sy# = object position y(npc(i).b)
                        sz# = object position z(npc(i).b)
                        move object npc(i).b,2000
                        nx# = object position x(npc(i).b)
                        ny# = object position y(npc(i).b)
                        nz# = object position z(npc(i).b) 
                        move object npc(i).b,-2000
 
                        `Enemy-to-Player
                        if intersect object(p.b,sx#,sy#,sz#,nx#,ny#,nz#) > 0 and p_health > 0
                            ai_turning = 0
                            show object npc_mf(i).a
                            show object npc_mf(i).b
                            dec p_health
 
                            if p_health < 1
                                `He just died
                                set text font "verdana"
                                set text size 40
 
                                phr = rnd(10)
                                ink 0,0
                                center text screen width()/2+2,screen height()/2+2,death_phrase(phr)
                                ink rgb(255, 128, 0),0
                                center text screen width()/2,screen height()/2,death_phrase(phr)
 
                                set text size 20
 
                                ink 0,0
                                center text screen width()/2+2,screen height()/2+52,"Press any key to try again."
                                ink rgb(255, 255, 255),0
                                center text screen width()/2,screen height()/2+50,"Press any key to try again."
                                sync
                                wait key
                                p_health = 100
                                play = 1
                            endif
                        endif
                        `Enemy-to-Enemy
                        for x = 1 to 5
                            if x <> i : `Don't hit oneself
                                ray = intersect object(npc(x).b,sx#,sy#,sz#,nx#,ny#,nz#)
                                if  ray > 0 and npc_health(x) > 0
                                    npc_health(x) = npc_health(x) - 1
                                    show object npc_mf(i).a
                                    show object npc_mf(i).b
                                    ai_turning = 0
 
                                    if npc_health(x) < 1
                                        npc_rt(x) = timer() + 10000
                                    endif
                                endif
                            endif
 
                            `MuzzleFlahses
                            if intersect object(npc(x).b,sx#,sy#,sz#,nx#,ny#,nz#) = 0 and intersect object(p.b,sx#,sy#,sz#,nx#,ny#,nz#) = 0
                                hide object npc_mf(i).a
                                hide object npc_mf(i).b
                            endif
                        next x
                    endif
                next i 
 
            `Health Bar (Player)
            ink rgb(255,0,0),0
            box 10,screen height()-30,110,screen height()-10
 
            ink rgb(0,255,0),0
            box 10,screen height()-30,p_health+10,screen height()-10
 
            `Health bars (bots)
            for i = 1 to 5
                bx = object screen x(npc(i).t)
                by = object screen y(npc(i).t)
 
                if npc_health(i) > 0
                    ink rgb(255,0,0),0
                    box bx,by,bx+50,by+5
 
                    ink rgb(0,255,0),0
                    box bx,by,bx+(npc_health(i)/2),by+5  
                else
                    ink 0,0
                    box bx,by,bx+50,by+5
 
                    ink rgb(255, 255, 0),0
                    center text bx+25,by,str$((npc_rt(i)-timer())/1000)
                endif
            next i
 
            `Dead bot
            for i = 1 to 5
                if npc_health(i) < 1
                    set alpha mapping on npc(i).b,20
                    set alpha mapping on npc(i).t,20
                    set alpha mapping on npc(i).g1,20
                    set alpha mapping on npc(i).g2,20
                    hide object npc_mf(i).a
                    hide object npc_mf(i).b
                    if npc_rt(i) < timer() and npc_rt(i) > -1
                        npc_rt(i) = -1
                        npc_health(i) = 100
                        position object npc(i).b,rnd(500)-250,6,rnd(500)-250
                        PositionObjectsAsNPC(npc(i).b,npc(i).t,npc(i).g1,npc(i).g2,i)
                    endif
                else
                    set alpha mapping on npc(i).b,100
                    set alpha mapping on npc(i).t,50
                    set alpha mapping on npc(i).g1,100
                    set alpha mapping on npc(i).g2,100
                    npc_rt(i) = -1
                endif
            next i
 
            `Info
            set cursor 0,0
            print p_velo#
 
            if escapekey() = 1 then end
        endif
    endif
 
    `Handle Flash Thingamajigger
    HandleFlash()
    if flash_stage = -1
        nextFlashTimer = timer() + rnd(9000)+1000
        flash_stage = 0
    endif
    if flash_stage = 0
        if nextFlashTimer < timer()
            InitFlash()
            nextFlashTimer = -1
        endif
    endif
 
    `Info
    set cursor 0,0
 
sync
loop
`*****************************
`END LOOP
`*****************************
 
function InitFlash()
    rotate object 3,rnd(360),rnd(360),rnd(360)
    flash_stage = 1
endfunction
 
function HandleFlash()
    if flash_stage = 1 : `Slow fade-in
        inc flash_fade,10
        fade object 3,flash_fade
        if flash_fade > 300
            flash_stage = 2
        endif
    endif
    if flash_stage = 2 : `Quick flash
        inc flash_fade,50
        fade object 3,flash_fade
        if flash_fade > 500
            flash_stage = 3
        endif
    endif
    if flash_stage = 3 : `Quick flash out
        dec flash_fade,50
        fade object 3,flash_fade
        if flash_fade < 301
            flash_stage = 4
        endif
    endif
    if flash_stage = 4
        dec flash_fade,10
        fade object 3,flash_fade
        if flash_fade < 1
            flash_stage = -1
        endif
    endif
endfunction
 
function freeObject()
    LOCAL f
    LOCAL i = 0
    do
        inc i
        if object exist(i) = 0
            f = i
            exit
        endif
    loop
endfunction f
 
function button(x,y,txt$)
    truex = x-(text width(txt$)+10)/2
 
    if mousex() > truex and mousex() < (truex+text width(txt$)+10) and mousey() > y and mousey() < (y+text height(txt$)+10)
        col1 = rgb(236, 0, 0)
        col2 = rgb(255, 128, 0)
        col3 = rgb(0,0,0)
        flag = 1
        if mouseclick() = 1
            col1 = rgb(0, 64, 128)
            col2 = rgb(0, 128, 255)
            col3 = rgb(255, 255, 255)
            flag = 2
        endif
    else
        col1 = rgb(225, 0, 0)
        col2 = rgb(73, 73, 73)
        col3 = rgb(255,255,255)
        flag = 0
    endif
    ink col1,0
    box truex,y,truex+text width(txt$)+10,y+text height(txt$)+10
    ink col2,0
    box truex+1,y+1,truex+text width(txt$)+9,y+text height(txt$)+9
    ink col3,0
    text truex+5,y+5,txt$
endfunction flag
 
function PositionObjectsAsPlayer(b,t,g1,g2)
 
    LOCAL bx#
        bx# = object position x(b)
    LOCAL by#
        by# = object position y(b)
    LOCAL bz#
        bz# = object position z(b)
    LOCAL bay#
        bay# = object angle y(b)
 
    rotate object t,0,bay#,0
    rotate object g1,0,bay#,0
    rotate object g2,0,bay#,0
 
    position object t,bx#,14.5,bz#
    position object g1,bx#,12.5,bz#
    move object left g1,6
    move object g1,3
    position object g2,bx#,12.5,bz#
    move object right g2,6
    move object g2,3
 
    `Muzzleflashes
    for x = 15 to 1 step -1
        position object mfo(x),object position x(g1),object position y(g1),object position z(g1)
        rotate object mfo(x),object angle x(g1),object angle y(g1),object angle z(g1)
        move object mfo(x),((15-x)*4)+17.5+rnd(5)
        point object mfo(x),camera position x(),camera position y(),camera position z() 
        roll object right mfo(x),x*90
    next x 
    for x = 30 to 16 step -1
        position object mfo(x),object position x(g2),object position y(g2),object position z(g2)
        rotate object mfo(x),object angle x(g2),object angle y(g2),object angle z(g2)
        move object mfo(x),((15-(x-15))*4)+17.5+rnd(5)
        point object mfo(x),camera position x(),camera position y(),camera position z()  
        roll object right mfo(x),(x-15)*90
    next x      
endfunction
 
function PositionObjectsAsNPC(b,t,g1,g2,i)
 
    LOCAL bx#
        bx# = object position x(b)
    LOCAL by#
        by# = object position y(b)
    LOCAL bz#
        bz# = object position z(b)
    LOCAL bay#
        bay# = object angle y(b)
 
    rotate object t,0,bay#,0
    rotate object g1,0,bay#,0
    rotate object g2,0,bay#,0
 
    position object t,bx#,14.5,bz#
    position object g1,bx#,12.5,bz#
    move object left g1,6
    move object g1,3
    position object g2,bx#,12.5,bz#
    move object right g2,6
    move object g2,3
 
    `Muzzleflashes  
     position object npc_mf(i).a,object position x(g1),object position y(g1),object position z(g1)
     rotate object npc_mf(i).a,object angle x(g1),object angle y(g1),object angle z(g1)
     move object npc_mf(i).a,17.5+rnd(5)
     point object npc_mf(i).a,camera position x(),camera position y(),camera position z()  
     roll object right npc_mf(i).a,rnd(90)
 
     position object npc_mf(i).b,object position x(g2),object position y(g2),object position z(g2)
     rotate object npc_mf(i).b,object angle x(g2),object angle y(g2),object angle z(g2)
     move object npc_mf(i).b,17.5+rnd(5)
     point object npc_mf(i).b,camera position x(),camera position y(),camera position z()  
     roll object right npc_mf(i).b,rnd(90)
 
     RollNPCMF()
endfunction
 
function RollMF()
    for i = 1 to 30
        roll object right mfo(i),rnd(90)
    next i
endfunction
 
function RollNPCMF()
    for i = 1 to 5
        roll object right npc_mf(i).a,rnd(90)
        roll object right npc_mf(i).b,rnd(90)
    next i
endfunction
 
`***********************************
`CHOOSE MODE CODE
`***********************************
_chooseMode:
    if mode = 0
        show mouse
        set cursor 0,0
        hide object 5
        position camera curvevalue(cam1.x,camera position x(),20),curvevalue(cam1.y,camera position y(),20),curvevalue(cam1.z,camera position z(),20)
        rotate camera curveangle(cam1.xa,camera angle x(),20),curveangle(cam1.ya,camera angle y(),20),0
 
        set text font "verdana"
        set text size 24
 
        if abs(camera position x() - cam1.x) < 5 and abs(camera position y() - cam1.y) < 5 and abs(camera position z() - cam1.z) < 5
            if button(screen width()/2,300,"Play the Game") = 2 then mode = 2
            if button(screen width()/2,340,"Map Editor") = 2 then mode = 1
            if escapekey() = 1 then end
        endif
 
    endif
return
 
`***********************************
`LEVEL EDITOR CODE
`***********************************
_levelEditor:
    if mode = 1
        `Escape
        if escapekey() = 1
            mode = 0
            for i = 1 to wall_count
                delete object walls(i)
            next i
            wall_count = 0
            goto _MainLoopStart
            FinalString$ = ""
            StaticString$ = ""
        endif
 
       `Crosshair
        sprite 1,screen width()/2 - 8, screen height()/2 - 8,3
 
        `Mouse
        if mouseLock = 0
            position mouse screen width()/2 + 8, screen height()/2 + 8
 
            `Mouselook
            cx# = wrapvalue(cx#+mousemovey())
            cy# = wrapvalue(cy#+mousemovex())
            rotate camera cx#,cy#,0
            position camera curvevalue(0,camera position x(),20),curvevalue(100,camera position y(),20),curvevalue(0,camera position z(),20)
            `if upkey() = 1 then move camera 5
            `if downkey() = 1 then move camera -5
            hide mouse
        else
            show mouse
            junk = mousemovex()
            junk = mousemovey()
        endif
 
            `Find distance to floor
            sx# = camera position x()
            sy# = camera position y()
            sz# = camera position z()
            move camera 2000
            nx# = camera position x()
            ny# = camera position y()
            nz# = camera position z()
            move camera -2000
            FloorDist = intersect object(4,sx#,sy#,sz#,nx#,ny#,nz#)
            move camera FloorDist
            fx# = camera position x()
            fy# = camera position y()
            fz# = camera position z()
            move camera FloorDist*-1
            position object 5,fx#,fy#+12.5,fz#
 
        `Find Distance to any existing wall
        if wall_count > 0
            for i = 1 to wall_count
                if object exist(i)
                    sx# = camera position x()
                    sy# = camera position y()
                    sz# = camera position z()
                    move camera 2000
                    nx# = camera position x()
                    ny# = camera position y()
                    nz# = camera position z()
                    move camera -2000
                    dist = intersect object(walls(i),sx#,sy#,sz#,nx#,ny#,nz#)
                    if dist > 0
                        hittingWall = walls(i)
                        color object walls(i),rgb(0, 100, 0)
                        exit
                    else
                        hittingWall = 0
                        color object walls(i),rgb(255, 255, 255)
                    endif
                endif
            next i
        endif
 
        `Make Sure the cursor isn't in contact with any walls
        if wall_count > 0
            for i = 1 to wall_count
                if object exist(i)
                    if object collision(5,walls(i)) = 1
                        wallOverlap = 1
                        hide object 5
                        exit
                    else
                        wallOverlap = 0
                        show object 5
                    endif
                endif
            next i
        endif
 
        `New Object
        if mouseclick() = 1 and wallOverlap = 0 and hittingWall = 0
            inc wall_count
            array insert at bottom walls(0)
            walls(wall_count) = freeObject()
            make object box walls(wall_count),50,25,50
            position object walls(wall_count),fx#,fy#+12.5,fz#
        endif
 
        `Stretch Object
        if mouseclick() = 1 and hittingWall > 0
            mouseLock = 1
            color object hittingWall,rgb(100,0,0)
            scale object hittingWall,100+(mousex()-(screen width()/2)),100,100+(mousey()-(screen height()/2))
        else
            mouseLock = 0
        endif
 
        `Move Object
        if mouseclick() = 2 and hittingWall > 0
            color object hittingWall,rgb(0,0,100)
            move camera FloorDist
            tx# = camera position x()
            tz# = camera position z()
            move camera FloorDist*-1
            position object hittingWall,tx#,12.5,tz#
        endif
 
        `Print Info
        set cursor 0,0
        ink rgb(255,255,255),0
        set text font "verdana"
        set text size 15
        if wall_count = 0
            center text screen width()/2,0,"Press <Space> Now to Load a Saved Map"
        else
            if inLSMenu = 0
                center text screen width()/2,0,"Press <Space> Now to Save This Map"
            endif
        endif
 
        `Load / Save
        if spacekey() = 1 and inLSMenu = 0
            FinalString$ = ""
            StaticString$ = ""
            saveFile$ = ""
            loadFile$ = ""
            inLSMenu = 1
            clear entry buffer
        endif
 
        `Menus
        if inLSMenu = 1
            hide sprite 1
        else
            show sprite 1
        endif
 
        if inLSMenu = 1 and wall_count > 0
            set cursor 0,0
            ink rgb(255,255,255),0
            print "What name would you like to save the file by?"
 
            if returnkey() = 1
                saveFile$ = FinalString$
                FinalString$ = ""
                StaticString$ = ""
                CharHit$ = ""
                inLSMenu = 0
            endif
 
            CharHit$ = inkey$()
            if CharHit$ = chr$(8)
                StaticString$ = StaticString$ + entry$()
                StaticString$ = left$(StaticString$,len(StatingString$)-1)
                clear entry buffer
            endif
            FinalString$ = StaticString$ + entry$()
            print FinalString$
        endif
 
        if inLSMenu = 1 and wall_count < 1
            set cursor 0,0
            ink rgb(255,255,255),0
            print "What file would you like to load?"
 
            if returnkey() = 1
                loadFile$ = FinalString$
                FinalString$ = ""
                inLSMenu = 0
            endif
 
            CharHit$ = inkey$()
            if CharHit$ = chr$(8)
                StaticString$ = StaticString$ + entry$()
                StaticString$ = left$(StaticString$,len(StatingString$)-1)
                clear entry buffer
            endif
            FinalString$ = StaticString$ + entry$()
            print FinalString$
        endif
 
        if saveFile$ <> "" and file exist(loadFile$) = 0
            open to write 1,saveFile$
            write string 1,str$(wall_count)
            for i = 1 to wall_count
                write string 1,str$(object position x(walls(i)))
                write string 1,str$(object position z(walls(i)))
                write string 1,str$(object size x(walls(i),1))
                write string 1,str$(object size z(walls(i),1))
            next i
            close file 1
            saveFile$ = ""
        endif
 
        if loadFile$ <> "" and file exist(loadFile$) = 1
            open to read 1,loadFile$
            read string 1,txt$
            NumBlocks = val(txt$)
            for i = 1 to NumBlocks
                read string 1,txt$
                xPos# = val(txt$)
                read string 1,txt$
                zPos# = val(txt$)
                read string 1,txt$
                xSize# = val(txt$)
                read string 1,txt$
                zSize# = val(txt$)
 
                inc wall_count
                array insert at bottom walls(0)
                walls(wall_count) = freeObject()
 
                make object box walls(wall_count),xSize#,25,zSize#
                position object walls(wall_count),xPos#,12.5,zPos#
            next i
            close file 1
            inLSMenu = 0
            loadFile$ = ""
        endif
    else
        if sprite exist(1) then delete sprite 1
    endif
return