global variabls are only in dbpro which i used to code it but the same effect can be used by using variable arrays, i think
set display mode 1024,768,32
rem make global variables for functions
dim ang#(1)
ang#(1)=1.0
dim height#(1)
height#(1)=100.0
dim camdist#(1)
camdist#(1)=100.0
dim health#(1)
health#(1)=1000.0
dim enemyhealth#(1)
enemyhealth#(1)=100.0
rem make player
player=1
make object box player,10,20,10
rem make enemy
enemy=2
make object box enemy,10,20,10
rem move enemy away from you
position object enemy,0,0,100
rem make camera
camera=1
make camera camera
set cursor 500,350
set text size 32
print "Press a key to start"
wait key
do
controlcam(player,camera)
shooting()
hit?()
health()
loop
function controlcam(obj,cam)
if upkey()=1 then move object obj,.1
if downkey()=1 then move object obj,-.1
if leftkey()=1 then yrotate object obj,wrapvalue(object angle y(obj)+.1)
if rightkey()=1 then yrotate object obj,wrapvalue(object angle y(obj)-.1)
if mousex()=>1000 then ang#=wrapvalue(ang#-.2)
if mousex()=<100 then ang#=wrapvalue(ang#+.2)
if height#(1) < 400
if mousey()=<100 then height#(1)=height#(1)+.1
endif
if height#(1)>50
if mousey()=>700 then height#(1)=height#(1)-.1
endif
set camera to follow cam,object position x(obj),0,object position z(obj),ang#,camdist#(1),height#(1),1,1
point camera cam,object position x(obj),0,object position z(obj)
endfunction
function shooting()
if keystate(57)=1
if object exist(100)=0
make object box 100,10,10,10
rem makes object at your position
position object 100,Object Position x(1),Object Position y(1),Object Position z(1)
rem fires bullet in the direction you are facing
rotate object 100,object angle x(1),object angle y(1),object angle z(1)
endif
endif
if object exist(100)=1
move object 100,1
rem distance formula
ox#=object position x(100)
oz#=object position z(100)
oy#=object position y(100)
dx#=object position x(1)-ox#
dz#=object position z(1)-oz#
dy#=object position y(1)-oy#
dist#=sqrt((dx#*dx#)+(dz#*dz#)+(dy#*dy#))
endif
rem deletes bullet if it goes too far
if dist#>100
delete object 100
endif
rem make the enemy shoot back
if object exist(101)=0
make object box 101,10,10,10
rem makes object at enemy position
position object 101,Object Position x(2),Object Position y(2),Object Position z(2)
rem fires bullet in the direction the enemy is facing
rotate object 101,object angle x(2),object angle y(2),object angle z(2)
endif
rem points the enemy at you
point object 2,Object Position x(1),Object Position y(1),Object Position z(1)
rem delete the bullet if it is to far from the enemy
if object exist(101)=1
move object 101,1
rem distance formula
ox#=object position x(101)
oz#=object position z(101)
oy#=object position y(101)
dx#=object position x(2)-ox#
dz#=object position z(2)-oz#
dy#=object position y(2)-oy#
dist#=sqrt((dx#*dx#)+(dz#*dz#)+(dy#*dy#))
endif
rem deletes bullet if it goes too far
if dist#>100
delete object 101
endif
endfunction
function hit?()
rem check to see if player is hit
rem checks to see if the bullets are close to you or enemy
rem checks to see if you have shot a bullet
if object exist(100)=1
ox#=object position x(100)
oz#=object position z(100)
oy#=object position y(100)
dx#=object position x(2)-ox#
dz#=object position z(2)-oz#
dy#=object position y(2)-oy#
dist#=sqrt((dx#*dx#)+(dz#*dz#)+(dy#*dy#))
if dist#<5
rem if the bullet is close to the enemy subtract 10 health from the enemy and remove the bullet
enemyhealth#(1)=enemyhealth#(1)-10
delete object 100
endif
endif
rem does the same above, but for you
if object exist(101)=1
ox#=object position x(101)
oz#=object position z(101)
oy#=object position y(101)
dx#=object position x(1)-ox#
dz#=object position z(1)-oz#
dy#=object position y(1)-oy#
dist#=sqrt((dx#*dx#)+(dz#*dz#)+(dy#*dy#))
if dist#<5
health#(1)=health#(1)-10
delete object 101
endif
endif
endfunction
function health()
rem your health
Ink RGB(255,255,255),0
box 10,700,100,720
Ink RGB(255,0,0),0
box 10,700,health#(1),720
rem enemy health
Ink RGB(255,255,255),0
box 900,10,1000,30
Ink RGB(255,0,0),0
box 900,10,enemyhealth#(1)+900,30
rem check to see if you or the enemy has 0 health
if health#(1)=<0
do
set text size 32
set cursor 500,350
print "you have lost"
loop
endif
if enemyhealth#(1)=<0
do
set cursor 500,350
set text size 32
print "you have won"
loop
endif
endfunction
I am unfimiliar with DBC but i heard that variable arrays work in place of global variables, it works in dbpro and they globals are variable arrays and will work in dbc. there might be other commands, just let me know and i will try to fix/change them