I have just spent quite a while trying to get some 2d "popup" menus to work the way i want them to in a 3d environment... ok it took me hours... but i look at the code and think it could probably be neater, i know it's a pretty lame question, but i'm always after ways of making my coding take less space and look neater and considering what it is i'm trying to do being a very small part of the program... i kinda figure it should be alot smaller than it is.
Set Display mode 1280,1024,32
hide mouse
Sync on
Make matrix 1,500,500,25,25
x#=330
y#=50
z#=120
RX#=595
RY#=495
position camera x#,y#,z#
`Camera setup and Positioning
make object sphere 200,3
Position camera x#,y#,z#
position object 200,x#+10,80,z#+10
point camera 500,0,500
color object 200,0
hide object 200
`set object collision to polygons 1
make object plane 22,64,76.5
lock object on 22
position object 22,0,0,200
set object transparency 22,1
make object plane 23,64,76.5
lock object on 23
position object 23,0,0,200
set object transparency 23,1
set image colorkey 255,0,255
load bitmap "F:\Game Creation\Dark Basic Pro\ObjectMenu.bmp",100
get image 100,0,0,128,153
delete bitmap 100
load bitmap "F:\Game Creation\Dark Basic Pro\SpellMenu.bmp",101
get image 101,0,0,128,153
delete bitmap 101
load image "F:\Game Creation\Dark Basic Pro\Protection.bmp",301
sprite 2,595,405,301
hide sprite 2
load image "F:\Game Creation\Dark Basic Pro\HealthPack.bmp",302
sprite 3,595,405,302
hide sprite 3
load image "F:\Game Creation\Dark Basic Pro\SelectCursor.bmp",200
sprite 1,640,512,200
set sprite priority 1,2
do
oldx# = x#
oldz# = z#
`Fix Mouse Position
position mouse 640,512
sprite 1,RX#,RY#,200
`reset cursor to middle of menu cross
if sprite visible(1)=0
RX#=595
RY#=495
endif
`Hide all sprites except 20, we wanna see that one
hide all sprites
if sprite exist(20) then show sprite 20
`Player controls
`Mouse "Look" Routine
cx#=wrapvalue(cx#+mousemovey())
cy#=wrapvalue(cy#+mousemovex())
cz#=wrapvalue(cz#+mousemovez())
rotate camera cx#,cy#,cz#
`Move Camera
if keystate(17)=1 then x#=newxvalue(x#,cy#,1) : z#=newzvalue(z#,cy#,1)
if keystate(31)=1 then x#=newxvalue(x#,cy#,-1) : z#=newzvalue(z#,cy#,-1)
if keystate(30)=1 then z#=newzvalue(z#,cy#-90,1) : x#=newxvalue(x#,cy#-90,1)
if keystate(32)=1 then z#=newzvalue(z#,cy#-90,-1) : x#=newxvalue(x#,cy#-90,-1)
`crouch routine
IF keystate(46)=1
if flag = 0
ButtonOn = 1 - ButtonOn
flag = 1
gy#=30
endif
else
flag = 0
gy#=100
ENDIF
`slightly crappy spell and object menus
if keystate(16)=1 then texture object 22,100 : show object 22 : ItemSprites() : else hide object 22 `Q object menu
if keystate(18)=1 then texture object 23,101 : show object 23 : SpellSprites() : else hide object 23 `E spell Menu
`move menu cursor
if upkey()=1 and sprite visible(1)=1 then RY#=RY#-90 : if RY#=<405 then RY#=405
if downkey()=1 and sprite visible(1)=1 then RY#=RY#+90 : if RY#=>585 then RY#=585
if leftkey()=1 and sprite visible(1)=1 then RX#=RX#-90 : if RX#=<505 then RX#=505
if rightkey()=1 and sprite visible(1)=1 then RX#=RX#+90 : if RX#=>685 then RX#=685
`prevent cursor going outside of menu bounds by moving it to closest apropriate space
if (RY#=405 OR RY#= 585) and leftkey()=1 then RY#=495
if (RY#=405 OR RY#= 585) and rightkey()=1 then RY#=495
if (RX#=505 OR RX#= 685) and upkey()=1 then RX#=595
if (RX#=505 or RX#= 685) and downkey()=1 then RX#=595
for spl = 2 to 3
if sprite collision (1,spl) and sprite visible(spl) and returnkey()=1
if sprite exist(20) then delete sprite 20
clone sprite spl,20
sprite 20,1180,10,spl+299
`*****this bit is just debug gumph*****
if spl=2 then SPL$="Protection"
if spl=3 then SPL$="HealthPack"
`**************************************
endif
next spl
`Update Camera Position
y#=get ground height(1,x#,z#)+gy#
position camera x#,y#,z#
position object 200,x#,40,z#
`Debug info
set cursor 0,0
print "cy#=";cy#
print "cx#=";cx#
print "cz#=";cz#
print "Xpos";x#
print "Zpos";z#
print "CursorY# ";RY#
print "CursorX# ";RX#
print "Spell ";SPL$
sync
loop
function ItemSprites()
show sprite 1
Show sprite 3 `HealthPack
endfunction
function SpellSPrites()
show sprite 1
show sprite 2 `Protection
endfunction
the matrix and stuff is just there to provide a basic 3d world so i could test if it would function during movement and such. Oh yeah and it's using the keystates from a UK qwerty keyboard.