TI99 Environment

# CALL_DISTANCE

Syntax

integer-variable = CALL_DISTANCE(sprite1,sprite2)

Description

The CALL_DISTANCE function returns the distance in pixels between sprite1 and sprite2. The number returned is computed as follows: The difference in pixels between the dot-rows of the sprites is found and squared. Then the difference in pixels between the dot-columns of the sprites is found and squared. Then the two squares are added. If the sum is larger than 32767, then 32767 is returned (181 squared). To obtain the actual distance between the sprites, use the square root function (SQRT()) on the value returned. Valid Function Values: sprite1 and sprite2 = an integer between 1 and maxsprites indicating the sprites being compared. Return values: integer-variable: distance between sprite1 and sprite2 expressed as an integer between 1 and 32,767.

Example Code

    `  Call_Distance function Test
    y1 =1 : x1 = 1 : dx1 = 1 : dy1 = 0
    y2 = 1 : x2 = 1 : dx2 = 0 : dy2 = 1
    call_sprite(1,65,16,y1,x1,0,0)
    call_sprite(2,66,14,y2,x2,0,0)
    dst AS INTEGER
    do
        display_at(24,1,"Press Key to Test Distance",0)
        dst = sqrt(CALL_DISTANCE(1,2))
        ti_printat(9,5,"SQR DISTANCE:"+str$(dst))
        tiwaitkey()
        x1 = x1 + dx1 : y1= y1 + dy1
        x2 = x2 + dx2 : y2= y2+ dy2
        call_locate(1,y1,x1)
        call_locate(2,y2,x2)
        ti_sync()
    loop

    The above program will display the distance between two sprites.
    The user can press a key on the keyboard to make the program move one sprite down and the other one to the right respectively and show the distance change.

Go back to ...

TI99E Commands Menu
Main Menu

Copyright © Carlos Santiago Lebron - TI99 Environment 2020