Nice work! I did something similar for one of the coding challenges here's my walking robot (also fires missiles) all procedurally done too:
Rem Project: War Machine
Rem Created: 08/02/2010 08:42:39
Rem by baxslash
Rem ***** Main Source File *****
autocam off
sync on
sync rate 60
global sw
global sh
sw=screen width()
sh=screen height()
hide mouse
`color backdrop RGB(159,243,255) `DAY
color backdrop RGB(10,0,100) `EVENING/NIGHT
set camera fov 70
global rate
rate = 60
`Make a simple world
make object box 10000, 1000, 2, 1000
color object 10000, RGB(50, 150,0)
position object 10000, 0,-1,0
for c=10001 to 10020
if RND(1)=1
X=RND(100)
if RND(1)=1
Z=RND(100)
else
Z=-RND(100)
endif
else
X=-RND(100)
if RND(1)=1
Z=RND(100)
else
Z=-RND(100)
endif
endif
make object cube c, 4
position object c, X,2,Z
set shadow shading on c,-1,50,shader
next c
`Make Body
`Hips
make object sphere 1, 4, 40,40
position object 1, 0,8, 0
color object 1, RGB(50,50,50)
`Feet
`Left
make object sphere 2, 2
position object 2, 3,1, 0
color object 2, RGB(50,50,50)
`Right
make object sphere 3, 2
position object 3, -3,1, 0
color object 3, RGB(50,50,50)
`Knees
`Left
LKnee=4
make object sphere LKnee, 2
position object LKnee, 3,5, 0
color object LKnee, RGB(100,100,100)
`Right
RKnee=5
make object sphere RKnee, 2
position object RKnee, -3,5, 0
color object RKnee, RGB(100,100,100)
`length of leg limbs
length=6
`Thighs
`Left
LThigh=6
make object box LThigh, 1,1,length
color object LThigh, RGB(100,100,100)
`Right
RThigh=7
make object box RThigh, 1,1,length
color object RThigh, RGB(100,100,100)
`Calves
`Left
LCalf=8
make object box LCalf, .5,.5,length
color object LCalf, RGB(100,100,100)
`Right
RCalf=9
make object box RCalf, .5,.5,length
color object RCalf, RGB(100,100,100)
`Toes
make object box 10, 1,.5,1
color object 10, RGB(50,50,50)
make object box 11, 1,.5,1
color object 11, RGB(50,50,50)
make object box 12, 1,.5,1
color object 12, RGB(50,50,50)
make object box 13, 1,.5,1
color object 13, RGB(50,50,50)
make object box 14, 1,.5,1
color object 14, RGB(50,50,50)
make object box 15, 1,.5,1
color object 15, RGB(50,50,50)
make object box 16, 1,.5,1
color object 16, RGB(50,50,50)
make object box 17, 1,.5,1
color object 17, RGB(50,50,50)
`Body
make object box 18, 6,3,6
color object 18, RGB(100,100,100)
`missile launcher
make object box 19, 1,1,2
color object 19, RGB(50,50,50)
make object box 20, 1,.5,.5
color object 19, RGB(5,5,5)
REM Shadows and light
set ambient light 0
hide light 0
`general light
make light 1
set point light 1, 50,100,-50
set light range 1, 3000
color light 1, RGB(255,255,255)
shader=1
SET GLOBAL SHADOW COLOR 0,0,0, 200
for x=1 to 20
set shadow shading on x,-1,50,shader
set shadow position -1,50,100,-50
next x
`Make dummy object
dummy=999
make object sphere dummy, 1
hide object dummy
`set up missile array
type type1
Target as integer
Life as integer
Hit as integer
TX as float
TY as float
TZ as float
endtype
Dim Missile(100) as type1
`set up explosion array
type type2
Life as integer
endtype
Dim Boom(100) as type2
`set up parts array
type type3
FX as float
FY as float
FZ as float
RX as float
RY as float
RZ as float
endtype
Dim Part(300) as type3
global speed as float
global foot
global camang#
global Obj
camang# = 180
mdx#=100
`############################################################### MAIN LOOP START
do
camera()
gosub move
update_explosions()
update_parts()
gosub firepower
gosub _update_missiles
target(p)
sync
loop
`############################################################### MAIN LOOP END
function target(p)
if p<>0
ink RGB(255,0,0),0
else
ink RGB(0,255,0),0
endif
line mousex()-5,mousey(),mousex()+5,mousey()
line mousex(),mousey()-5,mousex(),mousey()+5
endfunction
move:
if moving=0 then move$=""
if keystate(17)=1
if moving=0
move$="Backward"
turn$=""
endif
moving=1
endif
if keystate(31)=1
if moving=0
move$="Forward"
turn$=""
endif
moving=1
endif
if keystate(30)=1
if move$="" then move$="Left"
if moving=1
if move$="Forward" then turn$="Left"
if move$="Backward" then turn$="Right"
endif
endif
if keystate(32)=1
if move$="" then move$="Right"
if moving=1
if move$="Forward" then turn$="Right"
if move$="Backward" then turn$="Left"
endif
endif
if foot=0 `2 is left 3 is right
foot=RND(1)+2
endif
set cursor 0,0
if moving=1
if move$="Forward"
if prevmove$="Forward"
if foot=2
foot=3
else
foot=2
endif
endif
if foot=2 then pos=1
if foot=3 then pos=-1
move object 1, 6
move object right 1, pos*3
FX#=object position x(1)
FY#=object position y(foot)
FZ#=object position z(1)
prevmove$=move$
move$="Committed"
endif
if move$="Backward"
if prevmove$="Backward"
if foot=2
foot=3
else
foot=2
endif
endif
if foot=2 then pos=1
if foot=3 then pos=-1
move object 1, -8
move object right 1, pos*3
FX#=object position x(1)
FY#=object position y(foot)
FZ#=object position z(1)
prevmove$=move$
move$="Committed"
endif
if move$="Settle"
if foot=2
foot=3
else
foot=2
endif
if foot=2 then pos=1
if foot=3 then pos=-1
if prevmove$="Forward" then move object 1, 3
if prevmove$="Backward" then move object 1, -3
move object right 1, pos*3
FX#=object position x(1)
FY#=object position y(foot)
FZ#=object position z(1)
prevmove$=move$
move$="Committed"
endif
if move$="Committed"
inc movecount
`turn foot towards new position
roty#=object angle y(foot)
point object foot, FX#,FY#,FZ#
newy#=object angle y(foot)
if turnfoot#=0
turnfoot#=(newy#-roty#)/rate
endif
rotate object foot, object angle x(foot), object angle y(foot)+turnfoot, object angle z(foot)
`move foot towards new position
if movefoot#=0
dx#=FX#-object position x(foot)
dy#=FY#-object position y(foot)
dz#=FZ#-object position z(foot)
d#=sqrt(dx#^2+dy#^2+dz#^2)
movefoot#=d#/rate
endif
if movecount<=rate
if turn$="Left" then turn object right 1, .3
if turn$="Right" then turn object left 1, .3
move object foot, movefoot#
if movecount<=40
position object foot, object position x(foot), object position y(foot)+movefoot#*1.1, object position z(foot)
else
position object foot, object position x(foot), object position y(foot)-movefoot#*1.1, object position z(foot)
endif
if movecount<=30
move object up 1, movefoot#/2
else
move object down 1, movefoot#/2
endif
if object position y(foot)<1 then position object foot, object position x(foot), 1, object position z(foot)
if object position y(1)<8 then position object 1, object position x(1), 8, object position z(1)
else
move$=""
moving=0
if prevmove$="Forward" or prevmove$="Backward"
if keystate(17)=0 and keystate(30)=0 and keystate(31)=0 and keystate(32)=0
move$="Settle":moving=1
endif
endif
movecount=0
turnfoot#=0
movefoot#=0
endif
endif
endif
`reposition hip
PX#=object position x(2)-((object position x(2)-object position x(3))/2)
PY#=object position y(1)
PZ#=object position z(2)-((object position z(2)-object position z(3))/2)
position object 1, PX#,PY#,PZ#
`position Left knee
dx#=object position x(1)-object position x(2)
dy#=object position y(1)-object position y(2)
dz#=object position z(1)-object position z(2)
d#=sqrt(dx#^2+dy#^2+dz#^2)
ang#=asin((d#/2)/length)
hyp#=length * cos(ang#)
mX#=(sqrt(dx#^2+dz#^2))/1.5
mY#=dy#/2
mZ#=sqrt(hyp#^2-mX#^2)
position object LKnee, object position x(1),object position y(1)-mY#,object position z(1)
set object to object orientation LKnee, 1
move object right LKnee, mX#
move object LKnee, mZ#
`position Right knee
dx#=object position x(1)-object position x(3)
dy#=object position y(1)-object position y(3)
dz#=object position z(1)-object position z(3)
d#=sqrt(dx#^2+dy#^2+dz#^2)
ang#=asin((d#/2)/length)
hyp#=length * cos(ang#)
mX#=(sqrt(dx#^2+dz#^2))/1.5
mY#=dy#/2
mZ#=sqrt(hyp#^2-mX#^2)
position object RKnee, object position x(1),object position y(1)-mY#,object position z(1)
set object to object orientation RKnee, 1
move object left RKnee, mX#
move object RKnee, mZ#
`check knee pos
dx#=object position x(LKnee)-object position x(2)
dy#=object position y(LKnee)-object position y(2)
dz#=object position z(LKnee)-object position z(2)
d#=sqrt(dx#^2+dy#^2+dz#^2)
if d#<>length
point object LKnee, object position x(2),object position y(2),object position z(2)
move object LKnee, d#-length
endif
dx#=object position x(LKnee)-object position x(1)
dy#=object position y(LKnee)-object position y(1)
dz#=object position z(LKnee)-object position z(1)
d#=sqrt(dx#^2+dy#^2+dz#^2)
if d#<>length
point object LKnee, object position x(1),object position y(1),object position z(1)
move object LKnee, d#-length
endif
dx#=object position x(RKnee)-object position x(3)
dy#=object position y(RKnee)-object position y(3)
dz#=object position z(RKnee)-object position z(3)
d#=sqrt(dx#^2+dy#^2+dz#^2)
if d#<>length
point object RKnee, object position x(3),object position y(3),object position z(3)
move object RKnee, d#-length
endif
dx#=object position x(RKnee)-object position x(1)
dy#=object position y(RKnee)-object position y(1)
dz#=object position z(RKnee)-object position z(1)
d#=sqrt(dx#^2+dy#^2+dz#^2)
if d#<>length
point object RKnee, object position x(1),object position y(1),object position z(1)
move object RKnee, d#-length
endif
`position thighs
position object LThigh, object position x(1),object position y(1),object position z(1)
point object LThigh, object position x(LKnee),object position y(LKnee),object position z(LKnee)
move object LThigh, length/2
position object RThigh, object position x(1),object position y(1),object position z(1)
point object RThigh, object position x(RKnee),object position y(RKnee),object position z(RKnee)
move object RThigh, length/2
`position calves
position object LCalf, object position x(LKnee),object position y(LKnee),object position z(LKnee)
point object LCalf, object position x(2),object position y(2),object position z(2)
move object LCalf, length/2
position object RCalf, object position x(RKnee),object position y(RKnee),object position z(RKnee)
point object RCalf, object position x(3),object position y(3),object position z(3)
move object RCalf, length/2
`position toes
for x=10 to 13
position object x, object position x(2),object position y(2),object position z(2)
set object to object orientation x, 2
next x
for x=14 to 17
position object x, object position x(3),object position y(3),object position z(3)
set object to object orientation x, 3
next x
turn object right 11, 90
turn object right 15, 90
turn object right 12, 180
turn object right 16, 180
turn object left 13, 90
turn object left 17, 90
if moving=1
if foot=2
for x=10 to 13
if movecount<=30 then pitch object down x, movecount
if movecount>30 then pitch object down x, 60-movecount
next x
endif
if foot=3
for x=14 to 17
if movecount<=30 then pitch object down x, movecount
if movecount>30 then pitch object down x, 60-movecount
next x
endif
endif
for x=10 to 17
move object x, 1.2
move object down x, .75
next x
`position body
position object 18, object position x(1),object position y(1)+2,object position z(1)
rotate object 18, 0,camera angle y(),0
`position launcher
position object 19, object position x(18),object position y(18),object position z(18)
set object to object orientation 19, 18
move object right 19, 4.5
position object 20, object position x(18),object position y(18),object position z(18)
set object to object orientation 20, 18
move object right 20, 3.5
return
function camera()
sw#=sw
if mousex()<sw/3
camang#=camang#-(((sw#/3)-mousex())/100)
endif
if mousex()>(sw*2)/3
camang#=camang#-((((sw*2)/3)-mousex())/100)
endif
set camera to follow object position x(1),10,object position z(1), camang#, 20,10, 10,0
point camera object position x(1),10,object position z(1)
endfunction
firepower:
p=pick object(mousex(), mousey(), 10001,11000)
pd#=get pick distance()
px#=get pick vector x()
py#=get pick vector y()
pz#=get pick vector z()
tx#=px#+camera position x()
ty#=py#+camera position y()
tz#=pz#+camera position z()
if mouseclick()=1
if p<>0
if prevmouse=0
mx#=object position x(19)
my#=object position y(19)
mz#=object position z(19)
gosub _make_missile
endif
endif
prevmouse=1
else
prevmouse=0
endif
return
_make_missile:
Missile=5051
while object exist(Missile)=1 or particles exist(Missile)=1
inc Missile
endwhile
make object sphere Missile, .5,6,6
Missile(Missile-5050).Target=p
Missile(Missile-5050).Life=300
Missile(Missile-5050).TX=object position x(p)
Missile(Missile-5050).TY=object position y(p)
Missile(Missile-5050).TZ=object position z(p)
position object Missile, mx#,my#,mz#
set object to object orientation Missile, 19
MAKE PARTICLES Missile, 1, 100, 2
color particles Missile, 10,10,10
set particle emissions Missile, 100
set particle speed Missile, 0.03
set particle gravity Missile, 1
set particle chaos Missile,1.0
set particle life Missile,50
return
_update_missiles:
for m=5051 to 5100
if object exist(m)=1
Targ=Missile(m-5050).Target
if object exist(Targ)=1 and Missile(m-5050).Life>0
Missile(m-5050).Life=Missile(m-5050).Life-1
`check distance from target
DX#=object position x(m)-object position x(Targ)
DY#=object position y(m)-object position y(Targ)
DZ#=object position z(m)-object position z(Targ)
DT#=SQRT(DX#^2+DY#^2+DZ#^2)
`check diff in angle from pointing at target
dirMX#=object angle x(m)
dirMY#=object angle y(m)
dirMZ#=object angle z(m)
point object m, object position x(Targ),object position y(Targ),object position z(Targ)
TMX#=object angle x(m)
TMY#=object angle y(m)
TMZ#=object angle z(m)
rotate object m, dirMX#,dirMY#,dirMZ#
TdffX#=TMX#-dirMX#
TdffY#=TMY#-dirMY#
TdffZ#=TMZ#-dirMZ#
if TdffX#>180 then TdffX#=TdffX#-360
if TdffY#>180 then TdffY#=TdffY#-360
if TdffZ#>180 then TdffZ#=TdffZ#-360
Tdff#=TdffX#+TdffY#+TdffZ#
`set change in angle
if DT#>300
turnratio#=0.1
else
turnratio#=1-(DT#/300)
endif
if Missile(m-5050).Life<250
rotate object m, object angle x(m)+TdffX#*turnratio#,object angle y(m)+TdffY#*turnratio#,object angle z(m)+TdffZ#*turnratio#
else
turn object left m, .2-(RND(40)*.01)
endif
`move missile
move object m, 15
`move particles
POSITION PARTICLE EMISSIONS m, object position x(m),object position y(m),object position z(m)
`explode?
insx#=object position x(m)
insy#=object position y(m)
insz#=object position z(m)
if DT#<8
GOSUB _missile_explosion
else
`blow up if hit something else
if Missile(m-5050).Hit=1
GOSUB _missile_explosion
endif
endif
else
`missile blows up if object otherwise destroyed
GOSUB _missile_explosion
endif
endif
`let trails live a little after missile has blown up
if particles exist(m)=1 and object exist(m)=0
if Missile(m-5050).Life>0
dec Life
else
Missile(m-5050).Life=0
delete particles m
endif
endif
next m
return
function update_explosions()
for b=0 to 50
if particles exist(b+5000)=1
if Boom(b).Life>0
Life=Boom(b).Life
set particle emissions b+5000, 0
dec Life
Boom(b).Life=Life
else
Boom(b).Life=0
delete particles b+5000
endif
endif
next b
endfunction
_missile_explosion:
rem Make particles
Boom=5000
while particles exist(Boom)=1
inc Boom
endwhile
MAKE PARTICLES Boom, 1, 100, 3
t=Missile(m-5050).Target
TX#=Missile(m-5050).TX
TY#=Missile(m-5050).TY
TZ#=Missile(m-5050).TZ
position particles Boom, TX#,TY#,TZ#
color particles Boom, 255, 128, 0
set particle emissions Boom, 100
set particle speed Boom, 0.03
set particle gravity Boom, 1
set particle chaos Boom,1.0
set particle life Boom,100
Boom(Boom-5000).Life=1000
delete object m
set particle emissions m, 0
`GOSUB _createExplosion
if object exist(t) then destroy_target(t)
Missile(m-5050).Target=0
Missile(m-5050).Life=100
return
function destroy_target(t)
X#=object position x(t)
Y#=object position y(t)
Z#=object position z(t)
delete object t
`make replacement parts and add forces
gosub _GET_OBJ
make object box Obj, 4,.1,4
position object Obj, X#,Y#-1.95,Z#
set shadow shading on Obj,-1,50,shader
Part(Obj-9000).FX=0
Part(Obj-9000).FY=.5
Part(Obj-9000).FZ=0
Part(Obj-9000).RX=RND(100)/10:Part(Obj-9000).RY=RND(100)/10:Part(Obj-9000).RZ=RND(100)/10
gosub _GET_OBJ
make object box Obj, 4,.1,4
position object Obj, X#,Y#+1.95,Z#
set shadow shading on Obj,-1,50,shader
Part(Obj-9000).FX=0
Part(Obj-9000).FY=1
Part(Obj-9000).FZ=0
Part(Obj-9000).RX=RND(100)/10:Part(Obj-9000).RY=RND(100)/10:Part(Obj-9000).RZ=RND(100)/10
gosub _GET_OBJ
make object box Obj, .1,4,4
position object Obj, X#-1.95,Y#,Z#
set shadow shading on Obj,-1,50,shader
Part(Obj-9000).FX=-1
Part(Obj-9000).FY=1
Part(Obj-9000).FZ=0
Part(Obj-9000).RX=RND(100)/10:Part(Obj-9000).RY=RND(100)/10:Part(Obj-9000).RZ=RND(100)/10
gosub _GET_OBJ
make object box Obj, .1,4,4
position object Obj, X#+1.95,Y#,Z#
set shadow shading on Obj,-1,50,shader
Part(Obj-9000).FX=1
Part(Obj-9000).FY=1
Part(Obj-9000).FZ=0
Part(Obj-9000).RX=RND(100)/10:Part(Obj-9000).RY=RND(100)/10:Part(Obj-9000).RZ=RND(100)/10
gosub _GET_OBJ
make object box Obj, 4,4,.1
position object Obj, X#,Y#,Z#-1.95
set shadow shading on Obj,-1,50,shader
Part(Obj-9000).FX=0
Part(Obj-9000).FY=1
Part(Obj-9000).FZ=-1
Part(Obj-9000).RX=RND(100)/10:Part(Obj-9000).RY=RND(100)/10:Part(Obj-9000).RZ=RND(100)/10
gosub _GET_OBJ
make object box Obj, 4,4,.1
position object Obj, X#,Y#,Z#+1.95
set shadow shading on Obj,-1,50,shader
Part(Obj-9000).FX=0
Part(Obj-9000).FY=1
Part(Obj-9000).FZ=1
Part(Obj-9000).RX=RND(100)/10:Part(Obj-9000).RY=RND(100)/10:Part(Obj-9000).RZ=RND(100)/10
endfunction
function update_parts()
for p=9000 to 9299
if object exist(p)
FX#=Part(p-9000).FX
FY#=Part(p-9000).FY
FZ#=Part(p-9000).FZ
RX#=Part(p-9000).RX
RY#=Part(p-9000).RY
RZ#=Part(p-9000).RZ
position object p, object position x(p)+FX#,object position y(p)+FY#,object position z(p)+FZ#
rotate object p, object angle x(p)+RX#,object angle y(p)+RY#,object angle z(p)+RZ#
FX#=FX#*.9999
FZ#=FZ#*.9999
if object position y(p)>-2
if FY#>0.0
if FY#<.1
FY#=-FY#
else
FY#=FY#*.9
endif
else
FY#=FY#*1.05
endif
else
delete object p
endif
Part(p-9000).FX=FX#
Part(p-9000).FY=FY#
Part(p-9000).FZ=FZ#
endif
next p
endfunction
_GET_OBJ:
Obj=9000
while object exist(Obj)=1
inc Obj
endwhile
return
Of course mine is vastly overcomplicated compaired to yours!