        REM POSXY
        REM This 'droid displays its position on the
        REM bottom left hand corner of the screen.

    100 xvel=0: yvel=0 : rem stop droid
        gosub 200      : rem display position

        rem calculate random new speed
        rem NB: the random(n) function returns a random
        rem     number between 0 and n-1 inclusive.
        xspeed=random(200)-100:yspeed=random(200)-100
        if xpos<100 then xspeed= abs(xspeed) : rem make speed +ve
        if xpos>400 then xspeed=-abs(xspeed) : rem make speed -ve
        if ypos<100 then yspeed= abs(yspeed) : rem make speed +ve
        if ypos>40  then yspeed=-abs(yspeed) : rem make speed -ve
        xvel=xspeed: yvel=yspeed : rem move the droid
        gosub 300 : rem Give time for droid to move
        goto 100


        REM  DISPLAY COORDINATES OF DROID
    200 locate 20,64: print "xpos=";xpos;"    "
        locate 21,64: print "ypos=";ypos;"    "
        return

    300 for i = 1 to 10:next:return
