GetMapImpactBot
State = GetMapImpactBot()
 
Parameters: NONE
Returns:

    State = The state of the impact upon this side
 

      The GetMapImpactBot function returns if the last map impact was on the BOTTOM side of the test region.



FACTS:


     * None



Mini Tutorial:


      This example builds map, and level. The primary focus of this example is the detection of collisions of moving region and the level.


  
; Create a map with provision for 5 levels
  MyMap=NewMap(5)
  
; Create some blank blocks for this map
  CreateMapGFX MyMap,25,25,2,RGB(0,0,0)
  BoxC 0,0,30,30,1,RGB(255,0,200)
  GetMapBlk MyMap,1,0,0
  
  
; create the level
  MyLevel=NewLevel(Mymap, 25,20)
  
  w=GetLevelWidth(MyMap,MyLevel)
  h=GetLevelHeight(MyMap,MyLevel)
  
; Fill the Level edges with blocks
  For Xlp=0 To GetLevelWidth(MyMap,mylevel)
     PokeLevelTile Mymap,MyLevel,xlp,0,1
     PokeLevelTile Mymap,MyLevel,xlp,h,1
  Next
  
  For Ylp=0 To GetLevelHeight(MyMap,mylevel)
     PokeLevelTile Mymap,MyLevel,0,ylp,1
     PokeLevelTile Mymap,MyLevel,w,ylp,1
  Next
  
; Draw a strip of blocks across the middle
; of the page
  For Xlp=3 To GetLevelWidth(MyMap,mylevel)-3
     PokeLevelTile Mymap,MyLevel,xlp,h/2,1
  Next
  
  
; Define some variables for a PLayer
  
  PlayerX=50
  PlayerY=50
  
  PlayerWidth     =20
  PlayerHeight     =20
  
  Speed=4
  
; Start a Do / Loop
  Do
   ; Clear the screen
     Cls RGB(0,0,0)
     
   ; Draw the map to the screen
     DrawMap MyMap,MyLevel,0,0
     
   ; Store the players possible new position
     PlayerNewX=PlayerX
     PlayerNewY=PlayerY
     
   ; Handle the players Movement
     If UpKey() Then PlayerNewY=PLayerY-Speed
     If DownKey() Then PlayerNewY=PLayerY+Speed
     If LeftKey() Then PlayerNewX=PLayerX-Speed
     If RightKey() Then PlayerNewX=PLayerX+Speed
     
   ; ==========================
   ; Handle Collision
   ; ===========================
     
     If CheckMapImpact(MyMap,MyLevel,PlayerX,playerY,PlayerNewX,PlayerNewY,PLayerWidth,PlayerHeight)
      ; If there was impact with the map, then read our
      ; new position back.
        PlayerX=GetMapImpactX()
        PlayerY=GetMapImpactY()
        
      ; Check what side the impact occured upon
      ; and display a message
        
        If GetMapImpactLeft()
           Print "Impact occured on the LEFT side"
        EndIf
        
        If GetMapImpactRight()
           Print "Impact occured on the RIGHT side"
        EndIf
        
        If GetMapImpactTop()
           Print "Impact occured on the TOP side"
        EndIf
        
        If GetMapImpactBot()
           Print "Impact occured on the Bottom side"
        EndIf
     Else
      ; No Collision, Then set the current players
      ; position to it's new position
        PlayerX=PlayerNewX
        PlayerY=PlayerNewY
     EndIf
     
     
   ; draw the player (box) to the  screen
     X2=playerX+PlayerWidth
     Y2=playerY+PlayerHeight
     Box playerX,playerY,x2,y2,1
     
   ; Display the screen
     Sync
   ; Loop back to the do statement
  Loop
  



This example would output.

  
  no Text Output
  

 
Related Info: CheckMapImpact | GetMapImpactLeft | GetMapImpactRight | GetMapImpactTop | GetMapImpactX | GetMapImpactY :
 


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