darn you board
`---------------------------
`UFG
`---------------------------
`http://UFG.LurkerLordX.com
`Codded by Nikolai Crumb with help for the DB
`Comunity for debugging
`---------------------------
rem --------
rem INCLUDES
rem --------
rem include the MatEdit LoadMatrix files
#include "LoadMatrix.dba"
rem ------
rem ARRAYS
rem ------
rem declare the MatEdit variables
Dim BigMatrix(600,600,1)
Dim StartLoc_X(1): Dim StartLoc_Z(1):Dim Info(2)
Dim TArrayX(1): Dim TArrayZ(1): Dim FKey(10,1)
Dim ColData(100): Dim ZoneData(100): Dim Tiles(500,500)
Dim OverTexture$(100): Dim OverName$(20): Dim ReplaceTex(100)
Dim MOffsetX(25): Dim MOffsetY(25)
Dim MWire(20): Dim MGhost(20): Dim Lock(20)
Dim MatX#(20): Dim MatY#(20): Dim MatZ#(20)
Dim MatWidth#(20): Dim MatHeight#(20)
Dim TilesX(20): Dim TilesZ(20)
Dim MatHi#(20): Dim MatLo#(20)
rem player array
dim xSpeed#(4)
dim ySpeed#(4)
dim zSpeed#(4)
dim friction#(4)
dim moveDist#(4)
rem set fog
FOG ON
FOG DISTANCE 0
FOG COLOR RGB(0,133,255)
rem set up the program
sync on
sync rate 60
hide mouse
autocam off
rem load the matrix
LoadMatrix("BASIC1",1)
rem temp turbuckles
make object cube 101, 2100
position object 101, 50000, 6300, 53000
`set light properties
set ambient light 50
color ambient light RGB(255,255,255)
rem set cameral draw range
set camera range 1,30000
`gravity
dim gravity#(0) : gravity#(0)=1.43
`--------------
`player loading
`--------------
`make a temporary player object
make object cube 1,500
position object 1, 31000, 5006, 35000
friction#(1)=0.97
moveDist#(1)=6.065
xSpeed#(1)=0
zSpeed#(1)=0
`temp player, the ship
load object "spaceship.x", 11
scale object 11,30,30,30
glue object to limb 11,1,0
position object 11,0,370,0
hide limb 1,0
dim xPos#(1) :xPos#=object position x(1)
dim yPos#(1) :yPos#=object position y(1)
dim zPos#(1) :zPos#=object position z(1)
currentHotspot=0
`---------
`MAIN LOOP
`---------
main:
do
`get keyboard input for movement
if upkey()=1 then forward=1 else forward=0
if downkey()=1 then backward=1 else backward=0
if leftkey()=1 then left=1 else left=0
if rightkey()=1 then right=1 else right=0
`update the player
move_player(1,forward,backward,left,right)
`update the camera
chase_cam(1)
`call trap check
trapcheck(1,xPos#,yPos#,zPos#)
text 10,10, "Welcome to the 3d walk around for UFG."
text 10,24, "FPS: " + str$(screen fps())
text 10,38, "Fog Available (1=Yes): " + str$(name=fog available())
text 10,52, "X Cordinate (Cube Base): " + str$(object position x(1))
text 10,66, "Y Cordinate (Cube Base): " + str$(object position y(1))
text 10,80, "Z Cordinate (Cube Base): " + str$(object position z(1))
text 10,94, "Ghost Available (1=Yes): " + str$(name= alphablending available())
text 10,108, "Texture Smoothing Available (1=Yes): " + str$(name= filtering available())
text 10,122, "Fast 2D w/3D Available (1=Yes): " + str$(name= 3dblit available())
text 10,136, "3D Card: " + current graphics card$()
text 10,150, "Total Vid Memory: " + str$(name=system dmem available())
text 10,164, "Total Sys Memory: " + str$(name=system smem available())
text 10,178, "Total Memory: " + str$(name=system tmem available())
text 10,192, "Softwhere Emulation Mode (1=Yes): " + str$(name=emulation mode())
text 10,206, "Transformation and Lighting Supported (1=Yes): " + str$(name=tnl available())
text 10,220, "In Triger Zone (1=Yes): " + str$(currentHotspot)
`update the screen
sync
loop
`---------
`hotzone/trap zone
`---------
function trapcheck(id,xPos#,yPos#,zPos#)
`find current hotspot
if xPos#>=30000.0 and xPos#<=70000.0 and yPos#>=5000.0 and yPos#<=52000.0 and zPos#>=30000.0 and zPos#<=70000.0
currentHotspot=1
endif
currentHotspot=0
endfunction trapcheck
`---------
`chase cam
`---------
function chase_cam(id)
`work out the angle of the object being chased
yAng#=wrapvalue(object angle y(id)+180)
`grab the objects current position
xPos#=object position x(id)
yPos#=object position y(id)
zPos#=object position z(id)
`other variables
camDist=1500
camHeight=300
`work out new position
xCamPos#=newxvalue(xPos#,yAng#,camDist)
zCamPos#=newzvalue(zPos#,yAng#,camDist)
`camera collision
if xCamPos#>99999 then xCamPos#=99998
if zCamPos#>99999 then zCamPos#=99998
if xCamPos#<1 then XCamPos#=2
if zCamPos#<1 then zCamPos#=2
`work out camera height
yCamPos#=get ground height(1,xCamPos#,zCamPos#)+camHeight
if yCamPos#<yPos#+camHeight then yCamPos#=yPos#+camHeight
`organic camera
xCamPos#=curvevalue(xCamPos#,camera position x(),4)
yCamPos#=curvevalue(yCamPos#,camera position y(),4)
zCamPos#=curvevalue(zCamPos#,camera position z(),4)
`update camera position
position camera xCamPos#,yCamPos#,zCamPos#
point camera xPos#,yPos#+camHeight,zPos#
endfunction
`-------------------------
`move the specified player
`-------------------------
function move_player(id,forward, backward, left, right)
`----------------------------------
`get the required object properties
`----------------------------------
xPos#=object position x(id)
yPos#=object position y(id)
zPos#=object position z(id)
yAng#=object angle y(id)
`-----------------------
`sort out basic movement
`-----------------------
`apply forward movement
if forward=1
xSpeed#(id)=xSpeed#(id)+newxvalue(0,yAng#,moveDist#(id)*1)
zSpeed#(id)=zSpeed#(id)+newzvalue(0,yAng#,moveDist#(id)*1)
endif
`apply backward movement
if backward=1
xSpeed#(id)=xSpeed#(id)+newxvalue(0,yAng#,moveDist#(id)*-1)
zSpeed#(id)=zSpeed#(id)+newzvalue(0,yAng#,moveDist#(id)*-1)
endif
`apply left rotation
if left=1
yrotate object id,wrapvalue(yAng#-4)
endif
`apply right rotation
if right=1
yrotate object id,wrapvalue(yAng#+4)
endif
`--------------------------------------------------
`sort out friction and other physics related things
`--------------------------------------------------
`work out value with friction
xSpeed#(id)=xSpeed#(id)*friction#(id)
zSpeed#(id)=zSpeed#(id)*friction#(id)
`add gravity value
ySpeed#(id)=ySpeed#(id)+gravity#(0)
`work out the new position
xPos#=xPos#+xSpeed#(id)
zPos#=zPos#+zSpeed#(id)
yPos#=yPos#-ySpeed#(id)
`collision
if xPos#>99995 then xPos#=99995
if zPos#>99995 then zPos#=99995
if xPos#<5 then XPos#=5
if zPos#<5 then zPos#=5
`work out the height of the character
if yPos#<get ground height(1,xPos#,zPos#)
ySpeed#(id)=0
yPos#=get ground height(1,xPos#,zPos#)
`------------------------------
`tilt the vehicle to the ground
`------------------------------
distVal#=1.2
`work out the positions of the front, back, left and right of the vehicle
ang#=yAng# : frontX#=newxvalue(xPos#,ang#,distVal#) : frontZ#=newzvalue(zPos#,ang#,distVal#)
ang#=yAng#+180 : backX#=newxvalue(xPos#,ang#,distVal#) : backZ#=newzvalue(zPos#,ang#,distVal#)
ang#=yAng#+90 : leftX#=newxvalue(xPos#,ang#,distVal#) : leftZ#=newzvalue(zPos#,ang#,distVal#)
ang#=yAng#-90 : rightX#=newxvalue(xPos#,ang#,distVal#) : rightZ#=newzvalue(zPos#,ang#,distVal#)
`work out the different heights
frontHeight#=get ground height(1,frontX#,frontZ#)
backHeight#=get ground height(1,backX#,backZ#)
leftHeight#=get ground height(1,leftX#,leftZ#)
rightHeight#=get ground height(1,rightX#,rightZ#)
`work out tilt values
xAng#=curveangle((backHeight#-frontHeight#)*30,object angle x(id+10),5)
zAng#=curveangle((leftHeight#-rightHeight#)*30,object angle z(id+10),5)
`update the vehicle rotation
rotate object id+10,xAng#,180,zAng#
`-----------------
`slide down slopes
`-----------------
xMoveDist#=(backHeight#-frontHeight#)/3
zMoveDist#=(leftHeight#-rightHeight#)/3
`adjust forward/ backward momentum
xSpeed#(id)=xSpeed#(id)+newxvalue(0,yAng#,xMoveDist#)
zSpeed#(id)=zSpeed#(id)+newzvalue(0,yAng#,xMoveDist#)
`adjust left/ right momentum
xSpeed#(id)=xSpeed#(id)+newxvalue(0,yAng#-90,zMoveDist#)
zSpeed#(id)=zSpeed#(id)+newzvalue(0,yAng#-90,zMoveDist#)
endif
`reposition the player object
position object id,xPos#,yPos#,zPos#
endfunction