<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>


COINC Search:

In Graphics Words in TurboForth Kernal

Word Name: COINC
Type: Standard word
Data Stack Signature: tolerance sprite1 sprite2 -- flag
Return Stack Signature: --
Availability: V1.2
Description:

Checks for coincidence between sprite1 and sprite2. If both the horizontal and vertical difference between the two sprites is >= to tolerance then the sprites are not in coincidence with each other and flag shall be false, otherwise it shall be true.

Example:

50 value sx   60 value sy   0 value out   0 value hit?

: square ( -- )
  \ define a square block for sprite pattern #0
  data 4 $ffff $ffff $ffff $ffff 256 dchar ;

: ds ( -- )
  \ display sprites
  2 magnify
  0 50 50 0 3 sprite
  1 50 60 0 6 sprite ;

: movespr ( -- )
    \ use joystick to move sprites. Fire to exit.
    1 gmode  square  ds 
    false to out
    begin
        0 joyst case
             1 of true to out endof
             2 of -1 +to sx endof
             4 of  1 +to sx endof
             8 of  1 +to sy endof
            16 of -1 +to sy endof
        endcase
        1 sy sx sprloc
        8 0 1 coinc dup hit? = if
            \ collision state hasn't changed. don't update display
            drop
        else
            \ collision state has changed; update display
            dup to hit?
            0 0 gotoxy .
        then
    out until ;

Comment:

Introduced in TurboForth V1.2.1:4 (September 2015)

Note: Because checking for sprite coincidence is quite expensive, COINC first tests the VDP sprite collision bit. If the hardware says two sprites are in collision then the test proceeds to see if the nominated sprites are in collision with reference to the tolerance. If the hardware reports no collision then the test does not proceed any further. Distance measuring for tolerance calculation starts at the top left of the sprites.

See Also: SPRITE  SPRLOC  SPRLOC?  SPRMOV 

<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>