IceDragon200

IEX - Text Pop

Nov 1st, 2011
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.03 KB | None | 0 0
  1. #==============================================================================#
  2. # ** IEX(Icy Engine Xelion) - TP - Text Pop
  3. #------------------------------------------------------------------------------#
  4. # ** Created by    : IceDragon
  5. # ** Script-Status : Addon (Events and Player)
  6. # ** Script Type   : Text Pop
  7. # ** Date Created  : 08/29/2010
  8. # ** Date Modified : 12/09/2010
  9. # ** Version       : 1.0a
  10. #------------------------------------------------------------------------------#
  11. #==============================================================================#
  12. # ** FEATURES + HOW TO USE
  13. #------------------------------------------------------------------------------#
  14. # ~Quick Ref
  15. # stack_text_pop("text", color, size)
  16. # text is pretty straight forward..
  17. #
  18. # color is a color class type
  19. # Being Color.new(255, 255, 255, 255) R,G,B, alpha respectively
  20. #
  21. # size is an integer, and represents the pops font size
  22. #
  23. # ~Long Explanation
  24. # Just a simple text popping script.
  25. # How does this work?
  26. # You will do all these in a Move Route Call (Sorry its just easier that way)
  27. # This works a little different from the IXTP version
  28. # You do the script call stack_text_pop("text", color, size) This will immediately
  29. # pop the selected text.
  30. # You can call this as many times as you like. It will simply add to the existing
  31. # pops
  32. # Color is optional (The deafult color will be used if not defined)
  33. # Size is the font size and is also optional
  34. #
  35. # Credit goes to Xideworg (Did I spell it right?) for his Pop Engine (XRXS Scripts)
  36. #
  37. # To use text substitution.
  38. # <var[id]> for variables
  39. # <name[id]> for actor name
  40. #
  41. #------------------------------------------------------------------------------#
  42. #==============================================================================#
  43. # ** KNOWN ISSUES
  44. #------------------------------------------------------------------------------#
  45. # Non at the moment.
  46. #
  47. #------------------------------------------------------------------------------#
  48. #==============================================================================#
  49. # ** CHANGE LOG
  50. #------------------------------------------------------------------------------#
  51. #
  52. # 09/01/2010 1.0  Edited IXTP and shipped over to IEX
  53. # 12/09/2010 1.0a Bug Fix, if the default font was changed from an array,
  54. #                 the script would throw an error
  55. #
  56. #------------------------------------------------------------------------------#
  57. $imported = {} if $imported == nil
  58. $imported["IEX_Text_Pop"] = true
  59.  
  60. class XRXS_POP_ENGINE # Taken form XRXS
  61.     attr_accessor :finished
  62.     attr_accessor :sprite
  63.     attr_accessor :stop_update
  64.    
  65.     GRAVITY = 0.58
  66.     TRANCEPARENT_START = 40
  67.     TRANCEPARENT_X_SLIDE = 0    
  68.    
  69.     def initialize(sprite, x, y, ox)
  70.       @finished = false
  71.       @ref_character = Game_Character.new
  72.       @ref_character.moveto(x, y)
  73.       @ref_character.update
  74.       @spr_ox = ox
  75.       @working_sprite = sprite
  76.       @stop_update = false
  77.       prep_pop
  78.     end
  79.    
  80.     def work_sprite
  81.       return @working_sprite
  82.     end
  83.    
  84.     def damage_x_init_velocity
  85.       return 0.4 * (rand(8))  # 0.2 * (rand(5) - 2)
  86.     end
  87.    
  88.     def damage_y_init_velocity
  89.       return 1.5 * (rand(4) + 4)  
  90.     end
  91.    
  92.     def prep_pop
  93.       @now_x_speed = damage_x_init_velocity
  94.       @now_y_speed = damage_y_init_velocity
  95.       @potential_x_energy = 0.0
  96.       @potential_y_energy = 0.0
  97.       @speed_off_x = rand(10)
  98.       @pop_duration = 80
  99.     end
  100.    
  101.     def pop_update
  102.       sprite = work_sprite
  103.       return if sprite == nil
  104.       return if @finished
  105.       return if @stop_update
  106.       if @pop_duration <= TRANCEPARENT_START
  107.         sprite.opacity -= (256 / TRANCEPARENT_START)
  108.         sprite.x += TRANCEPARENT_X_SLIDE if @speed_off_x < 6
  109.         sprite.x -= TRANCEPARENT_X_SLIDE if @speed_off_x >= 6
  110.       end
  111.       sprite.x = @ref_character.screen_x + (@spr_ox - (sprite.bitmap.width) / 2)
  112.       sprite.y = @ref_character.screen_y
  113.       return if sprite == nil
  114.       n = sprite.oy + @now_y_speed
  115.       if n <= 0
  116.         @now_y_speed *= -1
  117.         @now_y_speed /=  2
  118.         @now_x_speed /=  2
  119.       end      
  120.       sprite.oy = [n, 0].max
  121.       @potential_y_energy += GRAVITY
  122.       speed = @potential_y_energy.floor
  123.       @now_y_speed        -= speed
  124.       @potential_y_energy -= speed
  125.       @potential_x_energy += @now_x_speed
  126.       speed = @potential_x_energy.floor
  127.       sprite.ox  += speed if @speed_off_x < 6
  128.       sprite.ox  -= speed if @speed_off_x >= 6
  129.       @potential_x_energy -= speed
  130.       @pop_duration -= 1
  131.       if @pop_duration == 0
  132.         @finished = true
  133.       end
  134.     end
  135.    
  136. end
  137.  
  138. class Sprite_Character < Sprite_Base
  139.  
  140.   #--------------------------------------------------------------------------
  141.   # * Object Initialization
  142.   #--------------------------------------------------------------------------
  143.   alias iex_text_pop_spc_initialize initialize unless $@
  144.   def initialize(*args)
  145.     iex_text_pop_spc_initialize(*args)
  146.     if @character != nil
  147.       @character.iex_sprite_back_ref = self
  148.     end  
  149.   end
  150.  
  151.   alias iex_text_pop_spc_dispose dispose unless $@
  152.   def dispose(*args)
  153.     iex_text_pop_spc_dispose(*args)
  154.     if @character != nil
  155.       @character.iex_sprite_back_ref = nil
  156.     end  
  157.   end
  158.  
  159. end
  160.  
  161. class Game_Character
  162.  
  163.   attr_accessor :texts_to_pop
  164.   attr_accessor :texts_ready
  165.   attr_accessor :iex_sprite_back_ref
  166.   attr_accessor :iex_waiting_text
  167.  
  168.   alias ixtp_gc_text_pop_initialize initialize unless $@
  169.   def initialize(*args)
  170.     ixtp_gc_text_pop_initialize(*args)
  171.     @texts_to_pop = []
  172.     @texts_ready = false
  173.     @ptext = ''
  174.     @iex_sprite_back_ref = nil
  175.     @iex_waiting_text = []
  176.     @pop_delay = 0
  177.     @iex_can_pop = true
  178.   end
  179.  
  180.   def prep_text_stack
  181.     if @texts_to_pop != nil
  182.        @texts_to_pop.clear
  183.     end  
  184.     @texts_to_pop = []
  185.   end
  186.  
  187.  
  188.   def stack_text_pop(text = nil, color = Color.new(255, 255, 255), size = 21, properties = [], more_fonts = [])
  189.     @iex_waiting_text.push([text, color, size, properties, more_fonts])
  190.   end
  191.  
  192.   alias ixtp_gc_text_pop_update update unless $@
  193.   def update(*args)
  194.     ixtp_gc_text_pop_update(*args)
  195.     if @iex_can_pop
  196.       @pop_delay -= 1 unless @pop_delay == 0
  197.       if @pop_delay == 0 and !@iex_waiting_text.empty?
  198.         pop_dat = @iex_waiting_text.shift
  199.         execute_text_pop(pop_dat[0], pop_dat[1], pop_dat[2], pop_dat[3], pop_dat[4])
  200.         @pop_delay = 5
  201.       end  
  202.     end  
  203.   end
  204.  
  205.   def execute_text_pop(text = nil, color = Color.new(255, 255, 255), size = 21, properties = [], more_fonts = [])
  206.     return if text == nil
  207.     text = text.to_s
  208.     size = size.to_i
  209.     text = text.gsub(/<(?:var|v)\[(\d+)\]>/i) { $game_variables[$1.to_i] }
  210.     text = text.gsub(/<(?:name|n)\[(\d+)\]>/i) { $game_actors[$1.to_i].name }
  211.     textsize = text.size * 24
  212.     textsize += 32 if textsize < 32
  213.     text_height = size + 2
  214.     text_data = []
  215.     text_data[0] = Sprite.new
  216.     text_data[0].bitmap = Bitmap.new(textsize, text_height)
  217.     font_names = []
  218.     font_names += more_fonts
  219.     for prop in properties
  220.       case prop.to_s
  221.       when /(?:BOLD|B)/i
  222.         text_data[0].bitmap.font.bold = true
  223.       when /(?:ITALIC|I)s?/i
  224.         text_data[0].bitmap.font.italic = true
  225.       when /(?:SHADOW|SH)/i
  226.         text_data[0].bitmap.font.shadow = true
  227.       when /(?:NO_SHADOW|no shadow|NSH)/i
  228.         text_data[0].bitmap.font.shadow = false  
  229.       when /(?:NO_BOLD|no bold|NB)/i
  230.         text_data[0].bitmap.font.bold = false
  231.       when /(?:NO_ITALIC|no italic|NI)s?/i
  232.         text_data[0].bitmap.font.italic = false
  233.       end
  234.     end  
  235.     font_names += Font.default_name if Font.default_name.is_a?(Array)
  236.     font_names.push(Font.default_name) if Font.default_name.is_a?(String)
  237.     text_data[0].bitmap.font.name = font_names    
  238.     text_data[0].bitmap.font.size = size
  239.     text_data[0].bitmap.font.color = color
  240.     text_data[0].bitmap.draw_text(0, 0, textsize, text_height, text, 1)
  241.     if @iex_sprite_back_ref != nil
  242.       spr_ox = @iex_sprite_back_ref.ox
  243.       spr_x  = @iex_sprite_back_ref.x
  244.       spr_y  = @iex_sprite_back_ref.y
  245.       spr_height = @iex_sprite_back_ref.height
  246.     else
  247.       spr_ox = 0
  248.       spr_x  = screen_x
  249.       spr_y  = screen_y
  250.       spr_height = 32
  251.     end  
  252.     text_data[0].x = spr_x + (spr_ox - (text_data[0].bitmap.width) / 2)
  253.     text_data[0].y = (spr_y - spr_height) + 16
  254.     text_data[0].z = 280
  255.     text_data[1] = XRXS_POP_ENGINE.new(text_data[0], self.x, self.y, spr_ox)
  256.     @texts_to_pop.push(text_data)
  257.   end
  258.  
  259. end
  260.  
  261. class Sprite_Character < Sprite_Base
  262.  
  263.   alias ixtp_scm_text_pop_initialize initialize unless $@
  264.   def initialize(*args)
  265.     @ixtp_text_pop = []
  266.     ixtp_scm_text_pop_initialize(*args)
  267.   end
  268.  
  269.   alias ixtp_update_text_pop_update update unless $@
  270.   def update
  271.     ixtp_update_text_pop_update
  272.     unless @character.texts_to_pop.empty?
  273.       @ixtp_text_pop = @ixtp_text_pop + @character.texts_to_pop
  274.       @character.texts_to_pop.clear
  275.     end    
  276.     ixtp_update_text_pop
  277.   end
  278.  
  279.   def ixtp_update_text_pop
  280.     return if @ixtp_text_pop.empty?
  281.     for i in 0..@ixtp_text_pop.size
  282.       spri = @ixtp_text_pop[i]
  283.       next if spri == nil
  284.       if spri[1] == nil or spri[0] == nil
  285.         #@ixtp_text_pop.compact!
  286.         next
  287.       end  
  288.       if spri[1].finished
  289.         ixtp_dispose_text_pop(spri)
  290.         @ixtp_text_pop.delete(i)
  291.         spri[0] = nil
  292.         spri[1] = nil
  293.         #@ixtp_text_pop.compact!
  294.       else
  295.         spri[1].pop_update
  296.       end
  297.     end
  298.   end
  299.  
  300.   def ixtp_dispose_text_pop(spri)
  301.     return if spri == nil
  302.     return if spri[0] == nil
  303.     spri[1].stop_update = true
  304.     spri[0].dispose
  305.   end
  306.    
  307.   def ixtp_dispose_all_text_pop
  308.     for spri in @ixtp_text_pop
  309.       ixtp_dispose_text_pop(spri)
  310.     end
  311.       @ixtp_text_pop.clear
  312.       @ixtp_text_pop = []
  313.   end
  314.  
  315.   alias ixtp_scm_text_pop_dispose dispose unless $@
  316.   def dispose
  317.     ixtp_scm_text_pop_dispose
  318.     ixtp_dispose_all_text_pop
  319.     @character.iex_sprite_back_ref = nil
  320.   end
  321.  
  322. end
  323.  
Advertisement
Add Comment
Please, Sign In to add comment