Somebody wrote somewhere that arrays are supposed to be easy - and as I wa struggling to get my head around them I though a bit of practice was in order. This program is meant to move a ball randomly across the screen, write all of its previous x and y positions into a 2 dimensional array, then print a series of dots (ie. a trail) at all of the positions, then repeat the process every loop as the ball moves.
Problem is, although I've got the x-component of the trail working, the y component seems to be stuck at zero - giving a trail at the top of the screen. Hmmm.......
Anybody with time to kill, could you check my code please?
Thanks!
Richard
sync on
make object sphere 1,3
position camera 0,0,-500
do
position object 1,x#,y#,0 `move ball randomly
x#=x#+1-rnd(2)
y#=y#+1-rnd(2)
dim xys#(n,2) `create array n columns by two rows
xys#(n,1)=(object screen X(1)) `put x position into 1st row and nth column
xys#(n,2)=(object screen Y(1)) `put y position into 2nd row and nth column
for d=1 to n
dx#=(xys#(d,1)) `extract x position from 1st row of array
dy#=(xys#(d,2)) `extract y position from 2nd row of array
dot dx#,dy# `put a dot at that point
next d `repeat for all previous positions of the ball
n=n+1 `move to next column of array ready for next entry
sync
loop