Sorry, code is sloppy, objects may intersect, and they only fall in one direction. Eventually I might add a routine to determine the preferred rotational polarity, and realistically the fall speed should start slower and increase, etc, etc...
* -Be sure to change 'MaxDomino' to your preferred number, as well as the sync rate.
+ Code Snippetgosub Setup:gosub GetNeighbors
do
if lower$(inkey$())="r" then gosub Reset:gosub GetNeighbors:while inkey$()="r":endwhile
gosub MovePieces:control camera using arrowkeys 0,1,6
position object Sky,camera position x(),camera position y(),camera position z()
set cursor 0,0:print "(R)eset":sync
LOOP
Setup:
autocam off:position camera 0,4,-10:make object cube 1,1:convert object fvf 1,338
scale limb 1,0,100,200,20:offset limb 1,0,0,1,0:fix object pivot 1
make mesh from object 1,1:delete object 1:make object plain 2,0,0:make mesh from object 2,2
delete object 2 `not sure how that got so complex, tee-hee!...
MaxDomino=2000:dim Moving(MaxDomino):Moving(1)=1
make object 1,1,0:color object 1,rgb(255,100+rnd(100),100)
for d=2 to MaxDomino
if rnd(10)=1 then Bias#=(rnd(100)*.1)-(rnd(100)*.1)
make object d,1,0:color object d,rgb(rnd(60),100+rnd(100),100)
position object d,object position x(d-1),object position y(d-1),object position z(d-1)
rotate object d,0,object angle y(d-1),0
move object d,1.5:rotate object d,object angle x(d-1),object angle y(d-1)+Bias#,object angle z(d-1)
NEXT
`make sky
Sky=(MaxDomino*2)+1
make object sphere Sky,-5000,5,5
convert object fvf Sky,338
lock vertexdata for limb Sky,0
Vcount=get vertexdata vertex count()
for v=1 to Vcount
xx#=get vertexdata position x(v)*100
yy#=get vertexdata position y(v)*100
zz#=get vertexdata position z(v)*100
randomize xx#+yy#+zz#
set vertexdata diffuse v,rgb(200+rnd(55),200+rnd(55),255)
NEXT
unlock vertexdata
set object light Sky,0
sync on:sync rate 25
return
GetNeighbors:
dim Neighbor(MaxDomino,3) `3 neighbors max for now
for d=1 to MaxDomino
for dd=1 to MaxDomino
if d<dd
x1#=object position x(d)
z1#=object position z(d)
x2#=object position x(dd)
z2#=object position z(dd)
dist#=abs(x1#-x2#)+abs(z1#-z2#)
if dist#<3 and Neighbor(d,2)>0 and Neighbor(d,3)=0 then Neighbor(d,3)=dd `BA
if dist#<3 and Neighbor(d,1)>0 and Neighbor(d,2)=0 then Neighbor(d,2)=dd `DA
if dist#<3 and Neighbor(d,1)=0 then Neighbor(d,1)=dd `BOOM!
ENDIF
NEXT
NEXT
return
MovePieces:
for d=1 to MaxDomino
Goal=0:if Moving(d)=1 then if d=MaxDomino then Goal=90 else Goal=80
if object angle x(d)<Goal then xrotate object d,object angle x(d)+11
if object angle x(d)>Goal then xrotate object d,Goal
if object angle x(d)>40
if Neighbor(d,1)>0 then Moving(Neighbor(d,1))=1
if Neighbor(d,2)>0 then Moving(Neighbor(d,2))=1
if Neighbor(d,3)>0 then Moving(Neighbor(d,3))=1
ENDIF
next
return
Reset:
position camera 0,5,-10:rotate camera 0,0,0
rotate object 1,0,0,0:position object 1,0,0,0
Neighbor(1,1)=0:Neighbor(1,2)=0:Neighbor(1,3)=0
for d=2 to MaxDomino
xrotate object d,0:Neighbor(d,1)=0:Neighbor(d,2)=0:Neighbor(d,3)=0
Moving(d)=0:if rnd(10)=1 then Bias#=(rnd(100)*.1)-(rnd(100)*.1)
position object d,object position x(d-1),object position y(d-1),object position z(d-1)
rotate object d,0,object angle y(d-1),0
move object d,1.5:rotate object d,0,object angle y(d-1)+Bias#,0
NEXT
return