MouseChaser3

Contest: Mouse Chaser
For Contest Description, see Mouse Chaser

code format="vbnet" 'You can mess with the variables that have comments after them. nomainwin WindowWidth=500 WindowHeight=500 obX=250 obY=250 numberChasers=10 'This changes the number of things chasing you moveCo=.04 'The things will move faster if this number is greater. Above about .1, 'they will catch your mouse almost immediately. Don't make it negative or they will 'run away and leave the screen! moveFrict=.4 'If this number is lower, they will have less inertia. If it is higher, 'they will have more. If it's above 1, they will actually accelerate, and if it's negative 'the inertia will constantly reverse itself. Negative inertia is very strange! gravity=1 'Obviously, this is gravity. frameDelay=10 dim chasing(numberChasers-1, 4) open "Mouse Chaser" for graphics as #a print #a, "home; down; trapclose [quit]"
 * Entry #3: Sir David**

[main] print #a, "when mouseMove [next]" timer 10, [next] wait

[next] frame=frame+1 if frame/frameDelay=int(frame/frameDelay) then chasers=chasers+1 if chasers>numberChasers-1 then chasers=numberChasers-1 goto[skip] end if       chasing(chasers, 1)=250 chasing(chasers, 2)=250 end if

[skip] print #a, "fill white" timer 0 curXIn=curXIn*moveFrict curYIn=curYIn*moveFrict xChan=(MouseX-obX)*moveCo+curXIn yChan=(MouseY-obY)*moveCo+curYIn angle=getAng(MouseX-obX, MouseY-obY) oldX=obX oldY=obY obX=obX+xChan obY=obY+yChan curXIn=curXIn+obX-oldX curYIn=curYIn+obY-oldY+gravity*1.5 call drawOb obX, obY, angle for i=1 to chasers curXInc=chasing(i, 3)*moveFrict curYInc=chasing(i, 4)*moveFrict if i>1 then xChang=(chasing(i-1, 1)-chasing(i, 1))*moveCo+curXInc yChang=(chasing(i-1, 2)-chasing(i, 2))*moveCo+curYInc end if       if i=1 then xChang=(obX-chasing(i, 1))*moveCo+curXInc yChang=(obY-chasing(i, 2))*moveCo+curYInc end if       angle=getAng((xChang-curXInc)/moveCo, (yChang-curYInc)/moveCo) oldX=chasing(i, 1) oldY=chasing(i, 2) chasing(i, 1)=chasing(i, 1)+xChang chasing(i, 2)=chasing(i, 2)+yChang chasing(i, 3)=curXInc+chasing(i, 1)-oldX chasing(i, 4)=curYInc+chasing(i, 2)-oldY+gravity*1.5 call drawOb chasing(i, 1), chasing(i, 2), angle next goto[main]

[quit] close #a end

function getAng(xChan, yChan) if xChan>0 and yChan>0 then getAng=180-atn(xChan/yChan)*57.29577951 end if   if xChan<0 and yChan>0 then getAng=180+atn(abs(xChan)/yChan)*57.29577951 end if   if xChan>0 and yChan<0 then getAng=atn(xChan/abs(yChan))*57.29577951 end if   if xChan<0 and yChan<0 then getAng=360-atn(abs(xChan)/abs(yChan))*57.29577951 end if   if xChan<0 and yChan=0 then getAng=270 if xChan>0 and yChan=0 then getAng=90 if xChan=0 and yChan>0 then getAng=180 end function

sub drawOb xpos, ypos, rot print #a, "north" print #a, "place ";xpos;" ";ypos;"; turn ";rot print #a, "turn 160; go 6; posxy urx ury; go 14; posxy lrx lry; turn 180" print #a, "go 20; turn 220; go 6; posxy ulx uly; go 14; posxy llx lly" print #a, "turn 160; down; color black; line ";xpos;" ";ypos;" ";llx;" ";lly print #a, "line ";xpos;" ";ypos;" ";lrx;" ";lry print #a, "line ";urx;" ";ury;" ";llx;" ";lly;"; line ";ulx;" ";uly;" ";lrx;" ";lry print #a, "turn ";360-rot end sub code