neonblack

Large Sprite ☆ Display Fix v1.2a - Seita version

Aug 18th, 2013
113
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##-----------------------------------------------------------------------------
  2. #  Large Sprite ☆ Display Fix v1.2b
  3. #  Created by Neon Black at request of seita
  4. #  v1.2 - 8.23.13 - Fixed a few slight positioning issues
  5. #  v1.1 - 8.18.13 - Fixed an odd lag issue
  6. #  v1.0 - 8.17.13 - Main script completed
  7. #  Only for non-commercial use.  See full terms of use and contact info at:
  8. #  http://cphouseset.wordpress.com/liscense-and-terms-of-use/
  9. ##-----------------------------------------------------------------------------
  10.  
  11. ##------
  12. ## By default, this script only affects the player.  To allow it to affect
  13. ## an event page as well, add a comment with the tag <large sprite> to the page
  14. ## of the event you would like to have affected by this.
  15.  
  16. class Sprite_Character < Sprite_Base
  17.   ##------
  18.   ## The ID of the terrain used to display the large character above ☆ tiles.
  19.   ## If the player is below this tile (y position), the sprite will appear
  20.   ## above all tiles and events from that y position up.  If the player is on
  21.   ## the same tile or above (y position) the event will appear BELOW ☆ tiles
  22.   ## from that position up.
  23.   ##------
  24.   UpperTerrain = 7
  25.  
  26.   ## Alias the update method to add in the new graphic check.
  27.   alias :cp_073013_update_pos :update_position
  28.   def update_position(*args)
  29.     cp_073013_update_pos(*args)
  30.     check_encompassed_area if sprite_is_onscreen?
  31.   end
  32.  
  33.   ## Alias the dispose to dispose the upper sprite.
  34.   alias :cp_073013_dispose :dispose
  35.   def dispose(*args)
  36.     @upper_area_sprite.dispose if @upper_area_sprite
  37.     cp_073013_dispose(*args)
  38.   end
  39.  
  40.   ## Alias the graphic changed method to allow the sprite to revent to what it
  41.   ## was during the last frame.  This allows the check to work again.
  42.   alias :cp_073013_graphic_changed? :graphic_changed?
  43.   def graphic_changed?(*args)
  44.     cp_073013_graphic_changed?(*args) || @set_upper_area_sprite
  45.   end
  46.  
  47.   ## Check if the sprite is onscreen.  Reduces redundant drawing.
  48.   def sprite_is_onscreen?
  49.     return false if @character.is_a?(Game_Vehicle) || @character.is_a?(Game_Follower)
  50.     return false unless @character.is_a?(Game_Player) || @character.large_sprite
  51.     return false if @character.screen_z >= 200
  52.     top_left, bot_right = get_edge_corner_dis
  53.     return false if top_left[0] > Graphics.width
  54.     return false if top_left[1] > Graphics.height
  55.     return false if bot_right[0] < 0
  56.     return false if bot_right[1] < 0
  57.     return true
  58.   end
  59.  
  60.   ## Get the top left and bottom right positions.
  61.   def get_edge_corner_dis
  62.     top_left = [self.x - self.ox, self.y - self.oy]
  63.     bot_right = [top_left[0] + self.width, top_left[1] + self.height]
  64.     return [top_left, bot_right]
  65.   end
  66.  
  67.   ## Long method that checks each position and draws the upper sprite.
  68.   def check_encompassed_area
  69.     @set_upper_area_sprite = false
  70.     top_left, bot_right = get_edge_corner_dis
  71.     last_x, last_y, copy_region = nil, nil, 0
  72.     map_xd, map_yd = $game_map.display_x * 32, $game_map.display_y * 32
  73.     ##total_height = (self.height + @character.jump_height).round
  74.     total_height = (self.oy).round
  75.     self.width.times do |x|
  76.       xp = map_xd.to_i + top_left[0] + x
  77.       unless xp / 32 == last_x
  78.         last_x = xp / 32
  79.         last_y, copy_region = nil, 0
  80.         total_height.times do |y|
  81.           yp = map_yd.to_i + bot_right[1] + @character.jump_height - y
  82.           next if yp.to_i / 32 == last_y
  83.           last_y = yp.to_i / 32
  84.           if last_y == (@character.screen_y + map_yd).to_i / 32
  85. #~           if last_y == (@character.screen_y + @character.jump_height +
  86. #~              map_yd).to_i / 32
  87.             break if $game_map.terrain_tag(last_x, last_y) == UpperTerrain
  88.             next
  89.           end
  90.           next if $game_map.terrain_tag(last_x, last_y) != UpperTerrain
  91.           copy_region = [self.height, total_height - y + 1].min
  92.           set_upper_sprite
  93.           break
  94.         end
  95.       end
  96.       next if copy_region == 0
  97.       rect = Rect.new(src_rect.x + x, src_rect.y, 1, copy_region)
  98.       @upper_area_sprite.bitmap.blt(x, 0, self.bitmap, rect)
  99.       self.bitmap.clear_rect(rect)
  100.     end
  101.     if !@set_upper_area_sprite && @upper_area_sprite
  102.       @upper_area_sprite.visible = false
  103.     end
  104.   end
  105.  
  106.   ## Creates the upper sprite that's a copy of the current sprite.
  107.   def set_upper_sprite
  108.     return if @set_upper_area_sprite
  109.     @upper_area_sprite ||= Sprite.new
  110.     @upper_area_sprite.bitmap = Bitmap.new(self.width, self.height)
  111.     props = ["x", "y", "ox", "oy", "zoom_x", "zoom_y", "angle", "mirror",
  112.              "bush_depth", "opacity", "blend_type", "color", "tone", "visible",
  113.              "viewport"]
  114.     props.each do |meth|
  115.       @upper_area_sprite.method("#{meth}=").call(self.method(meth).call)
  116.     end
  117. #~     @upper_area_sprite.x = @upper_area_sprite.y = 100
  118.     @upper_area_sprite.z = 200
  119.     @upper_area_sprite.viewport = @viewport1
  120.     @set_upper_area_sprite = true
  121.     old_bitmap, old_src_rect = self.bitmap, self.src_rect.clone
  122.     self.bitmap = Bitmap.new(old_bitmap.width, old_bitmap.height)
  123.     self.bitmap.blt(0, 0, old_bitmap, old_bitmap.rect)
  124.     self.src_rect = old_src_rect
  125.   end
  126. end
  127.  
  128. class Game_Event < Game_Character
  129.   attr_reader :large_sprite
  130.  
  131.   alias :cp_081713_setup_page_settings :setup_page_settings
  132.   def setup_page_settings(*args)
  133.     cp_081713_setup_page_settings(*args)
  134.     get_large_sprite_conditions
  135.   end
  136.  
  137.   def get_large_sprite_conditions
  138.     @large_sprite = false
  139.     return if @list.nil? || @list.empty?
  140.     @list.each do |line|
  141.       next unless line.code == 108 || line.code == 408
  142.       case line.parameters[0]
  143.       when /<large sprite>/i
  144.         @large_sprite = true
  145.       end
  146.     end
  147.   end
  148. end
RAW Paste Data