SHARE
TWEET

Water Currents

a guest Aug 28th, 2019 30 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===============================================================================
  2. # Terrain tags (initializes current terrain tags and adds water properties)
  3. #===============================================================================
  4. module PBTerrain
  5.   CurrentNorth    = 17
  6.   CurrentEast     = 18
  7.   CurrentSouth    = 19
  8.   CurrentWest     = 20
  9. end
  10.  
  11.   def PBTerrain.isSurfable?(tag)
  12.     return PBTerrain.isWater?(tag)
  13.   end
  14.  
  15.   def PBTerrain.isWater?(tag)
  16.     return tag==PBTerrain::Water ||
  17.            tag==PBTerrain::StillWater ||
  18.            tag==PBTerrain::DeepWater ||
  19.            tag==PBTerrain::WaterfallCrest ||
  20.            tag==PBTerrain::Waterfall ||
  21.            tag==PBTerrain::CurrentNorth ||
  22.            tag==PBTerrain::CurrentEast ||
  23.            tag==PBTerrain::CurrentSouth ||
  24.            tag==PBTerrain::CurrentWest
  25.            
  26.   end
  27.  
  28.   def PBTerrain.isPassableWater?(tag)
  29.     return tag==PBTerrain::Water ||
  30.            tag==PBTerrain::StillWater ||
  31.            tag==PBTerrain::DeepWater ||
  32.            tag==PBTerrain::WaterfallCrest ||
  33.            tag==PBTerrain::CurrentNorth ||
  34.            tag==PBTerrain::CurrentEast ||
  35.            tag==PBTerrain::CurrentSouth ||
  36.            tag==PBTerrain::CurrentWest
  37.   end
  38.  
  39.   def PBTerrain.isJustWater?(tag)
  40.     return tag==PBTerrain::Water ||
  41.            tag==PBTerrain::StillWater ||
  42.            tag==PBTerrain::DeepWater ||
  43.            tag==PBTerrain::CurrentNorth ||
  44.            tag==PBTerrain::CurrentEast ||
  45.            tag==PBTerrain::CurrentSouth ||
  46.            tag==PBTerrain::CurrentWest            
  47.          end
  48.  
  49.   def PBTerrain.isCurrent?(tag)
  50.     return tag==PBTerrain::CurrentNorth ||
  51.            tag==PBTerrain::CurrentEast ||
  52.            tag==PBTerrain::CurrentSouth ||
  53.            tag==PBTerrain::CurrentWest            
  54.          end        
  55.          
  56. #===============================================================================
  57. # Terrain tags (initializes current terrain tags and adds water properties)
  58. #===============================================================================
  59.  
  60. class PokemonEncounters
  61.   def isEncounterPossibleHere?
  62.     if PBTerrain.isCurrent?(pbGetTerrainTag($game_player))
  63.       return false    
  64.     elsif $PokemonGlobal && $PokemonGlobal.surfing
  65.       return true
  66.     elsif PBTerrain.isIce?(pbGetTerrainTag($game_player))
  67.       return false
  68.     elsif self.isCave?
  69.       return true
  70.     elsif self.isGrass?
  71.       return PBTerrain.isGrass?($game_map.terrain_tag($game_player.x,$game_player.y))
  72.     end
  73.     return false
  74.   end
  75. end  
  76.  
  77. #===============================================================================
  78. # Current Movement
  79. #===============================================================================
  80. def Kernel.pbWaterCurrent(event=nil)
  81.   event=$game_player if !event
  82.   return if !event
  83.   return if (pbGetTerrainTag(event)!=PBTerrain::CurrentSouth &&
  84.   pbGetTerrainTag(event)!=PBTerrain::CurrentWest && pbGetTerrainTag(event)!=PBTerrain::CurrentEast &&
  85.   pbGetTerrainTag(event)!=PBTerrain::CurrentNorth)
  86.   $PokemonGlobal.sliding=true
  87.   oldwalkanime=event.walk_anime
  88.   event.straighten
  89.   event.pattern=0
  90.   event.walk_anime=false
  91.   loop do
  92.     case pbGetTerrainTag(event)
  93.       when PBTerrain::CurrentSouth
  94.         direction=2
  95.       when PBTerrain::CurrentWest
  96.         direction=4
  97.       when PBTerrain::CurrentEast
  98.         direction=6
  99.       when PBTerrain::CurrentNorth
  100.         direction=8
  101.     end        
  102.     break if (pbGetTerrainTag(event)!=PBTerrain::CurrentSouth && pbGetTerrainTag(event)!=PBTerrain::CurrentWest &&
  103.     pbGetTerrainTag(event)!=PBTerrain::CurrentEast && pbGetTerrainTag(event)!=PBTerrain::CurrentNorth)
  104.     break if !event.passable?(event.x,event.y,direction)
  105.     case pbGetTerrainTag(event)
  106.       when PBTerrain::CurrentSouth
  107.         event.move_down(false)
  108.       when PBTerrain::CurrentWest
  109.         event.move_left(false)
  110.       when PBTerrain::CurrentEast
  111.         event.move_right(false)
  112.       when PBTerrain::CurrentNorth
  113.         event.move_up(false)
  114.     end      
  115.     while event.moving?
  116.       Graphics.update
  117.       Input.update
  118.       pbUpdateSceneMap
  119.     end
  120.   end
  121.   event.center(event.x,event.y) if event==$game_player
  122.   event.straighten
  123.   event.walk_anime=oldwalkanime
  124.   $PokemonGlobal.sliding=false
  125. end
  126.  
  127. Events.onStepTakenFieldMovement+=proc{|sender,e|
  128.   event=e[0] # Get the event affected by field movement
  129.   currentTag=pbGetTerrainTag(event)
  130.   if pbGetTerrainTag(event,true)==PBTerrain::Grass  # Won't show if under bridge
  131.     $scene.spriteset.addUserAnimation(GRASS_ANIMATION_ID,event.x,event.y,true)
  132.   elsif event==$game_player && currentTag==PBTerrain::WaterfallCrest
  133.      # Descend waterfall, but only if this event is the player
  134.     Kernel.pbDescendWaterfall(event)
  135.   elsif (currentTag==PBTerrain::CurrentSouth || currentTag==PBTerrain::CurrentWest ||
  136.     currentTag==PBTerrain::CurrentEast || currentTag==PBTerrain::CurrentNorth) && !$PokemonGlobal.sliding
  137.     Kernel.pbWaterCurrent(event)    
  138.   elsif currentTag==PBTerrain::Ice && !$PokemonGlobal.sliding
  139.     Kernel.pbSlideOnIce(event)
  140.   end
  141. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top