Well, it was late last night, so I didn't get the chance then, but here it is now:
`3rd Person
`Author : Jesse Farr, modified by IanM :p
`setup game - sync as fast as we can
sync on : sync rate 0
`make game data
gosub _make_players_make_bullets_ect
gosub _create_cameras
`Initialise the timer that will be used for skipping frames
SkipTimer=timer()+10
MovesTaken=0
`begin main loop
do
`control game elements
gosub _control_players
gosub _control_bullets
gosub _control_collisions
inc MovesTaken
` Do camera and rendering things here
if timer() < SkipTimer
gosub _control_camera_camera_views
gosub _display_update_rates
sync
endif
inc SkipTimer, 10
loop
_display_update_rates:
set cursor 0, 0
print "FPS : "; screen fps()
print "Moves : "; MovesTaken
MovesTaken=0
return
_control_players:
`Controls For Player 1
if upkey()=1 then move object 1,3
if downkey()=1 then move object 1,-3
if rightkey()=1 then yrotate object 1,(object angle y(1)+2)
if leftkey()=1 then yrotate object 1,(object angle y(1)-2)
`controls for player 2
if keystate(17) then move object 2,3
if keystate(31) then move object 2,-3
if keystate(32) then yrotate object 2,(object angle y(2)+2)
if keystate(30) then yrotate object 2,(object angle y(2)-2)
return
_control_bullets:
`Control Bullets player1 (NOT FULLY SURE NOW THIS WORKS)
if CONTROLKEY()=1 and bullet=-80
bullet=100
position object BulletP1,object position x(1),object position y(1),object position z(1)
rotate object BulletP1,object angle x(1),object angle y(1),object angle z(1)
endif
move object BulletP1,10
if bullet>0
if bullet=1
bullet=0
else
rem Move bullet
DEC bullet
endif
else
if bullet>-80 then dec bullet
endif
`Control Bullets player2 (NOT FULLY SURE NOW THIS WORKS)
if keystate(20) and bullet1=-80
bullet1=100
position object BulletP2,object position x(2),object position y(2),object position z(2)
rotate object BulletP2,object angle x(2),object angle y(2),object angle z(2)
endif
move object BulletP2,10
if bullet1>0
if bullet1=1
bullet1=0
else
dec bullet1
endif
if bullet1=0
endif
else
if bullet1>-80 then dec bullet1
endif
return
_control_collisions:
if object collision (BulletP2,1) = 1 then position object 1,0,10,0
if object collision (BulletP1,2) = 1 then position object 2,1000,10,1000
return
_control_camera_camera_views:
`set camera to follow player 1 and Player 2
set camera to follow 0,object position x(1),object position y(1),object position z(1),object angle y(1),dist#,height#,Smooth#,0
set camera to follow 1,object position x(2),object position y(2),object position z(2),object angle y(2),dist2#,height2#,Smooth2#,0
return
_make_players_make_bullets_ect:
`load media
`make Player 1
make object cube 1,20
position object 1,0,10,0
texture object 1,1
`make bullet P1
BulletP1=3 : make object SPHERE BulletP1,20
`make Player 2
make object cube 2,20
position object 2,1000,10,1000
texture object 2,1
`make bullet P2
BulletP2=4 : make object SPHERE BulletP2,20
`make matrix
make matrix 2,5000,5000,50,50
`variables Player 1,2
dist#=100
height#=40
smooth#=10
`2
dist2#=100
height2#=40
smooth2#=10
return
_create_cameras:
` Make another camera for player 2
make camera 1
` Arrange the cameras on the display
set camera view 0,0,0,screen width(),screen height()/2
set camera view 1,0,screen height()/2,screen width(),screen height()
` Setup FOV and aspect ratio, so that a cube will look like a cube
for cam=0 to 1
set camera fov cam, 62
set camera aspect cam, 2.25
next cam
return
I've tried to avoid making too many changes to the code
- Separated out the camera creation and setup code
- Added a simple timer check to the main loop to avoid moving the camera or syncing if the game loop is too far behind
- Added simple stats to the display that shows the render rate, and the number of movement steps that were taken by each render. Averaging each of these numbers and multiplying them together should come to approx 100, which was your original frame target frame rate
- Indentation!
I took the route of skipping rendering frames rather than adjusting movement and rotation rates to match because it was the easier route with your code.
Enjoy!
*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++
http://www.matrix1.demon.co.uk