Ahhh... This is very frustrating. Here's my whole program:
rem Use desktop resolution, vsync on
sync on : sync rate 0
desktopwidth=900
desktopheight=650
set display mode desktopwidth,desktopheight,32,1
rem Initialise application and hide mouse pointer
autocam off : hide mouse : disable escapekey
set global collision on
rem Set font
set text font "Ariel"
ink rgb(255,255,200),0
set text size 20
rem Load level (load static objects read a DBO and DBU file pair)
gdividetexturesize=0 : universefile$="levelbank\testlevel\universe.dbo"
set dir "S:\VGD_2015\Gravity\Files" : load static objects universefile$, gdividetexturesize
Rem set camera parameters
position camera 768,570,-547
point camera 1000,555,-2050
set ambient light 10
yrotate camera 90
T=Timer() : time = 0
A$ = ""
B$ = ""
C$ = ""
D$ = ""
answer$ = ""
noAnswer=0
Question$=""
wrongAnswers=0
`******** rem End intro section **********
`************* rem Main loop *************
while escapekey()=0
`
rem Control camera
BACKDROP ON
COLOR BACKDROP rgb(0,255,0)
Question$ = ""
REM check item collsiions
gosub _itemcollisions
REM camera controls
gosub _camera
rem Keep light with camera
set point light 0,camera position x(),camera position y()+50,camera position z()
`
REM timer
Elapsed=(Timer()-T)/1000
If Elapsed=60
Inc MinutesPassed:
Elapsed=0
T=Timer()
Endif
`
REM reset stuff
A$ = ""
B$ = ""
C$ = ""
D$ = ""
answer$ = ""
noAnswer=0
rem Update
sync
`
endwhile
rem Delete level
delete static objects
rem End program
end
_camera:
rem Read W,A,S,D keys for movement
tkeystate17=keystate(17)
tkeystate31=keystate(31)
tkeystate30=keystate(30)
tkeystate32=keystate(32)
rem Store CURRENT camera position
cox#=camera position x()
coy#=camera position y()
coz#=camera position z()
rem Determine camera direction
movement=0
if tkeystate17=1
if tkeystate30=1
y#=315 : movement=1
else
if tkeystate32=1
y#=45 : movement=1
else
y#=0 : movement=1
endif
endif
else
if tkeystate31=1
if tkeystate30=1
y#=225 : movement=1
else
if tkeystate32=1
y#=135 : movement=1
else
y#=180 : movement=1
endif
endif
else
if tkeystate30=1
y#=270 : movement=1
else
if tkeystate32=1
y#=90 : movement=1
endif
endif
endif
endif
rem Store camera angles
sx#=camera angle x()
sy#=camera angle y()
sz#=camera angle z()
REM Hud
set cursor 20, 25 : print "Camera height:"; str$(CAMERA POSITION Y())
set cursor 20, 45 : print "Camera Pos. X:"; str$(CAMERA POSITION X())
set cursor 20, 65 : print "Camera Pos. Z:"; str$(CAMERA Position Z())
set cursor 20, 85 : print "Camera angle (degrees):"; str$(CAMERA ANGLE Y())
set cursor 20, 125 : print "Close to item: "; closeToItem
set cursor 20, 105 : print "Screen FPS: "; STR$(screen fps())
set cursor 20, 145 : print "Your Time: "; MinutesPassed; ":"; Elapsed
set cursor 20, 165 : print "Wrong answers: "; wrongAnswers
rem Move camera in direction and restore camera angles
rotate camera 0, camera angle y()+y#,0
if movement=1 then move camera 3.0
if (shiftkey()=1 and movement = 1) then MOVE CAMERA 4.0
rotate camera sx#,sy#,sz#
rem Store NEW camera position (and apply gravity). Press SPACEBAR to walk through walls
rem To remove WTW function, remove entire 'if' except for one that calculates gravity.
cmx#=camera position x()
if (spacekey() = 0)
cmy#=camera position y()-gravity#
else
cmy#=camera position y()
endif
cmz#=camera position z()
rem Check volume collision between CURRENT and NEW camera positions
if static volume(cox#,coy#-25,coz#,cmx#,cmy#-25,cmz#,1.0)=1
`
rem If collision detected, determine material touching
materialtype=get static collision value()
`
rem If collision, calculate new ADJUSTED NEW camera position to avoid this collision
rem To remove WTW function, put static collisions outside the 'if' and remove the 'if'
if (spacekey() = 0)
cmx#=cox#+get static collision x()
cmz#=coz#+get static collision z()
cmy#=coy#+get static collision y()
else
cmy# = 560
endif
`
rem Reset gravity
gravity#=0.5
`
else
`
rem If no collision, must be in freefall so increase gravity
inc gravity#,0.2
`
endif
rem Update camera with ADJUSTED NEW position
position camera cmx#,cmy#,cmz#
rem Mouselook control
position mouse 400,300
cammovex#=mousemovex()*2
cammovey#=mousemovey()*2
camangx#=camera angle x()+cammovey#
camangy#=camera angle y()+cammovex#
if wrapvalue(camangx#)>85 and wrapvalue(camangx#)<180 then camangx#=85.0
if wrapvalue(camangx#)>180 and wrapvalue(camangx#)<275 then camangx#=275.0
rotate camera curveangle(camangx#,camera angle x(),15.0),curveangle(camangy#,camera angle y(),15.0),camera angle z()
rem If camera falls off map, reset it
if (cmy# <= -200) then position camera 768,570,-547
Rem No Code beyond this point!
return
REM ******************************
REM END CAMERA CONTROL FUNCTION
REM CHECK ITEM/QUESTION COLLISIONS
REM *****************************
_itemcollisions:
switch = 0
`item \/ Xval \/ Yval \/ Rad \/
`item1#=(sqrt((cmx#-xxx)^2+(cmz#+yyy)^2))-zz
REM QUESTIONS
REM Calc distance to item 1
item1#=(sqrt((cmx#-830)^2+(cmz#+445)^2))-45
if (item1# <= 0)
closeToItem = 1
gosub _item1
else
REM Calc distance to item 2
item2#=(sqrt((cmx#-447)^2+(cmz#+651)^2))-45
if (item2# <= 0)
closeToItem = 2
gosub _item2
else
REM Calc distance to item 3
item3#=(sqrt((cmx#-947)^2+(cmz#+1047)^2))-45
if (item3# <= 0)
closeToItem = 3
else
REM Calc distance to item 4
item4#=(sqrt((cmx#-1347)^2+(cmz#+1045)^2))-45
if (item4# <= 0)
closeToItem = 4
else
REM Calc distance to item 5
item5#=(sqrt((cmx#-1642)^2+(cmz#+149)^2))-45
if (item5# <= 0)
closeToItem = 5
else
REM Calc distance to endzone
item5#=(sqrt((cmx#-1642)^2+(cmz#+149)^2))-45
if (item5# <= 0)
closeToItem = 100
else
closeToItem = 0
endif
endif
endif
endif
endif
endif
REM Calc distance to item 6
if (closeToItem = 0)
item6#=(sqrt((cmx#-957)^2+(cmz#+1246)^2))-45
if (item6# <= 0)
closeToItem = 6
else
REM Calc distance to item 7
item7#=(sqrt((cmx#-648)^2+(cmz#+1651)^2))-45
if (item7# <= 0)
closeToItem = 7
else
REM Calc distance to item 8
item8#=(sqrt((cmx#-1948)^2+(cmz#+962)^2))-45
if (item8# <= 0)
closeToItem = 8
else
REM Calc distance to item 9
item9#=(sqrt((cmx#-3452)^2+(cmz#+248)^2))-45
if (item9# <= 0)
closeToItem = 9
else
REM Calc distance to item 10
item10#=(sqrt((cmx#-2452)^2+(cmz#+654)^2))-45
if (item10# <= 0)
closeToItem = 10
else
REM Calc distance to item 11
item11#=(sqrt((cmx#-3346)^2+(cmz#+756)^2))-45
if (item11# <= 0)
closeToItem = 11
else
closeToItem = 0
endif
endif
endif
endif
endif
endif
endif
switch = 1
if (closeToItem > 0) then center text 450, 600, "Press spacebar to read paper"
REM Detect spacebar being pressed, display question
if (closeToItem > 0 and (spacekey()>0) and closeToItem <> 100)
do
text 50, 300, Question$
text 50, 325, A$
text 50, 350, B$
text 50, 375, C$
text 50, 400, D$
if (noAnswer = 0)
set cursor 50, 425 : input "Your answer: ", guess$
if (upper$(guess$) = answer$)
exit
else
wrongAnswers = wrongAnswers + 1
endif
else
wait key
exit
endif
loop
endif
if (closeToItem = 100)
endif
return
REM *****************************
REM END CHECK ITEM COLLSISIONS
REM *****************************
REM **** QUESTION FUNCTIONS ****
_item1:
if (switch = 0)
Question$ = "You must find and answer the questions correctly, they will help you escape..."
noAnswer = 1
endif
return
_item2:
if (switch = 0)
Question$ = "What is the tallest mountain on Earth above sea-level?"
A$="A. Mt. McKinley"
B$="B. Mt. Kilimanjaro"
C$="C. Mt. Everest"
D$="D. MT. Makalu"
answer$="C"
else
endif
return