Advertisement
neutale

OneEyedEagle - Overhead Icon

Nov 28th, 2020
1,695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.74 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Overhead Icon by OneEyedEagle (http://oneeyedeagle.lofter.com/)
  3. # License - MIT License: http://opensource.org/licenses/mit-license.php
  4. #==============================================================================
  5. # - 2020.10.23.0 New variable added
  6. #==============================================================================
  7. # - Adds the ability to show icon above the character's head on the map.
  8. #--------------------------------------------------------------------------
  9. # - In RGSS3, you can use value on @balloon_id variable for Game_CharacterBase class.
  10. #   Which is use to show dynamic balloon above the character's head on map.
  11. # - Adds @pop_icon variable to the Game_Character class.
  12. #   Assign a value to variable that shows icon above the character for certain time.
  13. #   And a new @pop_icon_type variable has been added to specify types of motion.
  14. # - Example:
  15. #    $game_player.pop_icon = 1
  16. #      → Display is icon index 1, above player's head for MAX_SHOW_FRAME.
  17. #   If set to 0, the icon is removed.
  18. #==============================================================================
  19. module POP_ICON
  20.   #--------------------------------------------------------------------------
  21.   # ● 【Constant】 Icon isn't shown when this switch for serial ID is on.
  22.   #--------------------------------------------------------------------------
  23.   S_ID_NO_POP = 1
  24.   #--------------------------------------------------------------------------
  25.   # ● 【Constant】 Maximum number of frames to be shown after one activation.
  26.   #  If set to nil, it will not disappear.
  27.   #--------------------------------------------------------------------------
  28.   MAX_SHOW_FRAME = 30
  29.   #--------------------------------------------------------------------------
  30.   # ● 【Constant】 Maximum number of loop frames
  31.   #--------------------------------------------------------------------------
  32.   MAX_LOOP_FRAME = 60
  33.   #--------------------------------------------------------------------------
  34.   # ● Loop of frame number.
  35.   #  frame set value of 0 ~ MAX_LOOP_FRAME-1
  36.   #--------------------------------------------------------------------------
  37.   def self.draw_pop_icon(sprite_chara, sprite_icon, icon_id, frame, move_type)
  38.     # Set icon position
  39.     sprite_icon.x = sprite_chara.x
  40.     sprite_icon.y = sprite_chara.y - sprite_chara.height
  41.     sprite_icon.z = sprite_chara.z + 200
  42.  
  43.     # On first frame, creates a new bitmap to draw an icon.
  44.     if frame == 0
  45.       sprite_icon.visible = true
  46.       sprite_icon.bitmap ||= Bitmap.new(24, 24)
  47.       sprite_icon.bitmap.clear
  48.       sprite_icon.ox = 12
  49.       sprite_icon.oy = 24
  50.       draw_icon(sprite_icon.bitmap, icon_id, 0, 0)
  51.       sprite_icon.opacity = 255
  52.     end
  53.  
  54.     if move_type == 0
  55.     elsif move_type == 1
  56.       sprite_icon.y = sprite_chara.y - sprite_chara.height / 2
  57.     end
  58.  
  59.     case frame
  60.     when 1..29
  61.       sprite_icon.opacity -= 6
  62.       sprite_icon.y += (frame/4)
  63.     when 30..59
  64.       sprite_icon.opacity += 6
  65.       sprite_icon.y += ((29-(frame-29))/4)
  66.     end
  67.  
  68.   end
  69.   #--------------------------------------------------------------------------
  70.   # ● Draw icon
  71.   #     enabled : If false, transparent effect.
  72.   #--------------------------------------------------------------------------
  73.   def self.draw_icon(bitmap, icon_index, x, y, enabled = true)
  74.     bitmap_ = Cache.system("Iconset")
  75.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  76.     bitmap.blt(x, y, bitmap_, rect, enabled ? 255 : 120)
  77.   end
  78. end
  79. #=============================================================================
  80. # ○ Game_Character
  81. #=============================================================================
  82. class Game_Character
  83.   attr_accessor :pop_icon, :pop_icon_type
  84.   #--------------------------------------------------------------------------
  85.   # ● Initialize pop icon
  86.   #--------------------------------------------------------------------------
  87.   alias eagle_popicon_init initialize
  88.   def initialize
  89.     @pop_icon = 0
  90.     @pop_icon_type = 0
  91.     eagle_popicon_init
  92.   end
  93. end
  94. #=============================================================================
  95. # ○ Sprite_Character
  96. #=============================================================================
  97. class Sprite_Character < Sprite_Base
  98.   #--------------------------------------------------------------------------
  99.   # ● Pop icon remove
  100.   #--------------------------------------------------------------------------
  101.   alias eagle_popicon_dispose dispose
  102.   def dispose
  103.     eagle_popicon_dispose
  104.     if @popicon_sprite
  105.       @popicon_sprite.bitmap.dispose if @popicon_sprite.bitmap
  106.       @popicon_sprite.dispose
  107.     end
  108.   end
  109.   #--------------------------------------------------------------------------
  110.   # ● Pop icon alias
  111.   #--------------------------------------------------------------------------
  112.   alias eagle_popicon_update update
  113.   def update
  114.     eagle_popicon_update
  115.     update_popicon
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   # ● Update pop icon
  119.   #--------------------------------------------------------------------------
  120.   def update_popicon
  121.     if $game_switches[POP_ICON::S_ID_NO_POP]
  122.       end_popicon if @pop_icon != 0
  123.       return
  124.     end
  125.     reset_popicon if @popicon_sprite.nil?
  126.     flag_continue_show = false
  127.     if @character.pop_icon > 0
  128.       if @character.pop_icon == @pop_icon # If matches the display
  129.         @character.pop_icon = -1
  130.         flag_continue_show = true
  131.       else
  132.         reset_popicon
  133.       end
  134.     else
  135.       return end_popicon if @character.pop_icon == 0
  136.     end
  137.     if @pop_icon > 0
  138.       if !flag_continue_show && POP_ICON::MAX_SHOW_FRAME &&
  139.          @popicon_count > POP_ICON::MAX_SHOW_FRAME
  140.         return end_popicon
  141.       end
  142.       c = @popicon_count % POP_ICON::MAX_LOOP_FRAME
  143.       POP_ICON.draw_pop_icon(self, @popicon_sprite, @pop_icon, c,
  144.         @character.pop_icon_type)
  145.       @popicon_sprite.update
  146.       @popicon_count += 1
  147.     end
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # ● Reset pop icon
  151.   #--------------------------------------------------------------------------
  152.   def reset_popicon
  153.     @pop_icon = @character.pop_icon
  154.     @character.pop_icon = -1 # When shown, set it to -1.
  155.     @popicon_sprite ||= Sprite.new(viewport)
  156.     @popicon_count = 0
  157.   end
  158.   #--------------------------------------------------------------------------
  159.   # ● End pop icon
  160.   #--------------------------------------------------------------------------
  161.   def end_popicon
  162.     @popicon_sprite.visible = false if @popicon_sprite
  163.     @pop_icon = 0
  164.     @character.pop_icon = 0
  165.   end
  166. end
  167.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement