BoxHitShape
State = BoxHitShape(X1#, Y1#, X2#, Y2#, ShapeIndex, ShapeX#, ShapeY#)
 
Parameters:

    X1# = The X (top left) coord of the test box
    Y1# = The Y (top left) coord of the test box
    X2# = The X (bottom right) coord of the test box
    Y2# = The Y (bottom right) coord of the test box
    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 BoxHitShape function checks if a BOX 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:


      * The box coordinates don't have to be top to bottom, BoxHitShape will swap them internally for you.



Mini Tutorial:


      This example checks if a box 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 boxes size
  BoxSize=RndRange(20,50)
  
; Start a So/Loop
  Do
   ; Clear the sreen
     Cls RGB(0,0,0)
     
   ; Display a message
     Print "Testing Box 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
     x1#=MouseX()
     y1#=MouseY()
     
   ; If the right mouse button is pressed
   ; Then change the test circles radius
     If RightMouseButton()
        BoxSize=RndRange(20,100)
     EndIf
     
   ; Calc the Bottom cords of our test box
     x2#=x1#+BoxSize
     y2#=y1#+BoxSize
     
   ; Draw the test box
     BoxC x1#,y1#,x2#,y2#,1,RGB(100,100,100)
     
     
   ; Check if a Box hits the shape
     If BoxHitShape(x1#,y1#,x2#,y2#,MyShape,Shapex#,Shapey#)=true
        
      ; Set the pen's ink colour to yellow
        Ink RGB(255,255,0)
        
      ; display a message
        Print "Box Hit Shape"
        
      ; set the ink colour to RED
        Ink RGB(255,0,0)
     Else
        
      ; If the box 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: CircleHitShape | LineHitShape | PointHitShape | ShapeHitShape :
 


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