urr, yeah, i wrote this after a while, so enjoy!
creds to mm0zct - fps controls
and outland - heightmap
(used a wingman force 3d (really old))
`look up/down
if joystick y() <-500 then pitch#=pitch#+.25
if joystick y() <-700 then pitch#=pitch#+.25
if joystick y() <-900 then pitch#=pitch#+.25
if joystick y() <-1000 then pitch#=pitch#+.25
if joystick y() >500 then pitch#=pitch#+-.25
if joystick y() >700 then pitch#=pitch#+-.25
if joystick y() >900 then pitch#=pitch#+-.25
if joystick y() >1000 then pitch#=pitch#+-.25
if pitch#>70 then pitch#=69
if pitch#<-70 then pitch#=-69
xrotate camera pitch#
`Strafe Left
if JOYSTICK x() <-999 then left#=left#+1
if JOYSTICK x() <-666 then left#=left#+1
if JOYSTICK x() <-333 then left#=left#+1
strafe_camera_left(left#)
left#=0
`Strafe Right
if JOYSTICK x() >999 then right#=right#+1
if JOYSTICK x() >666 then right#=right#+1
if JOYSTICK x() >333 then right#=right#+1
strafe_camera_right(right#)
right#=0
`Turn left/right
if JOYSTICK TWIST Z() <20000 then turn#=turn#+-.1
if JOYSTICK TWIST Z() <15000 then turn#=turn#+-.1
if JOYSTICK TWIST Z() <10000 then turn#=turn#+-.1
if JOYSTICK TWIST Z() <5000 then turn#=turn#+-.1
if JOYSTICK TWIST Z() <2000 then turn#=turn#+-.1
if JOYSTICK TWIST Z() <900 then turn#=turn#+-.1
if JOYSTICK TWIST Z() >40000 then turn#=turn#+.1
if JOYSTICK TWIST Z() >45000 then turn#=turn#+.1
if JOYSTICK TWIST Z() >50000 then turn#=turn#+.1
if JOYSTICK TWIST Z() >55000 then turn#=turn#+.1
if JOYSTICK TWIST Z() >52000 then turn#=turn#+.1
if JOYSTICK TWIST Z() >53100 then turn#=turn#+.1
yrotate camera turn#
`Forward/backward
if joystick slider a() >60000 then forward#=forward#-(RunSpeed/2)
if joystick slider a() >40000 then forward#=forward#-(RunSpeed/2)
if joystick slider a() <20000 then forward#=forward#+(RunSpeed/2)
if joystick slider a() <1000 then forward#=forward#+(RunSpeed/2)
move_camera_forwards(forward#)
forward#=0
`functions:
function move_camera_forwards(move_speed#)
xcam#=camera angle x()
xrotate camera (185)
move camera 0, -(move_speed#)
xrotate camera 0,xcam#
endfunction
function move_camera_backwards(move_speed#)
xcam#=camera angle x()
xrotate camera (175)
move camera 0,move_speed#
xrotate camera xcam#
endfunction
function strafe_camera_left(strafeleftspeed#)
yrotate camera (camera angle y()+90)
xcam#=camera angle x()
xrotate camera (185)
move camera strafeleftspeed#
xrotate camera xcam#
yrotate camera (camera angle y(0)-90)
endfunction
function strafe_camera_right(straferightspeed#)
yrotate camera (camera angle y(0)-90)
xcam#=camera angle x(0)
xrotate camera (185)
move camera straferightspeed#
xrotate camera xcam#
yrotate camera (camera angle y(0)+90)
endfunction
usage: (needs media)(grass texture, and a 70x70 greyscale heightmap)
`========================================== SETUP =================================================================================
`==================================================================================================================================
RunSpeed= 8
MatrixSize= 5000
ink rgb(255,0,0),rgb(0,0,0)
set display mode 1440,900,32
sync on
sync rate 0
backdrop on
color backdrop rgb(0,0,0)
getheightbmp("hmap.bmp")
`=========================================== MATRIX STUFF =========================================================================
`==================================================================================================================================
make matrix 1,MatrixSize,MatrixSize,70,70
for x=1 to 70
for z=1 to 70
set matrix height 1,x,z,hmap(x,z)*4
next z
next x
load image "grass.bmp",1
prepare matrix texture 1,1,100,100
update matrix 1
hide mouse
position camera rnd(4980)+10,1000,rnd(4980)+10
do
position mouse screen width()/2,screen height()/2
pitch#=pitch#+mousemovey()
if joystick y() <-500 then pitch#=pitch#+.25
if joystick y() <-700 then pitch#=pitch#+.25
if joystick y() <-900 then pitch#=pitch#+.25
if joystick y() <-1000 then pitch#=pitch#+.25
if joystick y() >500 then pitch#=pitch#+-.25
if joystick y() >700 then pitch#=pitch#+-.25
if joystick y() >900 then pitch#=pitch#+-.25
if joystick y() >1000 then pitch#=pitch#+-.25
if pitch#>70 then pitch#=69
if pitch#<-70 then pitch#=-69
xrotate camera pitch#
rem in loop
if upkey()=1 then move_camera_forwards(RunSpeed)
if downkey()=1 then move_camera_backwards(RunSpeed)
if leftkey()=1 then strafe_camera_left(RunSpeed)
if rightkey()=1 then strafe_camera_right(RunSpeed)
if JOYSTICK x() <-999 then left#=left#+1
if JOYSTICK x() <-666 then left#=left#+1
if JOYSTICK x() <-333 then left#=left#+1
strafe_camera_left(left#)
left#=0
if JOYSTICK x() >999 then right#=right#+1
if JOYSTICK x() >666 then right#=right#+1
if JOYSTICK x() >333 then right#=right#+1
strafe_camera_right(right#)
right#=0
turn#=turn#+mousemovex()
if JOYSTICK TWIST Z() <20000 then turn#=turn#+-.1
if JOYSTICK TWIST Z() <15000 then turn#=turn#+-.1
if JOYSTICK TWIST Z() <10000 then turn#=turn#+-.1
if JOYSTICK TWIST Z() <5000 then turn#=turn#+-.1
if JOYSTICK TWIST Z() <2000 then turn#=turn#+-.1
if JOYSTICK TWIST Z() <900 then turn#=turn#+-.1
if JOYSTICK TWIST Z() >40000 then turn#=turn#+.1
if JOYSTICK TWIST Z() >45000 then turn#=turn#+.1
if JOYSTICK TWIST Z() >50000 then turn#=turn#+.1
if JOYSTICK TWIST Z() >55000 then turn#=turn#+.1
if JOYSTICK TWIST Z() >52000 then turn#=turn#+.1
if JOYSTICK TWIST Z() >53100 then turn#=turn#+.1
yrotate camera turn#
if joystick slider a() >60000 then forward#=forward#-(RunSpeed/2)
if joystick slider a() >40000 then forward#=forward#-(RunSpeed/2)
if joystick slider a() <20000 then forward#=forward#+(RunSpeed/2)
if joystick slider a() <1000 then forward#=forward#+(RunSpeed/2)
move_camera_forwards(forward#)
forward#=0
`Displays Framerate
Set Cursor 0,0
print "Framerate: ";Screen FPS()
print "JOY_X: ";joystick x()
print "JOY_Y: ";joystick y()
print "JOY_Z: ";Joystick Twist z()
print "JOY_Slider: ";joystick slider a()
print "buttons: ";
if joystick fire a()=1 then print "A,";
if joystick fire b()=1 then print "B,";
if joystick fire c()=1 then print "C,";
if joystick fire D()=1 then print "D,"
`Fog/Backdrop - I WANT A BLOODY SKYBAWX!!
fog on:fog color rgb(0,0,0)
COLOR BACKDROP rgb(0,0,0)
`less lag (because thiers less IF's)
if camera position x() > MatrixSize-80 then position camera camera position x()-RunSpeed,camera position y(),camera position z()
if camera position x() < 140 then position camera camera position x()+RunSpeed,camera position y(),camera position z()
if camera position z() > MatrixSize-80 then position camera camera position x(),camera position y(),camera position z()-RunSpeed
if camera position z() < 140 then position camera camera position x(),camera position y(),camera position z()+RunSpeed
`Puts Camera on the ground
position camera camera position x(), Get Ground Height (1,camera position x(),camera position z())+200, camera position z()
rem this must go at end of loop as so:
` gravity()
rem if you want it elsewhere in your loop or are using collision
rem other than bsp then run collision here
`if get ground height(1,camera position x(),camera position z()) < 0 then hitground=1
`if get ground height(1,camera position x(),camera position z()) > 0 then hitground=0
`sync's screen and loops to do
circle screen width()/2,screen height()/2,3
sync:loop
`=========================================== FUNCTIONS ============================================================================
`==================================================================================================================================
function getheightbmp(file$)
`this function only gets information from a 24-bit bitmap
`so make sure you save it as one
open to read 1,file$
`--------------------
`decode the header
`The info contained here is not usefull.
read byte 1,notusefull
read byte 1,notusefull
read long 1,notusefull
read long 1,notusefull
read long 1,notusefull
read long 1,notusefull
`--------------------
`Get Bitmap Width
read long 1,BmpWidth
`Get Bitmap Height
read long 1,BmpHeight
`--------------------
read word 1,notusefull
`--------------------
`Get BitDepth
read word 1,BitDepth
`--------------------
`The info contained here is not usefull.
read long 1,notusefull
read long 1,notusefull
read long 1,notusefull
read long 1,notusefull
read long 1,notusefull
read long 1,notusefull
`--------------------
`error check only if bitdepth=24
if BitDepth=24
ypos=BmpHeight
` Calculate If bmp required Padding
bmpwidth#=bmpwidth
evenwidth1#=(BmpWidth#*3)/4
evenwidth2=(BmpWidth*3)/4
padlen=0
if evenwidth1#<>evenwidth2
evenwidth1#=evenwidth1#-evenwidth2
padlen=4-(evenwidth1#*4)
endif
`-------------------------------------------
`create the hmap array
dim hmap(bmpwidth,bmpheight)
`-------------------------------------------
`Get color info
For Ylp=1 to BmpHeight
for Xlp=1 to Bmpwidth
`Read color values
read byte 1,blue
read byte 1,Green
read byte 1,red
`enter color info into height array
hmap(xlp,ypos)=(blue+green+red)/3
next Xlp
dec Ypos
`Padding
if padlen<>0
for padlp=1 to padlen
read byte 1,padbyte
next padlp
endif
next Ylp
endif
close file 1
endfunction
rem after loop
function move_camera_forwards(move_speed#)
xcam#=camera angle x()
xrotate camera (185)
move camera 0, -(move_speed#)
xrotate camera 0,xcam#
endfunction
function move_camera_backwards(move_speed#)
xcam#=camera angle x()
xrotate camera (175)
move camera 0,move_speed#
xrotate camera xcam#
endfunction
function strafe_camera_left(strafeleftspeed#)
yrotate camera (camera angle y()+90)
xcam#=camera angle x()
xrotate camera (185)
move camera strafeleftspeed#
xrotate camera xcam#
yrotate camera (camera angle y(0)-90)
endfunction
function strafe_camera_right(straferightspeed#)
yrotate camera (camera angle y(0)-90)
xcam#=camera angle x(0)
xrotate camera (185)
move camera straferightspeed#
xrotate camera xcam#
yrotate camera (camera angle y(0)+90)
endfunction
function gravity()
if hitground=0 then accel#=accel#+4
if hitground=1 then accel#=0
position camera camera position x(), camera position y()-(0.03+accel#), camera position z()
endfunction