Quote: "Maybe adding a debug toggle button would improve your workflow - like pressing a key to enable or disable the debug text. I'd also disable parts of it and see if I can narrow down any part that is causing more slowdown than others. I don't think text can be the whole problem."
This is what I have ended up doing. I was thinking that text isn't the only problem, as for my original 2d project I had substantial 2D commands and text and it was fine. I think I am missing something between using 3d and text.
Also, heres my code, it's a bit messy at the moment as I haven't gone to this in a while.
Set Display Mode 1024,768,32
Sync on:`Let the program control the sync
Sync Rate 60:`Refresh at 60
cls:sync:`Get screen ready
Autocam Off:`Disable camera move on object creation
Draw To Front:`Draws all 2D sprites over 3D
Randomize Timer():`Randomize the clock
Hide Mouse:`Hide the mouse cursor
Flush Video Memory:`DB Problems...
`Initialize data and media ready for use
GoSub Variables
GoSub Arrays
GoSub LoadMedia
GoSub CreateMenu
daNumberYo = RND(5)
Select daNumberYo
Case 1
randomString$ = "3D Engine v0.3; Now with more Polygons!"
EndCase
Case 2
randomString$ = "3D Engine v0.3; collision pls"
EndCase
Case 3
randomString$ = "3D Engine v0.3; Much cube, much player, wow"
EndCase
Case 4
randomString$ = "3D Engine v0.3; Not GunSkill"
EndCase
Case 5
randomString$ = "3D Engine v0.3; 0% of the time it works all the time"
EndCase
EndSelect
`Game update loop
Do
If isInMenu = 1
GoSub Menu
EndIf
If isInGame = 1 AND isInMenu = 0
GoSub Game
GoSub Hud
GoSub SkySphere
EndIf
If developer = 1
GoSub Debug
EndIf
Sync
Loop
`Initialize all variables
Variables:
`Menu Object Constants
MMBG = 1
MMSMLOAD = 2
MMSMSELECTLEVEL = 3
MMCOOPLEVEL = 4
MMCOOPINVITE = 5
MMCOMPMAP = 6
MMCOMPMODE = 7
MMCOMPSETTINGS = 8
MMCOMPINVITE = 9
`Cursor object constant
CURSOR = 1
`Current selected menu option
selectedItem = 1
`Timers to stop key spam/key carry
cursorTimer = 0
selectTimer = 0
`Boolean control variables
isInMenu = 1
isInGame = 0
isInCoop = 0
isInComp = 0
`Menu flags
mainMenu = 1
storyMenu = 0
coopMenu = 0
competitiveMenu = 0
optionsMenu = 0
loadMenu = 0
selectLevelMenu = 0
coopLevelMenu = 0
coopInviteMenu = 0
compMapMenu = 0
compModeMenu = 0
compSettingsMenu = 0
compInviteMenu = 0
`Main Menu coordinates
mmbgx# = 0.0
mmbgy# = 0.0
mmbgz# = 10.0
`Camera
camx# = 0.0
camy# = 0.0
camz# = -2.0
camAngx# = 0.0
camAngy# = 0.0
sensitivity# = 0.2
debugCamera = 0
objAngle = 0
objDistance# = 2.5
`Transition handlers for sub menus
gotoMMBG = 0
gotoMMSMLOAD = 0
gotoMMSMSELECTLEVEL = 0
gotoMMCOOPLEVEL = 0
gotoMMCOOPINVITE = 0
gotoMMCOMPMAP = 0
gotoMMCOMPMODE = 0
gotoMMCOMPSETTINGS = 0
gotoMMCOMPINVITE = 0
menu$ = ""
`Clean assets ready for game
cleanMenu = 1
`Test Object
oldobjx# = 0.0
oldobjy# = 10.0
oldobjz# = 0.0
objx# = 0.0
objy# = 5.0
objz# = 15.0
direction$ = ""
speed# = 0.287
maxSpeed# = 0.587
acceleration# = 0.03
`jumping
jump = 0
jumpCooldown# = 0.0
jumpForce# = 0.0
jumpFactor# = 0.0
jumpFlag = 0
antiHold = 0
ground = 0
`Collision
colFlag = 0
`Print variables and the fact that DB doesnt like my computer...
developer = 1
randomString$ = ""
`Levels
currentLevel = 0
createSky = 1
Return
`Initialize all the arrays
Arrays:
Return
`Load all media like images, sprites, objects, sounds, animations
LoadMedia:
Load Image "Sprites\menuCursor.bmp",1
Return
`Create the main menu scene
CreateMenu:
Make Object Cube MMBG,10
Make Object Cube MMSMLOAD,10
Make Object Cube MMSMSELECTLEVEL,10
Make Object Cube MMCOOPLEVEL,10
Make Object Cube MMCOOPINVITE,10
Make Object Cube MMCOMPMAP,10
Make Object Cube MMCOMPMODE,10
Make Object Cube MMCOMPSETTINGS,10
Make Object Cube MMCOMPINVITE,10
Position Object MMBG,mmbgx#,mmbgy#,mmbgz#
Position Object MMSMLOAD,20.0,0.0,10.0
Position Object MMSMSELECTLEVEL,40.0,0.0,10.0
Position Object MMCOOPLEVEL,60.0,0.0,10.0
Position Object MMCOOPINVITE,80.0,0.0,10.0
Position Object MMCOMPMAP,100.0,0.0,10.0
Position Object MMCOMPMODE,120.0,0.0,10.0
Position Object MMCOMPSETTINGS,140.0,0.0,10.0
Position Object MMCOMPINVITE,160.0,0.0,10.0
Color Object MMSMLOAD,RGB(0,255,0)
Color Object MMSMSELECTLEVEL,RGB(0,0,255)
Color Object MMCOOPLEVEL,RGB(255,0,0)
Color Object MMCOOPINVITE,RGB(255,255,0)
Color Object MMCOMPMAP,RGB(0,255,255)
Color Object MMCOMPMODE,RGB(255,0,255)
Color Object MMCOMPSETTINGS,RGB(50,255,50)
Color Object MMCOMPINVITE,RGB(100,100,255)
Set Object Emissive MMBG,RGB(0,0,0)
Set Object Specular MMBG,RGB(7,7,155),200
Color Backdrop RGB(0,0,0)
Return
`Menu update procedure
Menu:
`Camera placement and pulse
Position Camera camx#,camy#,camz#
camz# = camz# - increment#
If camz# < -3.0
reverseFlag = 1
EndIf
If camz# > -2.0
reverseFlag = 0
EndIf
If reverseFlag = 1
increment# = -0.02
EndIf
If reverseFlag = 0
increment# = 0.02
EndIf
`Main menu code
If mainMenu = 1
Center Text 512,184,"MAIN MENU"
Center Text 512,284,"STORY"
Center Text 512,344,"CO-OP"
Center Text 512,404,"COMPETITIVE"
Center Text 512,464,"OPTIONS"
Center Text 512,524,"EXIT"
menu$ = "Main"
Color Object MMBG,RGB(139,7,7)
DEC cursorTimer
DEC selectTimer
If cursorTimer < 0
cursorTimer = 0
EndIf
If selectTimer < 0
selectTimer = 0
EndIf
If upkey() = 1 and cursorTimer = 0
DEC selectedItem
cursorTimer = 30
EndIf
If downkey() = 1 and cursorTimer = 0
INC selectedItem
cursorTimer = 30
EndIf
If selectedItem > 5
selectedItem = 1
EndIf
If selectedItem < 1
selectedItem = 5
EndIf
If selectedItem = 1
Sprite 1,572,278,CURSOR
EndIf
If selectedItem = 2
Sprite 1,572,338,CURSOR
EndIf
If selectedItem = 3
Sprite 1,572,398,CURSOR
EndIf
If selectedItem = 4
Sprite 1,572,458,CURSOR
EndIf
If selectedItem = 5
Sprite 1,572,518,CURSOR
EndIf
If selectedItem = 1 AND ReturnKey() = 1 AND selectTimer = 0
storyMenu = 1
mainMenu = 0
selectTimer = 30
EndIf
If selectedItem = 2 AND ReturnKey() = 1 AND selectTimer = 0
coopMenu = 1
mainMenu = 0
selectTimer = 30
EndIf
If selectedItem = 3 AND ReturnKey() = 1 AND selectTimer = 0
competitiveMenu = 1
mainMenu = 0
selectTimer = 30
EndIf
If selectedItem = 4 AND ReturnKey() = 1 AND selectTimer = 0
optionsMenu = 1
mainMenu = 0
selectTimer = 30
EndIf
If selectedItem = 5 AND ReturnKey() = 1 AND selectTimer = 0
End
EndIf
EndIf
`Story menu code
If storyMenu = 1
Center Text 512,184,"STORY"
Center Text 512,284,"NEW"
Center Text 512,344,"LOAD"
Center Text 512,404,"SELECT LEVEL"
Center Text 512,464,"RETURN"
menu$ = "Story"
Color Object MMBG,RGB(7,139,7)
DEC selectTimer
DEC cursorTimer
If selectTimer < 0
selectTimer = 0
EndIf
If cursorTimer < 0
cursorTimer = 0
EndIf
If upkey() = 1 and cursorTimer = 0
DEC selectedItem
cursorTimer = 30
EndIf
If downkey() = 1 and cursorTimer = 0
INC selectedItem
cursorTimer = 30
EndIf
If selectedItem > 4
selectedItem = 1
EndIf
If selectedItem < 1
selectedItem = 4
EndIf
If selectedItem = 1
Sprite 1,572,278,CURSOR
EndIf
If selectedItem = 2
Sprite 1,572,338,CURSOR
EndIf
If selectedItem = 3
Sprite 1,572,398,CURSOR
EndIf
If selectedItem = 4
Sprite 1,572,458,CURSOR
EndIf
If selectedItem = 1 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
mainMenu = 0
storyMenu = 0
isInMenu = 0
isInGame = 1
currentLevel = 1
EndIf
If selectedItem = 2 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
gotoMMSMLOAD = 1
EndIf
If selectedItem = 3 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
gotoMMSMSELECTLEVEL = 1
EndIf
If selectedItem = 4 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
mainMenu = 1
storyMenu = 0
selectedItem = 1
EndIf
If gotoMMSMLOAD = 1
camx# = camx# + 0.1
EndIf
If camx# >= Object Position X(MMSMLOAD)
gotoMMSMLOAD = 0
loadMenu = 1
EndIf
If gotoMMSMSELECTLEVEL = 1
camx# = camx# + 0.2
EndIf
If camx# >= Object Position X(MMSMSELECTLEVEL)
gotoMMSMSELECTLEVEL = 0
selectLevelMenu = 1
EndIf
EndIf
`Coop menu code
If coopMenu = 1
Center Text 512,184,"CO-OPERATIVE"
Center Text 512,284,"START"
Center Text 512,344,"LEVEL"
Center Text 512,404,"DIFFICULTY"
Center Text 512,464,"INVITE"
Center Text 512,524,"RETURN"
menu$ = "Co-Operative"
Color Object MMBG,RGB(7,7,139)
DEC selectTimer
DEC cursorTimer
If selectTimer < 0
selectTimer = 0
EndIf
If cursorTimer < 0
cursorTimer = 0
EndIf
If upkey() = 1 and cursorTimer = 0
DEC selectedItem
cursorTimer = 30
EndIf
If downkey() = 1 and cursorTimer = 0
INC selectedItem
cursorTimer = 30
EndIf
If selectedItem > 5
selectedItem = 1
EndIf
If selectedItem < 1
selectedItem = 5
EndIf
If selectedItem = 1
Sprite 1,572,278,CURSOR
EndIf
If selectedItem = 2
Sprite 1,572,338,CURSOR
EndIf
If selectedItem = 3
Sprite 1,572,398,CURSOR
EndIf
If selectedItem = 4
Sprite 1,572,458,CURSOR
EndIf
If selectedItem = 5
Sprite 1,572,518,CURSOR
EndIf
If selectedItem = 1 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
EndIf
If selectedItem = 2 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
gotoMMCOOPLEVEL = 1
EndIf
If selectedItem = 3 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
EndIf
If selectedItem = 4 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
gotoMMCOOPINVITE = 1
EndIf
If selectedItem = 5 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
mainMenu = 1
coopMenu = 0
selectedItem = 1
EndIf
If gotoMMCOOPLEVEL = 1
camx# = camx# + 0.3
EndIf
If camx# >= Object Position X(MMCOOPLEVEL)
gotoMMCOOPLEVEL = 0
coopLevelMenu = 1
EndIf
If gotoMMCOOPINVITE = 1
camx# = camx# + 0.4
EndIf
If camx# >= Object Position X(MMCOOPINVITE)
gotoMMCOOPINVITE = 0
coopInviteMenu = 1
EndIf
EndIf
`Competitive menu code
If competitiveMenu = 1
Center Text 512,184,"COMPETITIVE"
Center Text 512,284,"MAP"
Center Text 512,344,"MODE"
Center Text 512,404,"GAME SETTINGS"
Center Text 512,464,"INVITE"
Center Text 512,524,"RETURN"
menu$ = "Competitive"
Color Object MMBG,RGB(139,7,139)
DEC selectTimer
DEC cursorTimer
If selectTimer < 0
selectTimer = 0
EndIf
If cursorTimer < 0
cursorTimer = 0
EndIf
If upkey() = 1 and cursorTimer = 0
DEC selectedItem
cursorTimer = 30
EndIf
If downkey() = 1 and cursorTimer = 0
INC selectedItem
cursorTimer = 30
EndIf
If selectedItem > 5
selectedItem = 1
EndIf
If selectedItem < 1
selectedItem = 5
EndIf
If selectedItem = 1
Sprite 1,572,278,CURSOR
EndIf
If selectedItem = 2
Sprite 1,572,338,CURSOR
EndIf
If selectedItem = 3
Sprite 1,572,398,CURSOR
EndIf
If selectedItem = 4
Sprite 1,572,458,CURSOR
EndIf
If selectedItem = 5
Sprite 1,572,518,CURSOR
EndIf
If selectedItem = 1 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
gotoMMCOMPMAP = 1
EndIf
If selectedItem = 2 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
gotoMMCOMPMODE = 1
EndIf
If selectedItem = 3 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
gotoMMCOMPSETTINGS = 1
EndIf
If selectedItem = 4 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
gotoMMCOMPINVITE = 1
EndIf
If selectedItem = 5 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
mainMenu = 1
competitiveMenu = 0
selectedItem = 1
EndIf
If gotoMMCOMPMAP = 1
camx# = camx# + 0.5
EndIf
If camx# >= Object Position X(MMCOMPMAP)
gotoMMCOMPMAP = 0
compMapMenu = 1
EndIf
If gotoMMCOMPMODE = 1
camx# = camx# + 0.6
EndIf
If camx# >= Object Position X(MMCOMPMODE)
gotoMMCOMPMODE = 0
compModeMenu = 1
EndIf
If gotoMMCOMPSETTINGS = 1
camx# = camx# + 0.7
EndIf
If camx# >= Object Position X(MMCOMPSETTINGS)
gotoMMCOMPSETTINGS = 0
compSettingsMenu = 1
EndIf
If gotoMMCOMPINVITE = 1
camx# = camx# + 0.8
EndIf
If camx# >= Object Position X(MMCOMPINVITE)
gotoMMCOMPINVITE = 0
compInviteMenu = 1
EndIf
EndIf
`Options menu code
If optionsMenu = 1
Center Text 512,184,"OPTIONS"
Center Text 512,284,"AUDIO"
Center Text 512,344,"VISUAL"
Center Text 512,404,"CONTROLS"
Center Text 512,464,"DATA"
Center Text 512,524,"RETURN"
menu$ = "Options"
Color Object MMBG,RGB(7,139,139)
DEC selectTimer
DEC cursorTimer
If selectTimer < 0
selectTimer = 0
EndIf
If cursorTimer < 0
cursorTimer = 0
EndIf
If upkey() = 1 and cursorTimer = 0
DEC selectedItem
cursorTimer = 30
EndIf
If downkey() = 1 and cursorTimer = 0
INC selectedItem
cursorTimer = 30
EndIf
If selectedItem > 5
selectedItem = 1
EndIf
If selectedItem < 1
selectedItem = 5
EndIf
If selectedItem = 1
Sprite 1,572,278,CURSOR
EndIf
If selectedItem = 2
Sprite 1,572,338,CURSOR
EndIf
If selectedItem = 3
Sprite 1,572,398,CURSOR
EndIf
If selectedItem = 4
Sprite 1,572,458,CURSOR
EndIf
If selectedItem = 5
Sprite 1,572,518,CURSOR
EndIf
If selectedItem = 1 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
EndIf
If selectedItem = 2 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
EndIf
If selectedItem = 3 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
EndIf
If selectedItem = 4 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
EndIf
If selectedItem = 5 AND ReturnKey() = 1 AND selectTimer = 0
selectTimer = 30
mainMenu = 1
optionsMenu = 0
selectedItem = 1
EndIf
EndIf
Return
Game:
`Remove menu objects and create next level, objects are created in level order.
If cleanMenu = 1 AND currentLevel = 1
For i = 1 To 9
Delete Object i
Next i
Flush Video Memory:`DB Problems...
Delete Sprite CURSOR
Make Object Cube 999,3:`Player
Color Object 999,RGB(117,107,207)
Set Object Emissive 999,RGB(0,255,0)
Set Object Specular 999,RGB(0,255,0),10
Make Object Box 123,100,1,100:`Floor
For j = 124 To 126
Make Object Cube j,5:`Block 1
Next j
Make Object Cube 127,2:`Switch 1 (Blue)
For k = 128 To 133
Make Object Cube k,5
Next k
Make Object Cube 134,2:`Switch 2 (Red)
Make Object Cube 135,2:`Block 1d
Make Object Cube 136,3:`Block 2d
Make Object Cube 137,4:`Block 3d
Position Object 124,30.0,2.0,10.0
Position Object 125,35.0,7.0,10.0
Position Object 126,35.0,12.0,15.0
Position Object 127,35.0,15.0,15.0
Position Object 128,15.0,12.0,15.0
Position Object 129,15.0,12.0,40.0
Position Object 130,0.0,12.0,40.0
Position Object 131,-10.0,20.0,40.0
Position Object 132,-10.0,20.0,20.0
Position Object 133,-10.0,20.0,0.0
Position Object 134,-10.0,25.0,0.0
Position Object 135,-20.0,25.0,0.0
Position Object 136,-20.0,25.0,10.0
Position Object 137,-10.0,30.0,15.0
Color Object 123,RGB(127,247,187)
For l = 124 To 126
Color Object l,RGB(0,255,0)
Next l
For m = 127 To 131
Color Object m,RGB(0,0,255)
Next m
Color Object 132,RGB(255,140,0)
Color Object 133,RGB(0,0,255)
For n = 134 To 137
Color Object n,RGB(255,0,0)
Next n
For n = 128 To 137
Hide Object n
Next n
ground = 0
cleanMenu = 0
EndIf
`Level 2
If cleanMenu = 1 AND currentLevel = 2
For del = 124 To 137
Delete Object del
Next del
Flush Video Memory
Color Object 123,RGB(27,87,247)
If Object Exist(124) = 0 then Make Object Cube 124,5
Color Object 124,RGB(127,0,0)
Position Object 124,0.0,0.0,5.0
If Object Exist(125) = 0 then Make Object Cube 125,5
Color Object 125,RGB(127,0,0)
Position Object 125,0.0,2.5,10.0
If Object Exist(126) = 0 then Make Object Cube 126,5
Color Object 126,RGB(127,0,0)
Position Object 126,0.0,8.0,18.0
If Object Exist(127) = 0 then Make Object Cube 127,5
Color Object 127,RGB(127,0,0)
Position Object 127,5.0,8.0,18.0
If Object Exist(128) = 0 then Make Object Cube 128,5
Color Object 128,RGB(128,0,0)
Position Object 128,5.0,8.0,10.0
objx# = 0.0
objy# = 10.0
objz# = 0.0
cleanMenu = 0
EndIf
`Movement
Position Object 999,objx#,objy#,objz#
Select objAngle
Case 0
If KeyState(32) <> 0
INC speed#,0.005
objx# = objx# + speed#
EndIf
If KeyState(30) <> 0
INC speed#,0.005
objx# = objx# - speed#
EndIf
If KeyState(17) <> 0
INC speed#,0.005
objz# = objz# + speed#
EndIf
If KeyState(31) <> 0
INC speed#,0.005
objz# = objz# - speed#
EndIf
EndCase
Case 90
If KeyState(32) <> 0
INC speed#,0.005
objz# = objz# - speed#
EndIf
If KeyState(30) <> 0
INC speed#,0.005
objz# = objz# + speed#
EndIf
If KeyState(17) <> 0
INC speed#,0.005
objx# = objx# + speed#
EndIf
If KeyState(31) <> 0
INC speed#,0.005
objx# = objx# - speed#
EndIf
EndCase
Case 180
If KeyState(32) <> 0
INC speed#,0.005
objx# = objx# - speed#
EndIf
If KeyState(30) <> 0
INC speed#,0.005
objx# = objx# + speed#
EndIf
If KeyState(17) <> 0
INC speed#,0.005
objz# = objz# - speed#
EndIf
If KeyState(31) <> 0
INC speed#,0.005
objz# = objz# + speed#
EndIf
EndCase
Case 270
If KeyState(32) <> 0
INC speed#,0.005
objz# = objz# + speed#
EndIf
If KeyState(30) <> 0
INC speed#,0.005
objz# = objz# - speed#
EndIf
If KeyState(17) <> 0
INC speed#,0.005
objx# = objx# - speed#
EndIf
If KeyState(31) <> 0
INC speed#,0.005
objx# = objx# + speed#
EndIf
EndCase
EndSelect
If speed# > maxSpeed# then speed# = maxSpeed#
DEC speed#,0.003
If speed# < 0.287 then speed# = 0.287
`Jumping
If SpaceKey() = 1 AND jumpCooldown# = 0 AND antiHold = 0 AND ground = 1
jump = 1
jumpCooldown# = 65
antiHold = 1
ground = 0
EndIf
If jump = 1
objy# = objy# - jumpForce#
DEC jumpCooldown#
If jumpCooldown# < 10.0
jumpFlag = 1
EndIf
If jumpCooldown# > 0.0
jumpFlag = 0
EndIf
If jumpFlag = 1
jumpForce# = 0.457 + jumpFactor#
EndIf
If jumpFlag = 0
jumpForce# = -0.457 + jumpFactor#
EndIf
INC jumpFactor#,0.01
Else
jumpForce# = 0.0
EndIf
If ground = 1
jumpCooldown# = 0
jump = 0
antiHold = 0
jumpFactor# = 0.0
EndIf
ground = 0
If currentLevel = 1
`Object collisions
For x = 123 To 126
If Object Collision(999,x) = 1
Repeat
Position Object 999, oldobjx#, oldobjy#, oldobjz#
oldobjy# = oldobjy# + 0.1
ground = 1
objAngle = 0
Until Object Collision(999,x) = 0
EndIf
Next x
If Object Collision(999,127) = 1
Show Object 128
Show Object 129
Show Object 130
Show Object 131
Show Object 133
Show Object 134
Hide Object 127
EndIf
If Object Collision(999,128) = 1
Repeat
Position Object 999, oldobjx#, oldobjy#, oldobjz#
oldobjy# = oldobjy# + 0.1
ground = 1
objAngle = 0
Until Object Collision(999,128) = 0
EndIf
If Object Collision(999,129) = 1
Repeat
Position Object 999, oldobjx#, oldobjy#, oldobjz#
oldobjy# = oldobjy# + 0.1
ground = 1
objAngle = 270
objDistance# = 3.5
Until Object Collision(999,129) = 0
EndIf
For y = 130 To 133
If Object Collision(999,y) = 1 AND Object Visible(y) = 1
Repeat
Position Object 999, oldobjx#, oldobjy#, oldobjz#
oldobjy# = oldobjy# + 0.1
ground = 1
Until Object Collision(999,y) = 0
EndIf
Next y
If Object Collision(999,134) = 1
Show Object 135
Hide Object 134
Show Object 136
Show Object 137
EndIf
For z = 135 To 136
If Object Collision(999,z) = 1 AND Object Visible(z) = 1
Repeat
Position Object 999, oldobjx#, oldobjy#, oldobjz#
oldobjy# = oldobjy# + 0.1
ground = 1
Until Object Collision(999,z) = 0
EndIf
Next z
`End Level
If Object Collision(999,137) = 1 AND Object Visible(137) = 1
currentLevel = 2
createSky = 1
cleanMenu = 1
EndIf
`Hide and show objects code (Orange objects)
DEC showObjTimer
If showObjTimer < 0 then showObjTimer = 120
If showObjTimer > 0 AND showObjTimer < 60
Show Object 132
EndIf
If showObjTimer > 60 AND showObjTimer < 120
Hide Object 132
EndIf
EndIf
If currentLevel = 2
For a1 = 123 To 126
If Object Collision(999,a1) = 1
Repeat
Position Object 999, oldobjx#, oldobjy#, oldobjz#
oldobjy# = oldobjy# + 0.1
ground = 1
objAngle = 0
Until Object Collision(999,a1) = 0
EndIf
Next a1
For a2 = 127 To 128
If Object Collision(999,a2) = 1
Repeat
Position Object 999, oldobjx#, oldobjy#, oldobjz#
oldobjy# = oldobjy# + 0.1
ground = 1
objAngle = 90
Until Object Collision(999,a2) = 0
EndIf
Next a2
EndIf
oldobjx# = objx#
oldobjy# = objy#
oldobjz# = objz#
If ground = 0 then objy# = objy# - 0.2
obja = 999
objb = 123
distancePlayGround$ = str$(objectDistance(obja,objb))
If objectDistance(obja,objb) > 5000 then objy# = 2.0
Set Camera To Follow objx#, objy#, objz#, objAngle, 20, objy# + objDistance#, 30, 1
Return
Hud:
Center Text 784,100,randomString$
Center Text 784,120,"Level:"
Center Text 804,120,str$(currentLevel)
If currentLevel = 1
Center Text 884,120,"First!"
EndIf
If currentLevel = 2
Center Text 884,120,"It wasn't dark..."
EndIf
Center Text 784,160,str$(Screen FPS())
Return
`Prints variables to watch to the screen
Debug:
If isInMenu = 1
Text 50,100,"Cursor:"
Text 120,100,str$(cursorTimer)
Text 50,120,"Select:"
Text 120,120,str$(selectTimer)
Text 50,140,"Item:"
Text 120,140,str$(selectedItem)
Text 50,200,"Pulse/Camera:"
Text 50,220,"Increment:"
Text 120,220,str$(increment#)
Text 50,240,"camz:"
Text 120,240,str$(camz#)
Text 50,260,"Reverse:"
Text 120,260,str$(reverseFlag)
EndIf
If isInGame = 1
Text 50,120,"Performance:"
Text 50,140,"FPS:"
Text 120,140,str$(Screen FPS())
Text 50,160,"Clock:"
Text 150,160,str$(timer())
Text 50,180,"Polygon Count:"
Text 150,180,str$(statistic(1))
Text 200,180,polygonStatus$
Text 50,200,"Memory Counts"
Text 50,220,"Video (Bytes):"
Text 200,220,str$(System DMEM Available())
Text 50,240,"System (Bytes):"
Text 200,240,str$(System SMEM Available())
Text 50,260,"Overall (Bytes):"
Text 200,260,str$(System TMEM Available())
EndIf
If debugCamera = 1
`First person camera movement
camAngy# = WrapValue(camAngy# + MouseMoveX() * sensitivity#)
camAngx# = WrapValue(camAngx# + MouseMoveY() * sensitivity#)
Yrotate Camera camAngy#
Xrotate Camera camAngx#
If ShiftKey() = 1:`W
Move Camera 0.5
EndIf
If KeyState(45) <> 0
DEC sensitivity#,0.1
EndIf
If KeyState(44) <> 0
INC sensitivity#,0.1
EndIf
If sensitivity# < 0.1 then sensitivity# = 0.1
If sensitivity# > 1.0 then sensitivity# = 1.0
EndIf
If statistic(1) > 10000
polygonStatus$ = "Too High"
Else
polygonStatus$ = "Good"
EndIf
Return
SkySphere:
If createSky = 1 AND currentLevel = 1
Make Object Sphere 987,-5000
Color Object 987,RGB(165,165,255)
Set Object Emissive 987,200:`Illuminate (Light Emission) object (SkySphere)
Set Object Specular 987,RGB(0,129,255),10:`Specular light (SkySphere)
createSky = 0
EndIf
If createSky = 1 AND currentLevel = 2
Delete Object 987
Make Object Sphere 988,-5000
Color Object 988,RGB(25,25,55)
Set Object Emissive 988,200:`Illuminate (Light Emission) object (SkySphere)
Set Object Specular 988,RGB(0,129,255),10:`Specular light (SkySphere)
createSky = 0
EndIf
If currentLevel = 1 AND Object Exist(987) = 1
Position Object 987, objx#, objy#, objz#
EndIf
If currentLevel = 2 AND Object Exist(988) = 1
Position Object 988, objx#, objy#, objz#
EndIf
Return
`Distance from origin
Function objectDistance(obja,objb)
hd#=sqrt((Object Position X(obja) - Object Position X(objb))^2+(Object Position Z(obja) - Object Position Z(objb))^2)
vd#=(Object Position Y(obja) - Object Position X(objb))^2
d#=sqrt(hd#^2+vd#^2)
endfunction d#
`Calculate the face of a block the player is going to hit to stop teleporting. The collision is decided on what
`Value approach provides.
Function CollisionExtension(objx#,objy#,objz#,obj1,obj2)
If objx# < Object Position X(obj2)
`Approaching from the left face
approach = 1
EndIf
If objx# > Object Position X(obj2)
`Approaching from the right face
approach = 2
EndIf
If objz# < Object Position Z(obj2)
`Approaching from the front face
approach = 3
EndIf
If objz# > Object Position Z(obj2)
`Approaching from the back face
approach = 4
EndIf
If objy# < Object Position Y(obj2)
`Approaching from the bottom face
approach = 5
EndIf
If objy# > Object Position Y(obj2)
`Approaching from the top face
approach = 6
EndIf
EndFunction approach