IceDragon200

Text Pop No Bounce :3

Jun 11th, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.05 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 = 9.88
  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
  86.     end
  87.    
  88.     def damage_y_init_velocity
  89.       return 0  
  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 = -5.0
  97.       @speed_off_x = rand(0)
  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.         #  Prevent Sliding
  109.         #sprite.x += TRANCEPARENT_X_SLIDE if @speed_off_x < 6
  110.         #sprite.x -= TRANCEPARENT_X_SLIDE if @speed_off_x >= 6
  111.       end
  112.       sprite.x = @ref_character.screen_x + (@spr_ox - (sprite.bitmap.width) / 2)
  113.       sprite.y = @ref_character.screen_y - 48
  114.       return if sprite == nil
  115.       n = sprite.oy + @now_y_speed
  116.       if n <= 0
  117.         @now_y_speed *= -1
  118.         @now_y_speed /=  2
  119.         @now_x_speed /=  2
  120.       end      
  121.       #sprite.oy = [n, 0].max # // Kill Y Offset
  122.       @potential_y_energy += GRAVITY
  123.       speed = @potential_y_energy.floor
  124.       @now_y_speed        -= speed
  125.       @potential_y_energy -= speed
  126.       @potential_x_energy += @now_x_speed
  127.       speed = @potential_x_energy.floor
  128.       # // Kill X offsets
  129.       #sprite.ox  += speed if @speed_off_x < 6
  130.       #sprite.ox  -= speed if @speed_off_x >= 6
  131.       @potential_x_energy -= speed
  132.       @pop_duration -= 1
  133.       if @pop_duration == 0
  134.         @finished = true
  135.       end
  136.     end
  137.    
  138. end
  139.  
  140. class Sprite_Character < Sprite_Base
  141.  
  142.   #--------------------------------------------------------------------------
  143.   # * Object Initialization
  144.   #--------------------------------------------------------------------------
  145.   alias iex_text_pop_spc_initialize initialize unless $@
  146.   def initialize(*args)
  147.     iex_text_pop_spc_initialize(*args)
  148.     if @character != nil
  149.       @character.iex_sprite_back_ref = self
  150.     end  
  151.   end
  152.  
  153.   alias iex_text_pop_spc_dispose dispose unless $@
  154.   def dispose(*args)
  155.     iex_text_pop_spc_dispose(*args)
  156.     if @character != nil
  157.       @character.iex_sprite_back_ref = nil
  158.     end  
  159.   end
  160.  
  161. end
  162.  
  163. class Game_Character
  164.  
  165.   attr_accessor :texts_to_pop
  166.   attr_accessor :texts_ready
  167.   attr_accessor :iex_sprite_back_ref
  168.   attr_accessor :iex_waiting_text
  169.  
  170.   alias ixtp_gc_text_pop_initialize initialize unless $@
  171.   def initialize(*args)
  172.     ixtp_gc_text_pop_initialize(*args)
  173.     @texts_to_pop = []
  174.     @texts_ready = false
  175.     @ptext = ''
  176.     @iex_sprite_back_ref = nil
  177.     @iex_waiting_text = []
  178.     @pop_delay = 0
  179.     @iex_can_pop = true
  180.   end
  181.  
  182.   def prep_text_stack
  183.     if @texts_to_pop != nil
  184.        @texts_to_pop.clear
  185.     end  
  186.     @texts_to_pop = []
  187.   end
  188.  
  189.  
  190.   def stack_text_pop(text = nil, color = Color.new(255, 255, 255), size = 18, properties = [], more_fonts = [])
  191.     @iex_waiting_text.push([text, color, size, properties, more_fonts])
  192.   end
  193.  
  194.   alias ixtp_gc_text_pop_update update unless $@
  195.   def update(*args)
  196.     ixtp_gc_text_pop_update(*args)
  197.     if @iex_can_pop
  198.       @pop_delay -= 1 unless @pop_delay == 0
  199.       if @pop_delay == 0 and !@iex_waiting_text.empty?
  200.         pop_dat = @iex_waiting_text.shift
  201.         execute_text_pop(pop_dat[0], pop_dat[1], pop_dat[2], pop_dat[3], pop_dat[4])
  202.         @pop_delay = 5
  203.       end  
  204.     end  
  205.   end
  206.  
  207.   def execute_text_pop(text = nil, color = Color.new(255, 255, 255), size = 14, properties = [], more_fonts = [])
  208.     return if text == nil
  209.     text = text.to_s
  210.     size = size.to_i
  211.     text = text.gsub(/<(?:var|v)\[(\d+)\]>/i) { $game_variables[$1.to_i] }
  212.     text = text.gsub(/<(?:name|n)\[(\d+)\]>/i) { $game_actors[$1.to_i].name }
  213.     textsize = text.size * 24
  214.     textsize += 32 if textsize < 32
  215.     text_height = size + 1
  216.     text_data = []
  217.     text_data[0] = Sprite.new
  218.     text_data[0].bitmap = Bitmap.new(textsize, text_height)
  219.     font_names = []
  220.     font_names += more_fonts
  221.     for prop in properties
  222.       case prop.to_s
  223.       when /(?:BOLD|B)/i
  224.         text_data[0].bitmap.font.bold = true
  225.       when /(?:ITALIC|I)s?/i
  226.         text_data[0].bitmap.font.italic = true
  227.       when /(?:SHADOW|SH)/i
  228.         text_data[0].bitmap.font.shadow = true
  229.       when /(?:NO_SHADOW|no shadow|NSH)/i
  230.         text_data[0].bitmap.font.shadow = false  
  231.       when /(?:NO_BOLD|no bold|NB)/i
  232.         text_data[0].bitmap.font.bold = false
  233.       when /(?:NO_ITALIC|no italic|NI)s?/i
  234.         text_data[0].bitmap.font.italic = false
  235.       end
  236.     end  
  237.     font_names += Font.default_name if Font.default_name.is_a?(Array)
  238.     font_names.push(Font.default_name) if Font.default_name.is_a?(String)
  239.     text_data[0].bitmap.font.name = font_names    
  240.     text_data[0].bitmap.font.size = size
  241.     text_data[0].bitmap.font.color = color
  242.     text_data[0].bitmap.draw_text(0, 0, textsize, text_height, text, 1)
  243.     if @iex_sprite_back_ref != nil
  244.       spr_ox = @iex_sprite_back_ref.ox
  245.       spr_x  = @iex_sprite_back_ref.x
  246.       spr_y  = @iex_sprite_back_ref.y
  247.       spr_height = @iex_sprite_back_ref.height
  248.     else
  249.       spr_ox = 0
  250.       spr_x  = screen_x
  251.       spr_y  = screen_y
  252.       spr_height = 32
  253.     end  
  254.     text_data[0].x = spr_x + (spr_ox - (text_data[0].bitmap.width) / 2)
  255.     text_data[0].y = (spr_y - spr_height) + 16
  256.     text_data[0].z = 280
  257.     text_data[1] = XRXS_POP_ENGINE.new(text_data[0], self.x, self.y, spr_ox)
  258.     @texts_to_pop.push(text_data)
  259.   end
  260.  
  261. end
  262.  
  263. class Sprite_Character < Sprite_Base
  264.  
  265.   alias ixtp_scm_text_pop_initialize initialize unless $@
  266.   def initialize(*args)
  267.     @ixtp_text_pop = []
  268.     ixtp_scm_text_pop_initialize(*args)
  269.   end
  270.  
  271.   alias ixtp_update_text_pop_update update unless $@
  272.   def update
  273.     ixtp_update_text_pop_update
  274.     unless @character.texts_to_pop.empty?
  275.       @ixtp_text_pop = @ixtp_text_pop + @character.texts_to_pop
  276.       @character.texts_to_pop.clear
  277.     end    
  278.     ixtp_update_text_pop
  279.   end
  280.  
  281.   def ixtp_update_text_pop
  282.     return if @ixtp_text_pop.empty?
  283.     for i in 0..@ixtp_text_pop.size
  284.       spri = @ixtp_text_pop[i]
  285.       next if spri == nil
  286.       if spri[1] == nil or spri[0] == nil
  287.         #@ixtp_text_pop.compact!
  288.         next
  289.       end  
  290.       if spri[1].finished
  291.         ixtp_dispose_text_pop(spri)
  292.         @ixtp_text_pop.delete(i)
  293.         spri[0] = nil
  294.         spri[1] = nil
  295.         #@ixtp_text_pop.compact!
  296.       else
  297.         spri[1].pop_update
  298.       end
  299.     end
  300.   end
  301.  
  302.   def ixtp_dispose_text_pop(spri)
  303.     return if spri == nil
  304.     return if spri[0] == nil
  305.     spri[1].stop_update = true
  306.     spri[0].dispose
  307.   end
  308.    
  309.   def ixtp_dispose_all_text_pop
  310.     for spri in @ixtp_text_pop
  311.       ixtp_dispose_text_pop(spri)
  312.     end
  313.       @ixtp_text_pop.clear
  314.       @ixtp_text_pop = []
  315.   end
  316.  
  317.   alias ixtp_scm_text_pop_dispose dispose unless $@
  318.   def dispose
  319.     ixtp_scm_text_pop_dispose
  320.     ixtp_dispose_all_text_pop
  321.     @character.iex_sprite_back_ref = nil
  322.   end
  323.  
  324. end
Advertisement
Add Comment
Please, Sign In to add comment