Here's n update.
I know the countdown is crap, but.. oh well, lol... I only really posted it to show off the speedometer.
`Racing Game Challenge
`Standad Setup
Sync on : Sync rate 60
Set display mode 1024,768,16 : Hide mouse
Autocam off : set camera range 1,0x7fffffff
`Constants
#constant StartLoop for DL=1 to 0x7fffffff
#constant EndLoop next DL
`Game Variables
grav#=5.0
backcl=rgb(240,102,0)
fogdist=30000
amb=30
lightrange=8000
lightheight=200
`Player Variables
id=1
maxspeed#=70.0
scspeed#=20.0
trac#=0.90 : itrac#=trac#
atrac#=0.999
tracd#=0.0006
traci#=0.01
mtrac#=0.99
acc#=2.0
turnd#=15.0
mturn#=3.0
fxang#=20.0
`Create Player
Create_Car(id)
Color_Car(id,rgb(129,105,105))
make object plain id+1,50,100 : xrotate object id+1,90 : fix object pivot id+1
color object id+1,rgb(0,0,0) : set object ambient id+1,0
set object rotation zyx id+1
x#=3000 : z#=3000
`Create powerslide particles
create bitmap 1,128,128 : set current bitmap 1
for d=1 to 500
ink rgb(rnd(128),rnd(128),rnd(128)),0 : dot rnd(128),rnd(128)
next d
for d=1 to 100
ink rgb(0,0,0),0 : dot rnd(128),rnd(128)
next d
ink rgb(128,128,128),0
circ(64,40,64,64) : circ(50,70,64,64) : circ(70,70,64,64)
blur bitmap 1,6 : get image 50,0,0,128,128
set current bitmap 0 : delete bitmap 1
particles=20
dim particles(1) : particles(1)=particles
dim particlex#(particles)
dim particley#(particles)
dim particlez#(particles)
dim particlexvel#(particles)
dim particleyvel#(particles)
dim particlezvel#(particles)
dim particleangx#(particles)
dim particleangy#(particles)
dim particleangz#(particles)
dim particlelife(particles)
for p=1 to particles(1)
particlex#(p)=emx#
particley#(p)=emy#
particlez#(p)=emz#
next p
for t=1 to particles(1)
make object cube 50+t,100
hide object 50+t : texture object 50+t,50
set object transparency 50+t,1 : set object ambient 50+t,0
next t
`Create world --
`Textures-
`Grass
create bitmap 1,128,128 : set current bitmap 1
cls rgb(0,128,0)
for d=1 To 10000
ink rgb(0,rnd(255),rnd(50)),0
dot rnd(128),rnd(128)
next d
blur bitmap 1,4
get image 10,0,0,128,128
set current bitmap 0 : delete bitmap 1
create bitmap 1,128,128 : set current bitmap 1
cls rgb(128,128,128)
for d=1 To 10000
ink rgb(rnd(200),rnd(200),rnd(200)),0
dot rnd(128),rnd(128)
next d
blur bitmap 1,4
get image 11,0,0,128,128
set current bitmap 0 : delete bitmap 1
create bitmap 1,512,128 : set current bitmap 1
paste image 10,0,0
paste image 11,128,0
get image 15,0,0,512,128
set current bitmap 0 : delete bitmap 1
`Create and Mold
make matrix 1,20000,20000,50,50
wallh=1000
for x=1 to 49
for z=1 to 49
set matrix height 1,x,1,wallh : set matrix height 1,x,50,wallh
set matrix height 1,1,z,wallh : set matrix height 1,50,z,wallh
next x
next z
for x=2 to 49
for z=2 to 49
set matrix height 1,x,2,wallh : set matrix height 1,x,49,wallh
set matrix height 1,2,z,wallh : set matrix height 1,49,z,wallh
next x
next z
for x=10 to 40
for z=10 to 40
set matrix height 1,x,z,wallh
next x
next z
for x=20 to 30
for z=30 to 40
set matrix height 1,x,z,0
next x
next z
for z=40 to 49
set matrix height 1,25,z,wallh
next z
for x=2 to 9
set matrix height 1,x,21,30
set matrix height 1,x,22,60
set matrix height 1,x,23,150
set matrix height 1,x,24,300
set matrix height 1,x,25,700
next x
`Texture
prepare matrix texture 1,15,4,1
for x=1 to 49
for z=1 to 49
set matrix tile 1,x,z,2
next x
next z
for x=3 to 8
for z=3 to 47
set matrix tile 1,x,z,1
next x
next z
for x=9 to 23
for z=41 to 47
set matrix tile 1,x,z,1
next x
next z
for x=20 to 29
for z=31 to 38
set matrix tile 1,x,z,1
next x
next z
for x=26 to 47
for z=41 to 47
set matrix tile 1,x,z,1
next x
next z
for x=41 to 47
for z=3 to 47
set matrix tile 1,x,z,1
next x
next z
for x=3 to 47
for z=3 to 8
set matrix tile 1,x,z,1
next x
next z
for x=20 to 23
for z=31 to 47
set matrix tile 1,x,z,1
next x
next z
for x=26 to 29
for z=31 to 47
set matrix tile 1,x,z,1
next x
next z
`Matrix Lightng
for z=1 to 49
for x=1 to 49
h8#=get matrix height(1,x,z-1)
h4#=get matrix height(1,x-1,z)
h#=get matrix height(1,x,z)
h2#=get matrix height(1,x,z)
x1#=(x-1)*25.0 : y1#=h#
x2#=(x+0)*25.0 : y2#=h4#
dx#=x2#-x1#
dy#=y2#-y1#
ax#=atanfull(dx#,dy#)
ax#=wrapvalue(90-ax#)
z1#=(z-1)*25.0 : y1#=h2#
z2#=(z+0)*25.0 : y2#=h8#
dz#=z2#-z1#
dy#=y2#-y1#
az#=atanfull(dz#,dy#)
az#=wrapvalue(90-az#)
nx#=sin(wrapvalue(ax#+45))
ny#=cos(ax#)
nz#=sin(wrapvalue(az#+45))
set matrix normal 1,x,z,nx#,ny#,nz#
next x
next z
update matrix 1
`Lighting
fog on
backdrop on
fog distance fogdist
fog color backcl
color backdrop backcl
`set ambient light amb
color ambient light backcl
for l=1 to 5
make light l
color light l,rgb(255,255,255)
set light range l,lightrange
next l
position light 1,2400,lightheight,19000
position light 2,8720,lightheight,12300
position light 3,11950,lightheight,12050
position light 4,19030,lightheight,19150
position light 5,19050,lightheight,1600
`Create Light posts
for l=1 to 5
make object box 100+l,10,lightheight*2,10
make object cone 105+l,100
next l
position object 101,2400,lightheight,19000
position object 102,8720,lightheight,12300
position object 103,11950,lightheight,12050
position object 104,19030,lightheight,19150
position object 105,19050,lightheight,1600
position object 106,2400,lightheight*2,19000
position object 107,8720,lightheight*2,12300
position object 108,11950,lightheight*2,12050
position object 109,19030,lightheight*2,19150
position object 110,19050,lightheight*2,1600
`Create opponents
type wp
x as float
y as float
z as float
endtype
dim wp(7) as wp
type opp
x as float
y as float
z as float
ax as float
ay as float
az as float
ma as float
oldx as float
oldy as float
oldz as float
yspeed as float
truey as float
cw as integer
nw as integer
wa as float
smooth as float
speed as float
endtype
dim opp(3) as opp
for o=1 to 3
clone object 10+o,id : Color_Car(10+o,rgb(rnd(255),rnd(255),rnd(255)))
yrotate object 10+o,180 : fix object pivot 10+o
next o
opp(1).x=2800
opp(2).x=3200
opp(3).x=3400
for o=1 to 3
opp(o).z=3000
opp(o).cw=6
opp(o).smooth=rnd(10.0)
opp(o).speed=10.0
next o
dim wd(3,7)
`Configure waypoints
wp(1).x=2500 : wp(1).z=17650
wp(2).x=8875 : wp(2).z=17350
wp(3).x=10000 : wp(3).z=13280
wp(4).x=11800 : wp(4).z=17601
wp(5).x=17450 : wp(5).z=18000
wp(6).x=17460 : wp(6).z=2450
wp(7).x=2580 : wp(7).z=2880
`Countdown
count=3
cnt=timer()
`*Main Loop*
StartLoop
`Controls Elements
Gosub _Countdown
Gosub _Control_Player
Gosub _Control_Effects
Gosub _Control_Racing
Gosub _Control_Camera
Gosub _Interfaces
`text 10,50,str$(x#)
`text 10,70,str$(z#)
`*End Loop*
If escapekey()=1 then end
Sync
EndLoop
`*Subroutines*
`Countdown
_Countdown:
do
`cls rgb(0,0,52)
ink rgb(255,255,0),0
`set text size 100
`set text font "Impact"
`set text to bold
elapsed=(timer()-cnt)/1000
countleft=count-elapsed
if countleft>0 then text screen width()/2,screen height()/2,str$(countleft)
if countleft<=0 then exit
sync
loop
`set text size 20
`set text font "Arial"
`set text to bold
Return
`Control Player
_Control_Player:
`Controls
oldx#=x#
oldy#=y#
oldz#=z#
if y#<truey#+1.0
if upkey()=1 then inc speed# : xspeed#=sin(ay#)*speed# : zspeed#=cos(ay#)*speed# : trac#=trac#+traci#
if upkey()=0 then trac#=trac#-tracd# : dec speed#
turn#=movespeed#/turnd#
if leftkey()=1 then ay#=wrapvalue(ay#-turn#)
if rightkey()=1 then ay#=wrapvalue(ay#+turn#)
endif
`Movement + Physics
if trac#>=mtrac# then trac#=mtrac#
if trac#<=itrac# then trac#=itrac#
if speed#>=maxspeed# then speed#=maxspeed#
if speed#<=0.0 then speed#=0.0
if y#<truey#+1.0
xspeed#=xspeed#*trac#
zspeed#=zspeed#*trac#
else
xspeed#=xspeed#*atrac#
zspeed#=zspeed#*atrac#
endif
x#=x#+xspeed#
z#=z#+zspeed#
moveang#=atanfull(x#-oldx#,z#-oldz#)
movespeed#=sqrt((x#-oldx#)^2+(z#-oldz#)^2)
if upkey()=0 and downkey()=0
if leftkey()=0 and rightkey()=0
if movespeed#>=scspeed#
if y#<truey#+1.0
ay#=curveangle(moveang#,ay#,fxang#)
endif
endif
endif
endif
`Ground Tilting and jumping off
truey#=get ground height(1,x#,z#)+30
if y#<=truey# then y#=truey#
y#=y#+yspeed#
if y#=truey#
yspeed#=y#-oldy#
else
yspeed#=-grav#
endif
out#=2
frontx#=x#+sin(ay#)*out#
frontz#=z#+sin(ay#)*out#
backx#=x#+sin(ay#)*out#*-1
backz#=z#+sin(ay#)*out#*-1
leftx#=x#+sin(wrapvalue(ay#-90))*out#
leftz#=z#+cos(wrapvalue(ay#-90))*out#
rightx#=x#+sin(wrapvalue(ay#+90))*out#
rightz#=z#+cos(wrapvalue(ay#+90))*out#
front#=get ground height(1,frontx#,frontz#)
back#=get ground height(1,backx#,backz#)
left#=get ground height(1,leftx#,leftz#)
right#=get ground height(1,rightx#,rightz#)
ax#=wrapvalue(curveangle((front#-back#)*30,object angle x(id),5.0))
az#=wrapvalue(curveangle((right#-left#)*30,object angle z(id),5.0))
`Dont go up steep hills
sx#=0 : sz#=0
for r=0 to 35
ex#=x#+sin(r*10)*55
ez#=z#+cos(r*10)*55
eh#=get ground height(1,ex#,ez#)
if eh#<-20.0 then eh#=-20.0
slideforce#=(eh#+50.0)/300.0
sx#=sx#+((ex#-x#)*slideforce#)
sz#=sz#+((ez#-z#)*slideforce#)
next r
if x#<1250 or x#>3550 and z#<7950 or z#>10490
x#=x#-(sx#/2.0)
z#=z#-(sz#/2.0)
endif
`Update Player
position object id,x#,y#,z#
if y#<truey#+1.0 then rotate object id,ax#,ay#,az#
`Update shadow
position object id+1,x#,truey#-29,z#
rotate object id+1,ax#,ay#,az#
`Check if powersliding
if ay#<wrapvalue(moveang#-45) and ay#>wrapvalue(moveang#-135) and y#<truey#+1.0 and speed#>0.0 or ay#>wrapvalue(moveang#+45) and ay#<wrapvalue(moveang#+135) and y#<truey#+1.0 and speed#>0.0
powerslide=1
else
powerslide=0
endif
Return
`Control Effects
_Control_Effects:
`Powerslide particles
scx#=x#-sin(ay#)*50
scz#=z#-cos(ay#)*50
scy#=y#-10.0
if powerslide=1 then powerparts=0 else powerparts=1
particle(scx#,scy#,scz#,particles(1),2.0,4.0,2.0,20,80.0,80.0,0.01)
control_particle(0,-0.3,0,0.95,0.95,0.95,1.0,1.0,0.0,1,1,1,powerparts)
Return
`Control Racing
_Control_Racing:
`Opponent Phsyics
for o=1 to 3
opp(o).oldx=opp(o).x
opp(o).oldy=opp(o).y
opp(o).oldz=opp(o).z
opp(o).truey=get ground height(1,opp(o).x,opp(o).z)+30
if opp(o).y<opp(o).truey then opp(o).y=opp(o).truey
opp(o).y=opp(o).y+opp(o).yspeed
if opp(o).y=opp(o).truey
opp(o).yspeed=opp(o).y-opp(o).oldy
else
opp(o).yspeed=-grav#
endif
`AI
for w=1 to 7
wd(o,w)=sqrt( (opp(o).x-wp(w).x)^2 + (opp(o).y-30)^2 + (opp(o).z-wp(w).z)^2 )
if wd(o,w)<100 then opp(o).cw=w
select opp(o).cw
case 1
opp(o).ma=atanfull(opp(o).x-wp(2).x,opp(o).z-wp(2).z)
endcase
case 2
opp(o).ma=atanfull(opp(o).x-wp(3).x,opp(o).z-wp(3).z)
endcase
case 3
opp(o).ma=atanfull(opp(o).x-wp(4).x,opp(o).z-wp(4).z)
endcase
case 4
opp(o).ma=atanfull(opp(o).x-wp(5).x,opp(o).z-wp(5).z)
endcase
case 5
opp(o).ma=atanfull(opp(o).x-wp(6).x,opp(o).z-wp(6).z)
endcase
case 6
opp(o).ma=atanfull(opp(o).x-wp(7).x,opp(o).z-wp(7).z)
endcase
case 7
opp(o).ma=atanfull(opp(o).x-wp(1).x,opp(o).z-wp(1).z)
endcase
endselect
opp(o).ay=curveangle(opp(o).ma,opp(o).ay,opp(o).smooth)
opp(o).x=opp(o).x+sin(opp(o).ay)*-(opp(o).speed/1)
opp(o).z=opp(o).z+cos(opp(o).ay)*-(opp(o).speed/1)
next w
position object 10+o,opp(o).x,opp(o).y,opp(o).z
yrotate object 10+o,opp(o).ay
next o
Return
`Control Camera
_Control_Camera:
`Camera
ca#=curveangle(ay#,ca#,20.0)
cx#=x#-sin(ca#)*400.0
cz#=z#-cos(ca#)*400.0
cy#=curvevalue(y#+200.0,cy#,10.0)
position camera cx#,cy#,cz#
point camera x#,y#,z#
Return
`Interfaces
_Interfaces:
`Speedo
speed$="Speed: "
Border_text(10,10,speed$,rgb(255,255,255),rgb(255,0,255))
Border_text(10+text width(speed$),10,str$(int(Movespeed#))+" mph",rgb(255,255,255),rgb(255,0,0))
`Border_Text(10,40,"Lap: "+str$(lap),rgb(255,255,255),rgb(0,0,0))
ink rgb(255,255,255),0
speedox=100
speedoy=100
speedow=4
speedl=50
Create_Speedometer(movespeed#,speedox,speedoy,speedow,speedl,rgb(255,0,255),rgb(0,255,0))
Return
`*Functions*
Function Create_Car(id)
create bitmap 1,100,100 : set current bitmap 1
cls rgb(0,0,0) : ink rgb(128,128,128),0
for x=1 to 100 : for y=1 to 100
if sqrt((x-50)^2+(y-50)^2)<50 then box x,y,x+1,y+1
next x : next y
get image id,0,0,100,100 : set current bitmap 0 : delete bitmap 1
make object box id,50,20,100 : make mesh from object id,id
add limb id,id,id : delete mesh id
make object box id+1,50,15,50 : xrotate object id+1,343.3 : glue object to limb id+1,id,id
make object plain id+2,20,20 : make object plain id+3,20,20
make object plain id+4,20,20 : make object plain id+5,20,20
for w=2 to 5 : yrotate object id+w,90 : glue object to limb id+w,id,id : next w
color object id,col : color object id+1,col
for c=1 to 5 : make mesh from object id+c,id+c : add limb id,id+c,id+c
delete mesh id+c : delete object id+c : next c
offset limb id,id+1,0,10.0,-23.9
offset limb id,id+2,-26,-10.0,30 : offset limb id,id+3,26,-10.0,30
offset limb id,id+4,-26,-10.0,-30 : offset limb id,id+5,26,-10.0,-30
rotate limb id,id+3,0,180,0 : rotate limb id,id+5,0,180,0
for w=2 to 5 : texture limb id,id+w,id : next w
set object cull id,0 : set object transparency id,1 : set object rotation zyx id
Endfunction
Function Color_Car(id,col)
color limb id,1,col : color limb id,2,col
endfunction
`Particles
function particle(px#,py#,pz#,particles,intx#,inty#,intz#,life,sclx#,scly#,sclz#)
t=0:p=0
repeat
t=t+1
if particlelife(t)=0
p=p+1
particlelife(t)=life + rnd(life/5)
particlex#(t)=px#
particley#(t)=py#
particlez#(t)=pz#
particlexvel#(t)=rnd(intx#)-(intx#/2)
particleyvel#(t)=rnd(inty#)-(inty#/2)
particlezvel#(t)=rnd(intz#)-(intz#/2)
show object 50+t
scale object 50+t,sclx#,scly#,sclz#
endif
if p>=particles then exit
until t>=particles(1)
endfunction
Function Control_Particle(velx#,vely#,velz#,fricx#,fricy#,fricz#,rotx#,roty#,rotz#,rot,cam,ghost,hide)
for t=1 to particles(1)
if particlelife(t)>1
particlelife(t) = particlelife(t) - 1
position object 50+t,particlex#(t),particley#(t),particlez#(t)
particlexvel#(t)=particlexvel#(t)*fricx#
particleyvel#(t)=particleyvel#(t)*fricy#
particlezvel#(t)=particlezvel#(t)*fricz#
particlexvel#(t)=particlexvel#(t)-velx#
particleyvel#(t)=particleyvel#(t)-vely#
particlezvel#(t)=particlezvel#(t)-velz#
particlex#(t) = particlex#(t) + particlexvel#(t)
particley#(t) = particley#(t) + particleyvel#(t)
particlez#(t) = particlez#(t) + particlezvel#(t)
`if particley#(t)<=0 then particlelife(t)=0
if cam=1 and rot=1
particleangx#(t)=camera angle x()
particleangy#(t)=camera angle y()
particleangz#(t)=wrapvalue(object angle z(50+t)+rotz#+rnd(particleangx#(t)/5))
endif
if cam=1 and rot=0
particleangx#(t)=camera angle x()
particleangy#(t)=camera angle y()
particleangz#(t)=0
endif
if cam=0 and rot=1
particleangx#(t)=wrapvalue(object angle x(50+t)+rotx#+rnd(particleangx#(t)/5))
particleangy#(t)=wrapvalue(object angle y(50+t)+roty#+rnd(particleangy#(t)/5))
particleangz#(t)=wrapvalue(object angle z(50+t)+rotz#+rnd(particleangz#(t)/5))
endif
if cam=0 and rot=0
particleangx#(t)=0
particleangy#(t)=0
particleangz#(t)=0
endif
rotate object 50+t,particleangx#(t),particleangy#(t),particleangz#(t)
if ghost=1 then ghost object on 50+t else ghost object off 50+t
if hide=1 then hide object 50+t else show object 50+t
endif
if particlelife(t)=1
particlelife(t)=0
hide object 50+t
endif
next t
endfunction
`Bordered text
Function Border_Text(x,y,text$,col1,col2)
ink col2,0
text x-1,y-1,text$
text x+1,y-1,text$
text x-1,y+1,text$
text x+1,y+1,text$
ink col1,0
text x,y,text$
Endfunction
`Circle
Function circ(x1,y1,r,t)
for x=1 to r
for y=1 to r
if sqrt((x-(r/2))^2 + (y-(r/2))^2)<(r/2) and sqrt((x-(r/2))^2 + (y-(r/2))^2)>(r/2)-t
box (x1+x)-(r/2),(y1+y)-(r/2),((x1+x)-(r/2))+1,((y1+y)-(r/2))+1
endif
next x
next y
Endfunction
`Speedometer
Function create_speedometer(movespeed#,speedox,speedoy,speedow,speedl,col1,col2)
ink col1,0
line speedox,speedoy,speedox+sin(wrapvalue(int(360-movespeed#)+180))*(speedow/2),speedoy+cos(wrapvalue(int(360-movespeed#)+180))*(speedow/2)
line speedox,speedoy,speedox-sin(wrapvalue(int(360-movespeed#)+180))*(speedow/2),speedoy-cos(wrapvalue(int(360-movespeed#)+180))*(speedow/2)
line speedox+sin(wrapvalue(int(360-movespeed#)+180))*(speedow/2),speedoy+cos(wrapvalue(int(360-movespeed#)+180))*(speedow/2),speedox+sin(wrapvalue(int(360-movespeed#)+270))*speedl,speedoy+cos(wrapvalue(int(360-movespeed#)+270))*speedl
line speedox-sin(wrapvalue(int(360-movespeed#)+180))*(speedow/2),speedoy-cos(wrapvalue(int(360-movespeed#)+180))*(speedow/2),speedox+sin(wrapvalue(int(360-movespeed#)+270))*speedl,speedoy+cos(wrapvalue(int(360-movespeed#)+270))*speedl
ink col2,0
text speedox-(speedl*1.5),speedoy,"0"
text speedox,speedoy-(speedl*1.5),"90"
text speedox+(speedl*1.5),speedoy,"180"
text speedox,speedoy+(speedl*1.5),"270"
endfunction