Was daydreaming of some sort of cool looking top down shooter/tank game at work today, so I got home and knocked up this little demo.
Hoping to develop into a full scale arcadey tank adventure with weapon and armour upgrades and masses of beautiful destruction.
Any comments on ease of use etc? And the code is of course free to use in your own projects.
` tank
` init
sync on: sync rate 60
autocam off: set camera range 1,10000
color backdrop 0
` make level
make matrix 1,5000,5000,50,50
` make tank
global tank_body=1
global tank_ltrack=2
global tank_rtrack=3
global tank_turret=4
global tank_weapon=5
` body
make object plain tank_body,50,50:xrotate object tank_body,270:set object wireframe tank_body,1
make object plain tank_ltrack,20,65:xrotate object tank_ltrack,270:set object wireframe tank_ltrack,1
make object plain tank_rtrack,20,65:xrotate object tank_rtrack,270:set object wireframe tank_rtrack,1
make object plain tank_turret,35,35:xrotate object tank_turret,270:set object wireframe tank_turret,1
make object plain tank_weapon,20,50:xrotate object tank_weapon,270:set object wireframe tank_weapon,1
` weapon
global cool#=0.0
global cool_time#=0.1
` init
x#=300:z#=300
` loop
do
` debug
set cursor 0,0
print screen fps()
print "Move - W/A/S/D"
print "Aim - Mouse"
print "Fire - LMB"
` control tank
acc#=0.3:turn#=3
if keystate(17)=1 then speed#=speed#+acc#
if keystate(31)=1 then speed#=speed#-acc#
if keystate(30)=1 then a#=a#-turn#
if keystate(32)=1 then a#=a#+turn#
` update position
x#=newxvalue(x#,a#,speed#)
z#=newzvalue(z#,a#,speed#)
` deccelerate
speed#=speed#/1.1
` body
position object tank_body,x#,y#,z#
yrotate object tank_body,a#
` left track
tx#=newxvalue(x#,a#+270,25):tz#=newzvalue(z#,a#+270,25)
tx#=newxvalue(tx#,a#,speed#):tz#=newzvalue(tz#,a#,speed#)
position object tank_ltrack,tx#,ty#,tz#
yrotate object tank_ltrack,a#
` right track
tx#=newxvalue(x#,a#+90,25):tz#=newzvalue(z#,a#+90,25)
tx#=newxvalue(tx#,a#,speed#):tz#=newzvalue(tz#,a#,speed#)
position object tank_rtrack,tx#,ty#,tz#
yrotate object tank_rtrack,a#
` turret
tx#=newxvalue(x#,a#+180,speed#):tz#=newzvalue(z#,a#+180,speed#)
position object tank_turret,tx#,ty#+1,tz#
ta#=object angle y(tank_turret)
target_a#=atanfull((object screen x(tank_turret)-mousex()),(object screen y(tank_turret)-mousey()))
ta#=curveangle((0-target_a#),ta#,20)
yrotate object tank_turret,ta#
` weapon
tx#=newxvalue(tx#,ta#,25-cool#):tz#=newzvalue(tz#,ta#,25-cool#)
position object tank_weapon,tx#,ty#+1,tz#
yrotate object tank_weapon,ta#
` track marks
td#=td#+abs(speed#)
if td#>20
td#=0
` left
tm=100
repeat:inc tm:until object exist(tm)=0
make object plain tm,20,10:xrotate object tm,270
tx#=newxvalue(x#,a#+270,25):tz#=newzvalue(z#,a#+270,25)
position object tm,tx#,y#,tz#:yrotate object tm,a#
set object wireframe tm,1
` right
tm=100
repeat:inc tm:until object exist(tm)=0
make object plain tm,20,10:xrotate object tm,270
tx#=newxvalue(x#,a#+90,25):tz#=newzvalue(z#,a#+90,25)
position object tm,tx#,y#,tz#:yrotate object tm,a#
set object wireframe tm,1
endif
` firing weapon
if cool#<=0
if mouseclick()=1 then cool#=10:shake_amp#=6:shake#=0
else
cool#=cool#-cool_time#
endif
` explosion shake
shake#=shake#+20
shake_x#=sin(shake#)*shake_amp#
shake_z#=sin(shake#*1.5)*shake_amp#
shake_amp#=shake_amp#/1.04
` camera
cx#=x#:cz#=z#:cy#=500
position camera cx#+shake_x#,cy#,cz#+shake_z#
point camera x#+shake_x#,y#,z#+shake_z#
` sync
sync
` end loop
loop