Advertisement
TechSkylander1518

Better Barriers

Sep 25th, 2021
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.69 KB | None | 0 0
  1. #=============================================================================
  2. # Borders
  3. #=============================================================================
  4.  
  5. #Borders prevent the player from crossing past a point in a certain direction
  6. #Set the event to parallel process, with conditional script Border(point,"direction")
  7.  
  8. def Border(point,direction)
  9.   event=$game_map.events[@event_id]
  10.   px=$game_player.x
  11.   py=$game_player.y
  12.   if event
  13.   case direction
  14.     when "up"
  15.      if py<point
  16.         return true
  17.       end
  18.     when "right"
  19.      if px>point
  20.         return true
  21.       end
  22.     when "down"
  23.      if py>point
  24.         return true
  25.       end
  26.     when "left"
  27.      if px<point
  28.         return true
  29.       end
  30.     end
  31.   end
  32. end
  33.  
  34.  
  35. #=============================================================================
  36. # Boundaries
  37. #=============================================================================
  38.  
  39. #Boundaries require the player to stay within the limits given.
  40. #Set the event to parallel process, with conditional script Boundary(X1,X2,Y1,Y2)
  41. #            Y1
  42. #      X1   (||)      X2
  43. #            Y2
  44. #Set both Xs to 0 for only Y boundaries, and vice versa
  45.  
  46.  
  47. def Boundary(x1,x2,y1,y2)
  48.   event=$game_map.events[@event_id]
  49.   px=$game_player.x
  50.   py=$game_player.y
  51.   if event
  52.     if y1==y2
  53.       if px<x1 || px>x2
  54.         return true
  55.       else
  56.         return false
  57.       end
  58.     elsif x1==x2
  59.       if py<y1 || py>y2
  60.         return true
  61.       else
  62.         return false
  63.       end
  64.     else
  65.       if px<x1 || px>x2 ||
  66.          py<y1 || py>y2
  67.         return true
  68.       else
  69.         return false
  70.       end
  71.     end
  72.   end
  73. end
  74.  
  75. #=============================================================================
  76. # Anchors
  77. #=============================================================================
  78.  
  79. #Anchors require the player to be within a certain range of their event.
  80. #Set the event to parallel process, with a conditional script Anchor(#), with
  81. #"#" being the number of tiles away the player can be before triggering the event.
  82. #xonly will only restrict the player horizontally
  83. #yonly will only restrict the player vertically
  84.  
  85.  
  86. def Anchor(limit,xonly=false,yonly=false)
  87.   event=$game_map.events[@event_id]
  88.   if event
  89.     x=event.x
  90.     y=event.y
  91.     px=$game_player.x
  92.     py=$game_player.y
  93.     if xonly==true
  94.         if px<=(x-limit) || px>=(x+limit)
  95.           return true
  96.         end
  97.     elsif yonly==true
  98.         if py<=(y-limit) || px>=(y+limit)
  99.           return true
  100.         end
  101.     end
  102.       if px<=(x-limit) || px>=(x+limit) ||
  103.         py<=(y-limit) || py>=(y+limit)
  104.         return true
  105.       else
  106.         return false
  107.       end
  108.   end
  109. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement