neonblack

Old Ruby Star Fix

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