Advertisement
neonblack

Bubble Pop-up v1.0

Apr 25th, 2013
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.89 KB | None | 0 0
  1. ##----------------------------------------------------------------------------##
  2. ## Common Bubble Pop-ups
  3. ## Created by Neon Black
  4. ##
  5. ## For both commercial and non-commercial use as long as credit is given to
  6. ## Neon Black and any additional authors.  Licensed under Creative Commons
  7. ## CC BY 3.0 - http://creativecommons.org/licenses/by/3.0/.
  8. ##----------------------------------------------------------------------------##
  9.                                                                               ##
  10. ##----------------------------------------------------------------------------##
  11. ##    Revision Info:
  12. ## v1.0 - 4.25.2013
  13. ##  Wrote and debugged main script
  14. ##----------------------------------------------------------------------------##
  15.                                                                               ##
  16. $imported ||= {}                                                              ##
  17. $imported["CP_BUBBLE_POP"] = 1.0                                              ##
  18.                                                                               ##
  19. ##----------------------------------------------------------------------------##
  20. ##    Instructions:
  21. ## Place this script in the script editor below "Materials" and above "Main".
  22. ## This script allows bubbles to appear over a player's head while they're
  23. ## standing over a specific event.  You can have this only occur on certain
  24. ## pages and have any bubble from the sheet appear.  To do this, place the
  25. ## following tag in a comment on the page you would like to activate this.
  26. ##
  27. ## pop bubble[1]
  28. ##  - Causes balloon 1 from the balloon sheet to appear over the player's head.
  29. ##    The first balloon is number 1 and you can use any number rather than 1.
  30. ##----------------------------------------------------------------------------##
  31.                                                                               ##
  32.                                                                               ##
  33. ##----------------------------------------------------------------------------##
  34. ## The following lines are the actual core code of the script.  While you are
  35. ## certainly invited to look, modifying it may result in undesirable results.
  36. ## Modify at your own risk!
  37. ###----------------------------------------------------------------------------
  38.  
  39.  
  40. class RPG::Event::Page
  41.   def bubble
  42.     return @bubble if @bubble
  43.     self.list.each do |l|
  44.       next unless [108, 408].include?(l.code)
  45.       if l.parameters[0] =~ /pop bubble\[(\d+)\]/i
  46.         @bubble = $1.to_i
  47.       end
  48.     end
  49.     @bubble ||= 0
  50.     bubble
  51.   end
  52. end
  53.  
  54. class Game_Event < Game_Character
  55.   alias :cp_42513_update :update
  56.   def update(*args)
  57.     cp_42513_update(*args)
  58.     check_bubble if @page.bubble > 0
  59.   end
  60.  
  61.   def check_bubble
  62.     $game_player.special_balloon = @page.bubble if $game_player.pos?(x, y)
  63.   end
  64. end
  65.  
  66. class Game_CharacterBase
  67.   attr_accessor :special_balloon
  68.  
  69.   alias :cp_42513_init_mems :init_public_members
  70.   def init_public_members(*args)
  71.     cp_42513_init_mems(*args)
  72.     @special_balloon = 0
  73.   end
  74. end
  75.  
  76. class Sprite_Character < Sprite_Base
  77.   alias :cp_42513_update :update
  78.   def update(*args)
  79.     cp_42513_update(*args)
  80.     update_sp_balloon
  81.   end
  82.  
  83.   alias :cp_42513_new_effect :setup_new_effect
  84.   def setup_new_effect(*args)
  85.     cp_42513_new_effect(*args)
  86.     if !@balloon_sprite && !@balloon_sp_sprite && @character.special_balloon > 0
  87.       @balloon_sp_id = @character.special_balloon
  88.       start_sp_balloon
  89.     end
  90.   end
  91.  
  92.   alias :cp_42513_start_balloon :start_balloon
  93.   def start_balloon(*args)
  94.     end_sp_balloon
  95.     cp_42513_start_balloon(*args)
  96.   end
  97.  
  98.   def start_sp_balloon
  99.     dispose_sp_balloon
  100.     @balloon_sp_duration = 8 * balloon_speed + balloon_wait
  101.     @balloon_sp_sprite = ::Sprite.new(viewport)
  102.     @balloon_sp_sprite.bitmap = Cache.system("Balloon")
  103.     @balloon_sp_sprite.ox = 16
  104.     @balloon_sp_sprite.oy = 32
  105.   end
  106.  
  107.   def update_sp_balloon
  108.     if @character.special_balloon > 0 && @balloon_sp_sprite
  109.       @balloon_sp_duration -= 1 if @balloon_sp_duration > 0
  110.       @balloon_sp_sprite.x = x
  111.       @balloon_sp_sprite.y = y - height
  112.       @balloon_sp_sprite.z = z + 200
  113.       frame = 7 - [(@balloon_sp_duration - balloon_wait) / balloon_speed, 0].max
  114.       sx = frame * 32
  115.       sy = (@balloon_sp_id - 1) * 32
  116.       @balloon_sp_sprite.src_rect.set(sx, sy, 32, 32)
  117.       @character.special_balloon = 0
  118.     elsif @character.special_balloon == 0
  119.       end_sp_balloon
  120.     end
  121.   end
  122.  
  123.   def end_sp_balloon
  124.     dispose_sp_balloon
  125.     @character.special_balloon = 0
  126.   end
  127.  
  128.   def dispose_sp_balloon
  129.     if @balloon_sp_sprite
  130.       @balloon_sp_sprite.dispose
  131.       @balloon_sp_sprite = nil
  132.     end
  133.   end
  134. end
  135.  
  136.  
  137. ###----------------------------------------------------------------------------
  138. #  End of script.
  139. ###----------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement