CircleHitMapPixels
Collision = CircleHitMapPixels(ThisMap, TheLevel, CircleX, CircleY, CircleRadius)
 
Parameters:

    ThisMap = The Index of the map you query for a collision
    TheLevel = The level within the map to query
    CircleX = The X coordinate of the circle relative to the level
    CircleY = The Y coordinate of the circle relative to the level
    CircleRadius = The Radius of the circle
Returns:

    Collision = The collision state. It'll return True (1) with the circle hit something and false (0) it didn't
 

     The CircleHitMapPixels() function checks if a circle region collides (overlaps) a map level at pixel level.




FACTS:


      * CircleHitMapPixels compares the the circle region with the map at pixel level. Therefore it's not recommended for use with Video Maps, best results are obtained with FX blocks.



 
Example Source: Download This Example
;     -----------------------------------------------------
;             --------->> SET UP <<------------
;     -----------------------------------------------------
  
  
  SetFPS 100
  
  
; Radius of test circle
  Radius=100
  
  
; create the random map from some circles
  Map,Level=Build_Random_Map(32,32)
  
  
; make a backdrop picture
  BackDrop=NewImage(800,600)
  RenderToImage Backdrop
  c1=RndRGB()
  c2=RndRGB()
  ShadeBox 0,0,800,600,c1,c1,c2,c2
  RenderToScreen
  
  
; create a camera to view the scene with
  Cam=NewCamera()
  CameraCls Cam,off
  
  
  
;     -----------------------------------------------------
;        --------->> MAIN LOOP OF PROGRAM <<------------
;     -----------------------------------------------------
  
  Do
     
   ; Get the camera current position
     CamX=GetCameraX(cam)
     CamY=GetCameraY(cam)
     
   ; Get the mouse position
     MX=MouseX()+CamX
     MY=MouseY()+CamY
     
     Method$="CircleHitMap"
     If Method=0
      ; Test if the Circle Hits the Map blocks
        Collision=CircleHitMap(Map,Level,MX,MY,RAdius)
     Else
      ; Test if the Circle Hits the Map at pixel level
        Collision=CircleHitMapPixels(Map,Level,MX,MY,RAdius)
        Method$+="Pixels"
     EndIf
     
     
     If Collision
        Colour=$ff0000
        Message$="Hit"
     Else
        Colour=$0000ff
        Message$="Missed"
     EndIf
     
     
   ; tell PB to capture the following drawing commands
     CaptureToScene
     
   ; clear the scene buffer so it's empty
     ClsScene
     
   ; set the capture depth of the next item to a depth of
   ; 100 units
     CaptureDepth 100
     DrawImage BackDrop,CamX,CamY,false
     
     
   ; draw the map level
     CaptureDepth 10
     DrawMap map,Level,0,0
     
     
   ; draw the circle at this depth
     CaptureDepth 20
     CircleC MX,MY,Radius,true,colour
     
     
   ; draw the scene with this camera
     DrawCamera cam
     
     
   ; Check if the Space key was pressed
     If SpaceKey()
      ; if so, change the collision method
        Method=1-Method
        FlushKeys
     EndIf
     
   ; check if the ENTER key was pressed
     If EnterKey()
      ; If so, toggle Debug mode on the map
        MapDebug Map,1-GetMapDebug(Map)
        FlushKeys
     EndIf
     
     
   ; check if the users wanted to move the camera
     If LeftKey()  Then     MoveCamera Cam,-2,0
     If RightKey() Then     MoveCamera Cam,2,0
     If UpKey()    Then     MoveCamera Cam,0,-2
     If DownKey()  Then     MoveCamera Cam,0,2
     
     SetCursor 0,0
     Ink $ffffff
     Print "Press Space To Change Methods"
     Print "Method:"+Method$
     Print  Message$
     Sync
  Loop
  
  
;     -----------------------------------------------------
;     ------------->> Build Random Map Scene <<------------
;     -----------------------------------------------------
  
  
Function Build_Random_Map(BlockWidth,BlockHeight)
  
  
  BackdropColour=$008f00
  
  screen=NewFXImage(2400,1600)
  RenderToImage screen
  Cls  BackdropColour
  CircleC 800,400,400,true,$8f8f8f
  CircleC 1700,400,400,true,$0f8faf
  
  For lp=0 To 150
     x=Rnd(2400)
     y=Rnd(1600)
     rx=RndRange(50,150)
     ry=RndRange(10,50)
     EllipseC x,y,rx,ry,true, BackdropColour
  Next
  
  
  
  Map=NewMap(50)
  
; Create 1024 FX BLocks for this map
  CreateMapGFX  Map,BlockWidth,BlockHeight,1024,BackdropColour,2
  
  BlocksX=GetSurfaceWidth()/BlockWidth
  BlocksY=GetSurfaceHeight()/BlockWidth
  
  Level=NewLevel(Map,BlocksX,BlocksY)
  LevelTransparent Map,Level,0
  GetMapBlk Map,Tile,0,0
  
  Tile=1
  For ylp=0 To GetLevelHeight(map,level)-1
     Ypos=ylp*BlockHeight
     If Ypos+BlockHeight<=GetSurfaceHeight()
        For xlp=0 To GetLevelWidth(map,level)-1
           Xpos=xlp*BlockWidth
           GetMapBlk Map,Tile,Xpos,ypos
           
           If GetMapBlockTransparent(Map,Tile)>-1
              PokeLevelTile Map,Level,xlp,ylp,tile
              tile++
           EndIf
           If Tile=>GetMapBlocks(Map) Then ExitFor ylp
        Next
     EndIf
  Next
  
  RenderToScreen
  
; Turn Debug Map for this map
  MapDebug Map,on
  
EndFunction Map,Level
  
  
  
 
Related Info: CircleHitMap | GetMapBlockTransparent :
 


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