Advertisement
dsiver144

Character Flash

Sep 14th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.02 KB | None | 0 0
  1. =begin
  2. #===============================================================================
  3.  Title: Character Flash
  4.  Author: Tsukihime
  5.  Date: Sep 13, 2013
  6. --------------------------------------------------------------------------------
  7.  ** Change log
  8.  Sep 13, 2013
  9.    - Initial release
  10. --------------------------------------------------------------------------------  
  11.  ** Terms of Use
  12.  * Free to use in commercial/non-commercial projects
  13.  * No real support. The script is provided as-is
  14.  * Will do bug fixes, but no compatibility patches
  15.  * Features may be requested but no guarantees, especially if it is non-trivial
  16.  * Credits to Tsukihime in your project
  17.  * Preserve this header
  18. --------------------------------------------------------------------------------
  19.  ** Description
  20.  
  21.  This script allows you to have characters on your map start flashing.
  22.  You can choose how long the flash should be and the color of the flash.
  23.  
  24. --------------------------------------------------------------------------------
  25.  ** Installation
  26.  
  27.  Place this script below Materials and above Main.
  28.  
  29. --------------------------------------------------------------------------------
  30.  ** Usage
  31.  
  32.  To make a character flash, make the script call
  33.  
  34.    character_flash(id, duration)
  35.    character_flash(id, duration, loopCount)
  36.    character_flash(id, duration, loopCount, color)
  37.    
  38.  Where ID is
  39.    -1 for the player
  40.    0 for the current event
  41.    1 or higher is the specified event ID
  42.    
  43.  The duration is the number of frames that you want it to flash.
  44.  
  45.  LoopCount is a number that specifies how many times it should loop.
  46.  By default, it only loops once (1), but you can have it loop infinitely by
  47.  passing in 0.
  48.  
  49.  If the flash is supposed to loop, you will need to manually turn off the
  50.  flashing by making the script call
  51.  
  52.    end_character_flash(id)
  53.  
  54.  The color of the flash is a Color object.
  55.  If the color is not specified, it defaults to the color that is specified
  56.  in the configuration.
  57.  
  58.  
  59.  
  60. --------------------------------------------------------------------------------
  61.  ** Example
  62.  
  63.   To have event 3 flash red (RGB value 255,0,0), for 60 frames, make the
  64.   script call
  65.  
  66.     color = Color.new(255, 0, 0)
  67.     character_flash(3, 60, 0, color)
  68.  
  69. #===============================================================================
  70. =end
  71. $imported = {} if $imported.nil?
  72. $imported["TH_CharacterFlash"] = true
  73. #===============================================================================
  74. # ** Configuration
  75. #===============================================================================
  76. module TH
  77.   module Character_Flash
  78.    
  79.     # The default flash color if you don't specify one. Takes an RGBA value.
  80.     Default_Color = Color.new(255, 255, 255, 255)
  81.   end
  82. end
  83. #===============================================================================
  84. # ** Rest of Script
  85. #===============================================================================
  86. class Game_Interpreter
  87.  
  88.   def character_flash(id, duration, loop=1, color=TH::Character_Flash::Default_Color)
  89.     get_character(id).begin_flash(duration, loop, color)
  90.   end
  91.  
  92.   def end_character_flash(id)
  93.     get_character(id).clear_flash_settings
  94.   end
  95. end
  96.  
  97. class Game_CharacterBase
  98.  
  99.   attr_reader :flash_on
  100.   attr_reader :flash_duration
  101.   attr_reader :flash_color
  102.   attr_reader :flash_loop
  103.  
  104.   alias :th_character_flash_init_public_members :init_public_members
  105.   def init_public_members
  106.     th_character_flash_init_public_members
  107.     clear_flash_settings
  108.   end
  109.  
  110.   def clear_flash_settings
  111.     @flash_loop = 1
  112.     @flash_on = false
  113.     @flash_duration = 0
  114.     @flash_color = TH::Character_Flash::Default_Color
  115.   end
  116.  
  117.   def begin_flash(duration, loop, color)
  118.     @flash_on = true
  119.     @flash_loop = loop
  120.     @flash_duration = duration
  121.     @flash_color = color
  122.   end
  123.  
  124.   def end_flash
  125.     if @flash_loop == 0
  126.       @flash_on = false
  127.     else
  128.       clear_flash_settings
  129.     end
  130.   end
  131.  
  132.   alias :th_character_flash_update :update
  133.   def update
  134.     update_flash
  135.     th_character_flash_update
  136.   end
  137.  
  138.   def update_flash
  139.     if @flash_loop == 0 && !@flash_on
  140.       @flash_on = true
  141.     end
  142.   end
  143. end
  144.  
  145. class Sprite_Character < Sprite_Base
  146.  
  147.   @@flash_color = Color.new(255, 255, 255)
  148.  
  149.   alias :th_character_flash_initialize :initialize
  150.   def initialize(viewport, character = nil)
  151.     @flash_duration = 0
  152.     @flashing = false
  153.     th_character_flash_initialize(viewport, character)
  154.   end
  155.  
  156.   alias :th_character_flash_update :update
  157.   def update
  158.     th_character_flash_update
  159.     update_flashing
  160.   end
  161.  
  162.   def update_flashing
  163.     if !@flashing
  164.       if @character.flash_on
  165.         @flashing = true
  166.         color = @character.flash_color || @@flash_color
  167.         flash(color, @character.flash_duration)
  168.         @character.end_flash
  169.       end
  170.     else
  171.       @flash_duration += 1  
  172.       if @flash_duration >= @character.flash_duration
  173.         @flash_duration = 0
  174.         @flashing = false
  175.       end
  176.     end    
  177.   end
  178. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement