Just for the hell of it - I added a missile launcher
(hope you don't mind me playing, Phaelax!)
hide mouse
sync on
sync rate 60
backdrop on
autocam off
set camera range 0.5, 30000
set dir "C:\Program Files\Dark Basic Software\Dark Basic Professional\Help\Advanced Terrain\Media"
load image "texture.bmp", 1
load image "detail.tga", 2
make object terrain 1 ` create the terrain object
set terrain heightmap 1, "map.bmp" ` set the heightmap
set terrain scale 1, 2, .2, 2 ` set the scale
set terrain split 1, 16 ` split value by 16 * 16
set terrain tiling 1, 4 ` detail map tiling
set terrain light 1, 1, -0.25, 0, 1, 1, 0.78, 0.5 ` light - xdir, ydir, zdir, red, green, blue, intensity
set terrain texture 1, 1, 2 ` base and detail texture
build terrain 1 ` finally build the terrain
` load our skybox
load object "skybox2.x", 200
set object light 200, 0
set object texture 200, 3, 1
position object 200, 1000, 2000, 4000
scale object 200, 30000, 30000, 30000
REM Car
`load object "truck.x", 2
`yrotate object 2,180
`fix object pivot 2
`set object ambient 2, 0
make object cube 2,100
scale object 2,3,2,5
rem dummy object
make object cone 6, 5
hide limb 6,0
glue object to limb 2,6,0
rem starting position
x# = 100
z# = 100
acc# = 0.01
`make missile
make object sphere 100,0.2
`numberofparticles=50 `number of particles in trail
`n=numberofparticles
vresultant#=0.4 `resultant velocity of missile
ay#=0.004 `deceleration due to gravity
ar#=0.003 `air resistance
`hw#=0.0 `headwind/trailing wind
traj#=45 `intitial trajectory
`main loop
DO
gosub _controls
gosub _sliding
y# = tilt(1,x#,z#,a#)+0.2
position object 6, x#, y#, z#
if launchloop=0
position object 100, x#, y#+1, z#
endif
gosub _camera
update terrain
`set trajectory of ball using arrow keys
if inkey$()="a" then traj#=traj#+1
if inkey$()="z" then traj#=traj#-1
print "Trajectory: ",traj#," Use keys A(+), Z(-), Space(launch)"
if launchloop=0
`apply trajectory to missile velocity
vahead#=vresultant#*cos(traj#) `(horizontal velocity)
vy#=vresultant#*sin(traj#) `(vertical velocity)
endif
`check for ball being launched
if launchloop=0
mspx#=x# `get missile start position x
mspy#=y# `get missile start position y
mspz#=z# `get missile start position z
if launchloop=0 then missang#=object angle y(6) `get missile start angle
endif
if spacekey()=1 then launchloop=1
if launchloop=1 then gosub launch
sync
LOOP
_controls:
if upkey()=1
spd# = spd# + acc#
endif
if downkey()=1
spd# = spd# - acc#*2.0
endif
if leftkey()=1 then a#=wrapvalue(a#-1.0)
if rightkey()=1 then a#=wrapvalue(a#+1.0)
`y# = get terrain ground height(1,x#,z#)
if spd# > 0.8 then spd# = 0.8
if spd# < 0 then spd# = 0
x#=newxvalue(x#,a#,spd#)
z#=newzvalue(z#,a#,spd#)
spd# = spd# - acc#/2.0
RETURN
_camera:
rem Position camera to the back of the character
cx#=newxvalue(x#,wrapvalue(a#+180),15)
cz#=newzvalue(z#,wrapvalue(a#+180),15)
cy#=get terrain ground height(1,cx#,cz#)+8.0
position camera cx#,cy#,cz#
rem Point camera at object
point camera x#,y#+5,z#
RETURN
_sliding:
rem control sliding due to angle of slope
opx#=x#
opz#=z#
tx#=opx#+2
tz#=opz#+2
tx2#=opx#-2
tz2#=opz#-2
opy1#=get terrain ground height(1,tx#,opz#)
opy2#=get terrain ground height(1,tx2#,opz#)
opy3#=get terrain ground height(1,opx#,tz#)
opy4#=get terrain ground height(1,opx#,tz2#)
sx#=abs(opy1#-opy2#)*0.2
sz#=abs(opy3#-opy4#)*0.2
if opy1#>opy2# then dec x#, sx#
if opy1#<opy2# then inc x#, sx#
if opy3#>opy4# then dec z#, sz#
if opy3#<opy4# then inc z#, sz#
RETURN
function tilt(number as integer, x# as float, z# as float, ang# as float)
h1# = get terrain ground height(number, x#, z#)
tx# = newxvalue(x#,wrapvalue(ang#+90),2)
tz# = newzvalue(z#,wrapvalue(ang#+90),2)
h2# = get terrain ground height(number, tx#, tz#)
at# = h2# - h1#
b# = 2
angz# = atan(at#/b#)
tx# = newxvalue(x#,ang#,2)
tz# = newzvalue(z#,ang#,2)
h2# = get terrain ground height(number, tx#, tz#)
at# = h2# - h1#
angx# = 360 - atan(at#/b#)
`position object 6, x#, h1#+0.5, z#
yrotate object 6,ang#
rotate object 2,angx#,0,angz#
remstart
if at# > 1.5
hill_force# = -0.4
else
hill_force# = 0.0
endif
set cursor 0,0
print at#
remend
endfunction h1#
launch:
aheadb#=aheadb#+vahead# `increase horizontal position by horizontal velocity
ahead#=vahead#*ar# `deceleration is proportional to air resistance
vahead#=vahead#-aahead# `decrease velocity by deceleration amount due to air res.
yb#=yb#+vy# `increase y position by vertical velocity
vy#=vy#-ay# `decrease velocity by deceleration due to gravity
xb#=aheadb#*sin(missang#) `calculate missiles new x position
zb#=aheadb#*cos(missang#) `calculate missiles new z position
position object 100,mspx#+xb#,mspy#+yb#,mspz#+zb# `update missile position
`bounce when ball hits the ground
if object position y(100)<get terrain ground height(1,object position x (100),object position z(100) )
yb#=yb#+1
vy#=vy#*-0.5 `increase for more bounciness
bounce=bounce+1
if bounce>5 `set number of bounces
`reset missile variables
undim xs(0)
undim ys(0)
n=numberofparticles
p=0
bounce=0
aheadb#=0
sideb#=0
xb#=0
zb#=0
vside#=0
vahead#=0
vy#=0
vresultant#=0.4
aahead#=0
yb#=0
launchloop=0
endif
endif
return