CircleHitShape
State = CircleHitShape(X#, Y#, Radius, ShapeIndex, ShapeX#, ShapeY#)
 
Parameters:

    X# = The X coordinate of the test circle
    Y# = The Y coordinate of the test circle
    Radius = The raidus of the test circle
    ShapeIndex = The index of the shape you wish to test
    ShapeX# = The base X position of the test shape
    ShapeY# = The base Y position of the test shape
Returns:

    State = The hit state of the circle (0 = outside of shape, 1 = intersects shape)
 

      The CircleHitShape function checks if a circle is inside, or intersects a vector shape. It will return a true (1) when it intersects, or a false(0) when it does not.




FACTS:


      * None



Mini Tutorial:


      This example checks if a circle positioned at the mouse pointer position, hits a moving shape.

  
; limit the Speed of the demo to 100(or less) frames per second
  SetFPS 100
  
  
; Create a convert shape to check collisions against
  MyShape=NewConvexShape(50,7)
  
; Init some variables to hold our shapes position
  ShapeX#=100
  ShapeY#=100
  
; Randomly init the test circle radius
  radius#=RndRange(20,50)
  
; Start a Do/Loop
  Do
   ; Clear the sreen
     Cls RGB(0,0,0)
     
   ; Display a message
     Print "Testing Circle To Shape Collision"
     
   ; Rotate our test shape
     RotateShape MyShape,Angle#,1
     
   ; Bump the Rotation angle
     Angle#=WrapAngle(angle#,1)
     
   ; Move and clip the Shapes position
     Shapex#=Mod(Shapex#+1,GetScreenWidth())
     
   ; Read the mouse pointers position
     x#=MouseX()
     y#=MouseY()
     
   ; If the right mouse button is pressed
   ; Then change the test circles radius
     If RightMouseButton()
        radius#=RndRange(20,100)
     EndIf
     
     CircleC x#,y#,Radius#,1,RGB(100,100,100)
     
     
   ; Check if a Circle hits the shape
     If CircleHitShape(x#,y#,Radius#,MyShape,Shapex#,Shapey#)=true
        
      ; Set the pen's ink colour to yellow
        Ink RGB(255,255,0)
        
      ; display a message
        Print "Circle Hit Shape"
        
      ; set the ink colour to RED
        Ink RGB(255,0,0)
     Else
        
      ; If the Circle didn't hit the shape, then
      ; Set then ink colour to White
        Ink RGB(255,255,255)
     EndIf
     
   ; Draw the filled shape
     DrawShape MyShape,ShapeX#,ShapeY#,2
     
   ; Display the screen
     Sync
     
   ; loop back to the do
  Loop
  



      Sample output,






 
Related Info: BoxHitShape | LineHitShape | PointHitShape | ShapeHitShape :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com