try this, it also moves the player and objects per second, not per frame, so it works at any frame rate. Also I like to keep everything at one scale, so I like to have 1 unit= 1 meter, so a100x100 matrix is 100 meters x 100 meters.
Rem Project: FPS Test
Rem Created: 8/14/2004 7:16:13 PM
Rem ***** Main Source File *****
set display mode 800,600,32
Sync On
Sync Rate 0
Hide mouse
autocam off
Rem make matrix
Make matrix 1,100,100,20,20
randomize matrix 1,5
update matrix 1
rem Handling the setting***********************************************************************
type bullet_type
object as dword
start as dword
endtype
dim bullet(100) as bullet_type
global bulletspeed as float
global bulletlife as word
bulletlife = 1000
`the bullet stay alive for 1 second (1000 miliseconds)
bulletspeed = 100
`bullets travel at 10 meters per second
walk_speed#=10.0
jump_speed#=0.0
`player walks at 3 meters per second
for n=1 to 100
bullet(n).object=n +100
next n
rem Variables**********************************************************************
Rem Set Camera Pos
position camera 50,2,50
Rem Main loop
last_timer=timer()
global time#
rem time# is 1 / frame rate, or seconds per frame, so if fps=50, time#=0.02
Do
time#=(timer()-last_timer)/1000.0
last_timer=timer()
gosub update_player
gosub display
rem update_bullet() is a function call
update_bullets()
Sync
Loop
display:
set cursor 0,0
print "Frame Rate: ",screen fps()
`cross hair
radius#=30*screen height()/600.0
line screen width()/2-radius#,screen height()/2,screen width()/2+radius#,screen height()/2
line screen width()/2,screen height()/2-radius#,screen width()/2,screen height()/2+radius#
return
update_player:
Rem Mouse Look
rotate camera wrapvalue(Camera angle x()+mousemovey()*0.2),wrapvalue(Camera angle y()+mousemovex()*0.2),0
Rem USER CONTROLS**************************************************************************************
Rem Keyboard Controls
walk#=(upkey()-downkey())*walk_speed#*time#
`if upkey=1, then walk = 1
`if downkey=1, then walk = -1
CY#=get ground height(1,camera position x(),camera position z())+2
move camera walk#
strafe#=(rightkey()-leftkey())*walk_speed#*time#
`if rightkety=1, then strafe = 1
`if leftkey=1, then strafe = -1
CXA#=camera angle x()
rotate camera 0,camera angle y()+90,0
move camera strafe#
`turn the camera to the right
rotate camera CXA#,camera angle y()+270,0
`update camera with the speed
position camera camera position x(),camera position y()+jump_speed#*time#,camera position z()
`Gravity is -9.8 per second, thus -9.8*time#
jump_speed#=jump_speed#-9.8*time#
if camera position y()<CY#
`if the camera is on the ground
position camera camera position x(),CY#,camera position z()
`get jump input
if spacekey()=1 then jump_speed#=6
endif
Rem ...On MouseclickEvent
If Mouseclick()=1 and timer()>lastshot+100
lastshot= timer()
shoot_bullet()
endif
return
function shoot_bullet()
n=0
repeat
inc n
obj=bullet(n).object
until object exist(obj)=0
`n is bullet ARRAY NUMBER (1-100)
`obj is bullet OBJECT NUMBER (101-200)
make object sphere obj,0.1
Position object obj, camera position x(),camera position y(),camera position Z()
rotate object obj,camera angle x(),camera angle y(),0
move object obj,0.1
bullet(n).start=timer()
endfunction
function update_bullets()
for n=1 to 100
obj=bullet(n).object
if object exist(obj)=1
move object obj, bulletspeed*time#
g#=get ground height(1,object position x(obj),object position z(obj))
if timer()>bullet(n).start+bulletlife OR object position y(obj)<g#
delete object obj
endif
endif
next n
endfunction
-----------------------------------
To delete the bug, delete the code.
Specs: Sony VAIO Laptop, Windows XP, P4 2.8Ghz, 512MB RAM, ATI Radeon 64MB video memory, DBP Upgrade 5.3.