khanhdu

Scirpt Sửa Lỗi Char

May 6th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.77 KB | None | 0 0
  1. #==============================================================================
  2. # ** Game_CharacterBase
  3. #------------------------------------------------------------------------------
  4. #  This base class handles characters. It retains basic information, such as
  5. # coordinates and graphics, shared by all characters.
  6. #==============================================================================
  7. class Game_CharacterBase
  8.   #--------------------------------------------------------------------------
  9.   # * Public Instance Variables
  10.   #--------------------------------------------------------------------------
  11.   attr_reader   :under_map_tile_z                                                               # Under Map Tile Z Flag
  12.   attr_reader   :over_map_tile_z                                                                  # Over Map Tile Z Flag
  13.   attr_accessor :character_bitmap_area                            # Character Bitmap Area
  14.   #--------------------------------------------------------------------------
  15.   # * Alias Listing & Method Definition
  16.   #--------------------------------------------------------------------------
  17.   # Alias Method List
  18.   ["init_private_members", "increase_steps", "moveto", "screen_z"].each {|name|
  19.                 # Alias Method
  20.                 alias_method :"pvgames_under_map_tile_z_game_characterbase_#{name}", name
  21.                 # Next if Methods don't need definition
  22.                 next if ["init_private_members", "screen_z"].include?(name)
  23.                 # Define Method
  24.                 define_method (name.to_sym) {|*args, &block|
  25.                   # Run Original Method
  26.                   self.send "pvgames_under_map_tile_z_game_characterbase_#{name}", *args, &block
  27.                   # Update Under Map Tile Z Flag
  28.                   update_under_map_tile_z
  29.                  }
  30.   }
  31.   #--------------------------------------------------------------------------
  32.   # * Initialize Private Member Variables
  33.   #--------------------------------------------------------------------------
  34.   def init_private_members(*args, &block)
  35.                 # Run Original Method
  36.                 pvgames_under_map_tile_z_game_characterbase_init_private_members(*args, &block)
  37.                 # Set Under/Over Map Tile Z Flag
  38.                 @under_map_tile_z = false ; @over_map_tile_z = false
  39.                 # Set Character Bitmap Area Rect
  40.                 @character_bitmap_area = Rect.new(0, 0, 1, 1)
  41.   end  
  42.   #--------------------------------------------------------------------------
  43.   # * Get Screen Z-Coordinates
  44.   #--------------------------------------------------------------------------
  45.   def screen_z(*args, &block)
  46.                 # Return 300 if Under/Over Map Tile Z is true
  47.                 return 300 if under_map_tile_z? or over_map_tile_z?
  48.                 # Run Original Method
  49.                 pvgames_under_map_tile_z_game_characterbase_screen_z(*args, &block)
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # * Opacity
  53.   #--------------------------------------------------------------------------
  54.   def opacity
  55.                 return @opacity if over_map_tile_z?
  56.                 return under_map_tile_z? ? 160 : @opacity
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # * Determine if Under Map Tile Z effect is true
  60.   #--------------------------------------------------------------------------
  61.   def under_map_tile_z? ; @under_map_tile_z end
  62.   def over_map_tile_z?  ; (!under_map_tile_z? and @over_map_tile_z) end  
  63.   #--------------------------------------------------------------------------
  64.   # * Update Under Map Tile Z Flag
  65.   #--------------------------------------------------------------------------
  66.   def update_under_map_tile_z
  67.                 # Get Character Area Bitmap Rect
  68.                 rect = @character_bitmap_area.dup
  69.                 # If Rect Width or Height is More than 32
  70.                 if rect.width >= 32 or rect.height > 32
  71.                   # Set Rect Width and Height
  72.                   rect.width = (rect.width / 32.0).round ; rect.height = (rect.height / 32.0).round
  73.                   # Set Rect X & Y
  74.                   rect.x = @x - (rect.width / 2) ; rect.y = @y - ( rect.height / 2)
  75.                   # Set Over Map Tile Z to false
  76.                   @over_map_tile_z = false
  77.                   # Multiple Loops Catch
  78.                   catch(:range) {  
  79.                                 # Go Through coordinates
  80.                                 for y in rect.y...(rect.y + rect.height)
  81.                                   for x in rect.x...(rect.x + rect.width)
  82.                                                 # If Under Map Tile
  83.                                                 if under_map_tile?(x, y)
  84.                                                   # Set Over Map Tile Z to true
  85.                                                   @over_map_tile_z = true
  86.                                                   # Break Loop
  87.                                                   throw :range
  88.                                                 end
  89.                                   end
  90.                                 end
  91.                   }
  92.                   # Go Through Bottom X
  93.                   for x in rect.x...(rect.x + rect.width)
  94.                                 # Return Under Map Tile Z as true if under map tile
  95.                                 return @under_map_tile_z = true if under_map_tile?(x, @y)
  96.                   end  
  97.                 end  
  98.                 # Set Under Map Tile Z
  99.                 @under_map_tile_z = under_map_tile?
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # * Determine if Character is under tile
  103.   #--------------------------------------------------------------------------
  104.   def under_map_tile?(x = @x, y = @y) ; $game_map.over_character_tile?(x, y) end
  105. end
  106.  
  107. #==============================================================================
  108. # ** Game_Map
  109. #------------------------------------------------------------------------------
  110. #  This class handles maps. It includes scrolling and passage determination
  111. # functions. The instance of this class is referenced by $game_map.
  112. #==============================================================================
  113.  
  114.  
  115. class Game_Map
  116.   #--------------------------------------------------------------------------
  117.   # * Determine if Tile goes over character [☆]
  118.   #--------------------------------------------------------------------------
  119.   def over_character_tile?(x, y)
  120.         # Return if Tile is default for nothing
  121.         return false if tile_id(x, y, 2) == 0
  122.         # Check if Valid tile and bit (Over Character)
  123.         # Instead of checking everything, just check layer 2. Seems like
  124.         # Layer 1 are automatically assigned for you, which may be bad
  125.         return valid?(x, y) && transparent_tile?(x, y)
  126.   end
  127.  
  128.   def transparent_tile?(x, y)
  129.         tileset.flags[tile_id(x, y, 2)] & 0x10 != 0
  130.   end
  131. end
  132.  
  133. #==============================================================================
  134. # ** Sprite_Character
  135. #------------------------------------------------------------------------------
  136. #  This sprite is used to display characters. It observes an instance of the
  137. # Game_Character class and automatically changes sprite state.
  138. #==============================================================================
  139. class Sprite_Character < Sprite_Base
  140.   #--------------------------------------------------------------------------
  141.   # * Alias Listing & Method Definition
  142.   #--------------------------------------------------------------------------
  143.   # Alias Method List
  144.   ["set_tile_bitmap", "set_character_bitmap"].each {|name|
  145.                 # Alias Method
  146.                 alias_method :"pvgames_under_map_tile_z_sprite_character_#{name}", name
  147.                 # Define Method
  148.                 define_method (name.to_sym) {|*args, &block|
  149.                   # Run Original Method
  150.                   self.send "pvgames_under_map_tile_z_sprite_character_#{name}", *args, &block
  151.                   # Update Character Bitmap Area
  152.                   update_character_bitmap_area
  153.                  }
  154.   }
  155.   #--------------------------------------------------------------------------
  156.   # * Update Character Bitmap Area
  157.   #--------------------------------------------------------------------------
  158.   def update_character_bitmap_area
  159.                 # Update Source Rect
  160.                 update_src_rect
  161.                 # Set Character Bitmap Area Rect
  162.                 @character.character_bitmap_area.set(0, 0, width, height)
  163.   end
  164. end
  165.  
  166.  
  167. #==============================================================================
  168. # ** Game_Event
  169. #------------------------------------------------------------------------------
  170. #  This class handles events. Functions include event page switching via
  171. # condition determinants and running parallel process events. Used within the
  172. # Game_Map class.
  173. #==============================================================================
  174. class Game_Event < Game_Character
  175.   #--------------------------------------------------------------------------
  176.   # * Alias Listing & Method Definition
  177.   #--------------------------------------------------------------------------
  178.   # Alias Method List
  179.   ["refresh", "clear_page_settings", "setup_page_settings"].each {|name|
  180.                 # Alias Method
  181.                 alias_method :"pvgames_under_map_tile_z_game_event_#{name}", name
  182.                 # Define Method
  183.                 define_method (name.to_sym) {|*args, &block|
  184.                   # Run Original Method
  185.                   self.send "pvgames_under_map_tile_z_game_event_#{name}", *args, &block
  186.                   # Update Under Map Tile Z Flag
  187.                   update_under_map_tile_z
  188.                  }
  189.   }
  190. end
Add Comment
Please, Sign In to add comment