molegato

molegato_functions_V1.2

Mar 3rd, 2012
1,236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.16 KB | None | 0 0
  1. #==============================================================================
  2. # MOLEGATO FUNCTIONS
  3. # Author Molegato
  4. # Version 1.2.4
  5. #------------------------------------------------------------------------------
  6. # Several methods that I use in my scripts.
  7. #------------------------------------------------------------------------------
  8. # Included in some of my scripts. May be needed for those that dont include it
  9. # in order to make them work.
  10. #==============================================================================
  11.  
  12.  
  13. #==============================================================================
  14. # MOLEGATO Sprite_Base
  15. #------------------------------------------------------------------------------
  16. # Animation fixation plus afterimage_effect
  17. #==============================================================================
  18. class Sprite_Base < Sprite
  19.  
  20. alias molegato_initialize initialize
  21. def initialize(viewport = nil)
  22. molegato_initialize(viewport)
  23. @past_info=[]
  24. @after_sprites=[]
  25. @afterimage=false
  26. @afterimage_options={}
  27. @afterimage_options[:max_images]=3
  28. @afterimage_options[:time]=10
  29. @afterimage_options[:color]=nil
  30.  
  31. @afterimage_frame=0
  32. end
  33.  
  34. alias molegato_update update
  35. def update
  36. molegato_update
  37. update_past_info
  38. update_afterimages if @afterimage
  39. end
  40.  
  41. alias molegato_dispose dispose
  42. def dispose
  43. stop_afterimage
  44. molegato_dispose
  45. end
  46.  
  47. def update_past_info
  48. data = {
  49. :x => x, :y => y, :ox => ox, :oy => oy, :z=>z-1,
  50. :zoom_x => zoom_x, :zoom_y => zoom_y,
  51. :opacity => opacity,
  52. :bitmap => bitmap, :src_rect => src_rect,
  53. :tone => tone, :color => color,
  54. :angle => angle, :mirror => mirror,
  55. :wave_amp => wave_amp,
  56. :wave_length => wave_length,
  57. :wave_speed => wave_speed,
  58. :wave_phase => wave_phase,
  59. :viewport => viewport,
  60. :bush_depth => bush_depth, :bush_opacity => bush_opacity
  61. }
  62. if bitmap
  63. @past_info << data
  64. end
  65. end
  66.  
  67. def update_afterimages
  68. for i in @after_sprites
  69. i.update
  70. if not i.animating?
  71. i.dispose
  72. @after_sprites.delete(i)
  73. end
  74. end
  75.  
  76. if @afterimage_frame==0
  77. t=(-@afterimage_options[:time]/@afterimage_options[:max_images])
  78. @after_sprites.push(Sprite_afterimage.new(@past_info[t],@afterimage_options)) if not @past_info.empty?
  79. end
  80. @afterimage_frame+=1
  81. @afterimage_frame %= @afterimage_options[:time]
  82. @afterimage_frame %= (-@afterimage_options[:time]/@afterimage_options[:max_images])
  83. end
  84.  
  85. def start_afterimage(max_images=3,time=10,color=nil,fade=0)
  86. stop_afterimage
  87. @afterimage_options[:max_images]=max_images
  88. @afterimage_options[:time]=time
  89. @afterimage_options[:color]=color
  90. @afterimage_options[:fade]=fade
  91. @afterimage=true
  92. @afterimage_frame=0
  93. end
  94.  
  95. def stop_afterimage
  96. @afterimage=false
  97. for sprite in @after_sprites
  98. sprite.dispose
  99. end
  100. @after_sprites.clear
  101. end
  102.  
  103. def afterimage?
  104. return @afterimage
  105. end
  106.  
  107. alias molegato_update_animation update_animation
  108. def update_animation
  109. molegato_update_animation
  110. set_animation_origin if @animation
  111. end
  112.  
  113. def set_bitmap_as_icon(icon_index)
  114. bitmap = Cache.system("Iconset")
  115. new_bitmap= Bitmap.new(24,24)
  116. rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  117. new_bitmap.blt(0, 0, bitmap, rect, 255)
  118. self.bitmap=new_bitmap
  119. end
  120. end
  121. #------------------------------------------------------------------------------
  122. # Sprite_Afterimage
  123. #------------------------------------------------------------------------------
  124. class Sprite_afterimage < Sprite
  125. def initialize(data, options)
  126. super()
  127. self.bitmap=data[:bitmap]
  128. self.x=data[:x]
  129. self.ox=data[:ox]
  130. self.y=data[:y]
  131. self.oy=data[:oy]
  132. self.z=data[:z]
  133. self.zoom_x=data[:zoom_x]
  134. self.zoom_y=data[:zoom_y]
  135. self.opacity=data[:opacity]
  136. self.src_rect=data[:src_rect]
  137. self.tone=data[:tone]
  138. self.color=data[:color]
  139. self.angle=data[:angle]
  140. self.wave_amp=data[:wave_amp]
  141. self.wave_length=data[:wave_length]
  142. self.wave_speed=data[:wave_speed]
  143. self.wave_phase=data[:wave_phase]
  144. self.viewport=data[:viewport]
  145. self.bush_depth=data[:bush_depth]
  146. self.bush_opacity=data[:bush_opacity]
  147. @anime_time=options[:time]
  148.  
  149. if options[:color]
  150. self.color=options[:color]
  151. end
  152. @fade=options[:fade]
  153. end
  154.  
  155. def update
  156. super
  157. if @anime_time>0
  158. if @fade==0
  159. self.opacity = ( self.opacity * ( @anime_time - 1 ) ) / @anime_time
  160. else
  161. self.opacity=@fade
  162. end
  163. @anime_time-=1
  164. end
  165. end
  166.  
  167. def animating?
  168. return (@anime_time>0)
  169. end
  170.  
  171. end
  172.  
  173. #==============================================================================
  174. # MOLEGATO GAME_EVENT
  175. #------------------------------------------------------------------------------
  176. # Several methods for Game_Event
  177. #==============================================================================
  178. class Game_Event < Game_Character
  179.  
  180. def note
  181. string_note=""
  182.  
  183. return "" if not list
  184.  
  185. for i in 0..list.size-1
  186. if list[i] and list[i].code==108
  187. string_note += list[i].parameters[0]
  188. end
  189. end
  190. return string_note
  191. end
  192.  
  193. end
  194.  
  195. #==============================================================================
  196. # MOLEGATO BattleManager
  197. #------------------------------------------------------------------------------
  198. # Several methods for BattleManager
  199. #==============================================================================
  200. module BattleManager
  201.  
  202. def self.action_battlers
  203. return @action_battlers
  204. end
  205.  
  206. def self.delete_battler_from_turn(battler)
  207. @action_battlers.delete(battler)
  208. end
  209.  
  210. def self.delete_dead_battlers
  211. for i in 0..@action_battlers.size-1
  212. if @action_battlers[i] && !@action_battlers[i].alive?
  213. @action_battlers.delete(@action_battlers[i])
  214. end
  215. end
  216. end
  217.  
  218. end
  219.  
  220. #==============================================================================
  221. # MOLEGATO WINDOW BASE
  222. #------------------------------------------------------------------------------
  223. # Several methods for window_base
  224. #==============================================================================
  225.  
  226. class Window_Base < Window
  227. def draw_face_scaled(face_name, face_index, x, y, scale,enabled = true)
  228. bitmap = Cache.face(face_name)
  229. rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
  230. rect2 = Rect.new(x,y, 96*scale, 96*scale)
  231. contents.stretch_blt(rect2, bitmap, rect,enabled ? 255 : translucent_alpha)
  232. bitmap.dispose
  233. end
  234.  
  235. def draw_actor_face_scaled(actor, x, y, scale, enabled = true)
  236. draw_face_scaled(actor.face_name, actor.face_index, x, y, scale, enabled)
  237. end
  238.  
  239. def draw_system(name, x, y, ox=0,oy=0)
  240. bitmap = Cache.system(name)
  241. rect = Rect.new(0, 0, bitmap.width, bitmap.width)
  242. contents.blt(x-bitmap.width*ox, y-bitmap.height*oy, bitmap, rect, 255)
  243. vector=[x-bitmap.width*ox, y-bitmap.height*oy,x-bitmap.width*ox+bitmap.width, y-bitmap.height*oy+bitmap.height]
  244. return vector
  245. end
  246.  
  247. def instant_close
  248. @openness=0
  249. @closing=false
  250. @opening=false
  251. end
  252.  
  253. def instant_open
  254. @openness=255
  255. @closing=false
  256. @opening=false
  257. end
  258.  
  259. end
  260.  
  261. #==============================================================================
  262. # MOLEGATO TAG METHODS
  263. #------------------------------------------------------------------------------
  264. # Several methods for using tags. Needed by some of my scripts.
  265. #==============================================================================
  266.  
  267. module MOLEGATO_TAG_METHODS
  268. def has_tag?(tag)
  269. if self.note[/<#{tag}>/mi]
  270. return true
  271. else
  272. return false
  273. end
  274. end
  275.  
  276. def tag_check_value(tag)
  277. if self.note[/<#{tag}: (.*?)>/mi]
  278. return $1
  279. else
  280. return false
  281. end
  282. end
  283.  
  284. def tag_check_multivalues_note(tag)
  285. if self.note[/<#{tag}: (.*?)>/mi]
  286. return $1.split(',')
  287. else
  288. return false
  289. end
  290. end
  291.  
  292. def tag_check_multivalues(string, tag)
  293. if string[/<#{tag}: (.*?)>/mi]
  294. return $1.split(',')
  295. else
  296. return false
  297. end
  298. end
  299.  
  300. def tag_get_block(tag)
  301. if self.note[/<#{tag}>(.*?)<\\#{tag}>/mi]
  302. return $1
  303. else
  304. return false
  305. end
  306. end
  307.  
  308. def tag_multiple(tag)
  309. if tag_get_block(tag)
  310. var=tag_get_block(tag)
  311. return var.split(';')
  312. else
  313. return false
  314. end
  315. end
  316.  
  317. def tag_check_multiple_multivalues(tag)
  318. if tag_multiple(tag)
  319. array=[]
  320. tag_multiple(tag).each do |each|
  321. array.push(tag_check_multivalues(each,tag))
  322. end
  323. return array
  324. else
  325. return false
  326. end
  327. end
  328.  
  329. end
  330.  
  331. #---For items/skills/actors/etc
  332. class RPG::BaseItem
  333. include MOLEGATO_TAG_METHODS
  334. end
  335.  
  336. #---for maps
  337. class RPG::Map
  338. include MOLEGATO_TAG_METHODS
  339. end
  340.  
  341. #---for events
  342. class Game_Event < Game_Character
  343. include MOLEGATO_TAG_METHODS
  344. end
Advertisement
Add Comment
Please, Sign In to add comment