/****************************************************************/ /* S A S S A M P L E L I B R A R Y */ /* */ /* NAME: WORM */ /* TITLE: ANIMATED WORM ON DISPLAY */ /* PRODUCT: IML */ /* SYSTEM: ALL */ /* KEYS: MATRIX FS */ /* PROCS: IML */ /* DATA: */ /* */ /* SUPPORT: LWB UPDATE: NOV1989 */ /* REF: */ /* MISC: */ /****************************************************************/ proc iml; /*---worm---*/ /* head @ body = food X empty . barrier / */ start worminit; window w rows=14 columns=22 icolumn=20; rowmove={0 0 1 -1}; colmove={1 -1 0 0}; nr=10; nc=20; a = repeat("X",nr,nc); /* the game field */ a[3,8:12]="/"; a[7,8:12]="/"; r = { 5 5 5 5 }; /* initial row position */ c = { 8 9 10 11}; /* initial col position */ loc=(r-1)*nc+c; a[loc]={"@" "=" "=" "="}; /* place worm in field */ * a[3,7:13]="B"; * a[7,7:13]="B"; ok = 1; finish; start wormmove; /*-clear old tail-*/ a[r[4],c[4]]='.'; a[r[1],c[1]]="="; r=r[{4 1 2 3}]; c=c[{4 1 2 3}]; /*-try new direction-*/ iii=0; tryagain: iii=iii+1; if iii>20 then do; ok=0; stop; end; move=int(uniform(0)#4)+1; r1 = r[2]+rowmove[move]; c1 = c[2]+colmove[move]; if r1<1 | r1>nr then goto tryagain; if c1<1 | c1>nc then goto tryagain; if a[r1,c1]^="X" then if a[r1,c1]^='.' then goto tryagain; freq=256; if a[r1,c1]="X" then freq=312; /*--make new move--*/ r[1] = r1; c[1] = c1; a[r1,c1]="@"; finish; freq=256; start wormshow; showa = cshape(a,nr,1,nc); display w ( / showa color="YELLOW" protect=yes ) repeat; call sound(freq,.05); finish; run worminit; start; do i=1 to 100; run wormshow; run wormmove; end; finish; /* You can ask the worm to "run" as many times as you like. */ /* The run; below will get him started. */ run;