Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.92 KB | None | 0 0
  1. =begin
  2.  
  3. Particle Engine
  4. by arevulopapo
  5. port by PK8
  6. Created: 11/15/2007
  7. Modified: 5/9/2012 - 5/12/2012
  8. Ported: 5/10/2012 (VX), 5/12/2012 (Ace)
  9. ──────────────────────────────────────────────────────────────────────────────
  10. ■ Introduction
  11. This script lets you create particle effects in your game. Particles are
  12. integrated into "Spriteset_Map", so the can be displayed over/under an event.
  13. ──────────────────────────────────────────────────────────────────────────────
  14. ■ Methods Aliased
  15. Spriteset_Map.initialize
  16. Spriteset_Map.update
  17. Spriteset_Map.dispose
  18. ──────────────────────────────────────────────────────────────────────────────
  19. ■ Thanks
  20. mobychan for helping out and pointing me to Archeia's RPG Maker VX's Ace
  21. tips and tricks page, which talked about how events set to parallel process
  22. need to be put in a loop in order for them to keep animating while events
  23. are being interacted with.
  24. ──────────────────────────────────────────────────────────────────────────────
  25. ■ Usage
  26. Effects are called from "Script" command like this:
  27. particle_effect(EVENT_ID, EFFECT, LOCK, X, Y)
  28. EVENT_ID - ID of an event the particles will flow from.
  29. -7/"follower3" for Follower 3
  30. -6/"follower2" for Follower 2
  31. -5/"follower1" for Follower 1
  32. -4/"airship" for Airship.
  33. -3/"ship" for Ship.
  34. -2/"boat" for Boat.
  35. -1/"player" for Player.
  36. 1 and above for Events.
  37. * Use @event_id for "This Event"
  38. * Use an array to specify multiple IDs.
  39. EFFECT - name of the effect to call. Names are defined in the
  40. Spriteset_Map. (Find: case effect)
  41. * Use an array to specify multiple effects.
  42. LOCK - alignment of the particles. 'event' to align particles
  43. with event's map position, 'screen' to align with event's
  44. screen position.
  45. For static events, like fireplaces, teleports, etc.
  46. 'event' alignment is recommended.
  47. For moving events use 'screen' mode.
  48. X, Y - number of pixels that will be added to the event's position
  49. to determine the starting point of particles.
  50. That's your most powerful weapon. See the demo for examples.
  51. * Use an array to specify multiple X/Y coordinates.
  52. ──────────────────────────────────────────────────────────────────────────────
  53. ■ Port Modifications
  54. o Added shortcuts within the script calls. You can now use arrays in
  55. EVENT_ID, EFFECT, X, and Y to set more events, effects, and coordinates.
  56. o Users can now set particles onto vehicles by setting EVENT_ID to "boat",
  57. "ship", and "airship".
  58.  
  59. =end
  60.  
  61. #==============================================================================
  62. # ** Spriteset_Map
  63. #------------------------------------------------------------------------------
  64. # This class brings together map screen sprites, tilemaps, etc. It's used
  65. # within the Scene_Map class.
  66. #==============================================================================
  67.  
  68. class Spriteset_Map
  69. #--------------------------------------------------------------------------
  70. # * Add Effect
  71. #--------------------------------------------------------------------------
  72. def add_effect(event=1, effect='', lock='event', x=0, y=0)
  73. # Case: Event
  74. event = event.downcase.gsub(/\s+/, "") if event.is_a?(String)
  75. case event
  76. when -20, "follower16"; object = $game_player.followers[15]
  77. when -19, "follower15"; object = $game_player.followers[14]
  78. when -18, "follower14"; object = $game_player.followers[13]
  79. when -17, "follower13"; object = $game_player.followers[12]
  80. when -16, "follower12"; object = $game_player.followers[11]
  81. when -15, "follower11"; object = $game_player.followers[10]
  82. when -14, "follower10"; object = $game_player.followers[9]
  83. when -13, "follower9"; object = $game_player.followers[8]
  84. when -12, "follower8"; object = $game_player.followers[7]
  85. when -11, "follower7"; object = $game_player.followers[6]
  86. when -10, "follower6"; object = $game_player.followers[5]
  87. when -9, "follower5"; object = $game_player.followers[4]
  88. when -8, "follower4"; object = $game_player.followers[3]
  89. when -7, "follower3"; object = $game_player.followers[2]
  90. when -6, "follower2"; object = $game_player.followers[1]
  91. when -5, "follower1"; object = $game_player.followers[0]
  92. when -4, "airship"; object = $game_map.airship
  93. when -3, "ship"; object = $game_map.ship
  94. when -2, "boat"; object = $game_map.boat
  95. when -1, "player"; object = $game_player
  96. else
  97. if event.is_a?(Integer); object = $game_map.events[event]
  98. else; object = event
  99. end
  100. end
  101. object = nil if object.is_a?(Game_Follower) and $game_player.vehicle != nil
  102.  
  103. #------------------------------------------------------------------------
  104. # Configuration
  105. #------------------------------------------------------------------------
  106. case effect
  107. # (sprite, acceleration[x,y], gravity[x,y], opacity[base,loss], blending)
  108. when 'blue'
  109. sprite='star_blue'
  110. add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
  111. when 'red'
  112. sprite='star_red'
  113. add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
  114. when 'green'
  115. sprite='star_green'
  116. add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
  117. when 'yellow'
  118. sprite='star_yellow'
  119. add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
  120. when 'smash'
  121. sprite='smash'
  122. add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
  123. when 'fire'
  124. sprite='particle_yellow'
  125. add_particles(object, x, y, sprite, [(rand(7)-3)*0.2, 0], [0,0.15], [255,8+rand(5)], lock, 1)
  126. when 'fire2'
  127. sprite='particle_orange'
  128. add_particles(object, x, y, sprite, [(rand(7)-3)*0.2, 0], [0,0.15], [255,8+rand(5)], lock, 1)
  129. when 'sparks'
  130. sprite='particle_red'
  131. add_particles(object, x, y, sprite, [0.5*(-25+rand(50))/10, -4], [0,-0.5], [255,20], lock, 1)
  132. when 'smoke'
  133. sprite='smoke'
  134. add_particles(object, x, y, sprite, [0.1*(-25+rand(50))/10, 0], [0,0.13], [128,3], lock, 1)
  135. when 'cells'
  136. sprite='particle_red'
  137. dx = 1.00*(-100 + rand(200))/100
  138. dy = 1.00*(-100 + rand(200))/100
  139. add_particles(object, x, y, sprite, [5*dx, 5*dy], [0.3*dx,0.3*dy],
  140. [255,10], lock, 1)
  141. #sines
  142. when 'black'
  143. sprite='star_sine'
  144. add_particles(object, x, y, sprite, [(rand(7)-3)*0.2, 0], [0,0.15],
  145. [255,8+rand(5)], lock, 1)
  146. #sines
  147. when 'portal'
  148. sprite='portal'
  149. add_particles(object, x, y, sprite, [(rand(2)-1)*0.2, 0], [0,0.1], [255,1+rand(10)], lock, 1)
  150. # Small Waterfalls # ---------------------------------------------------------------------------------------
  151. when 'waterfall_sml_1'
  152. sprite='waterfall1'
  153. add_particles(object, x, y+16, sprite, [0.1*(rand(4)-2)/10, 0], [0,-0.1], [255,4+rand(2)], lock, 1)
  154. when 'waterfall_sml_2'
  155. sprite='waterfall2'
  156. add_particles(object, x, y+16, sprite, [0.1*(rand(4)-2)/10, 0], [0,-0.1], [255,4+rand(2)], lock, 1)
  157. when 'waterfall_sml_3'
  158. sprite='waterfall3'
  159. add_particles(object, x, y+16, sprite, [0.1*(rand(4)-2)/10, 0], [0,-0.1], [255,4+rand(2)], lock, 1)
  160. end
  161. end
  162. #--------------------------------------------------------------------------
  163. # * Public Instance Variables
  164. #--------------------------------------------------------------------------
  165. attr_reader :particles
  166. #--------------------------------------------------------------------------
  167. # * Alias Listings
  168. #--------------------------------------------------------------------------
  169. alias :particle_ssm_init :initialize
  170. alias :particle_ssm_update :update
  171. alias :particle_ssm_dispose :dispose
  172. #--------------------------------------------------------------------------
  173. # * Object Initialization
  174. #--------------------------------------------------------------------------
  175. def initialize
  176. @particles = []
  177. particle_ssm_init
  178. end
  179. #--------------------------------------------------------------------------
  180. # * Dispose
  181. #--------------------------------------------------------------------------
  182. def dispose
  183. @particles.each{ |d| d.dispose }
  184. particle_ssm_dispose
  185. end
  186. #--------------------------------------------------------------------------
  187. # * Frame Update
  188. #--------------------------------------------------------------------------
  189. def update
  190. @particles.each_with_index{ |p,i|
  191. @particles[i].update
  192. if p.opacity == 0
  193. p.dispose
  194. @particles.delete_at(i)
  195. end
  196. }
  197. particle_ssm_update
  198. end
  199. #--------------------------------------------------------------------------
  200. # * Add Particles
  201. #--------------------------------------------------------------------------
  202. def add_particles(object = $game_player, x = 0, y = 0, sprite = '',
  203. acc = [0,0], grav = [0,0], opacity = [255,0], lock = 'event', blend = 0)
  204. if !object.is_a?(NilClass)
  205. if lock == 'event'
  206. @particles << Particle_Event.new(@viewport1, object, x, y, sprite, acc,
  207. grav, opacity, blend)
  208. elsif lock == 'screen'
  209. @particles << Particle_Screen.new(@viewport1, object, x, y, sprite, acc,
  210. grav, opacity, blend)
  211. end
  212. end
  213. end
  214. end
  215.  
  216. #===============================================================================​
  217. # ** Particle_Screen
  218. #===============================================================================​
  219.  
  220. class Particle_Screen < Sprite
  221. #--------------------------------------------------------------------------
  222. # * Object Initialization
  223. #--------------------------------------------------------------------------
  224. def initialize(viewport = Viewport.new(0,0,800,600), object = $game_player,
  225. x = 0, y = 0, sprite = '', acc = [0,0], grav = [0,0], opacity = [255,3],
  226. blend = 0)
  227. if !object.is_a?(NilClass)
  228. super(viewport)
  229. self.bitmap = Cache.picture('Particles/' + sprite)
  230. self.x = object.screen_x + x
  231. self.y = object.screen_y - 16 + y
  232. self.ox = self.oy = self.bitmap.width/2
  233. self.blend_type = blend
  234. self.opacity = opacity[0]
  235. @object = object
  236. @origin = [self.x, self.y]
  237. @acceleration = acc
  238. @gravity = grav
  239. @coords = [0.00, 0.00]
  240. @opacity = opacity[1]
  241. update
  242. end
  243. end
  244. #--------------------------------------------------------------------------
  245. # * Frame Update
  246. #--------------------------------------------------------------------------
  247. def update
  248. if !@object.is_a?(NilClass)
  249. @acceleration[0] -= @gravity[0] if @gravity[0] != 0
  250. @acceleration[1] -= @gravity[1] if @gravity[1] != 0
  251. @coords[0] += @acceleration[0]
  252. @coords[1] += @acceleration[1]
  253. self.opacity -= @opacity
  254. self.x = @origin[0] + @coords[0]
  255. self.y = @origin[1] + @coords[1]
  256. if self.y > (@object.screen_y - 16)
  257. self.z = @object.screen_z + 32
  258. else
  259. if @object == $game_map.airship; self.z = @object.screen_z + 120
  260. elsif @object.is_a?(Game_Follower); self.z = @object.screen_z + 1
  261. else
  262. self.z = @object.screen_z - 32
  263. end
  264. end
  265. end
  266. end
  267. end
  268.  
  269. #===============================================================================​
  270. # ** Particle_Event
  271. #===============================================================================​
  272.  
  273. class Particle_Event < Sprite
  274. #--------------------------------------------------------------------------
  275. # * Object Initialization
  276. #--------------------------------------------------------------------------
  277. def initialize(viewport = Viewport.new(0,0,800,600), object = $game_player,
  278. x = 0, y = 0, sprite = '', acc = [0,0], grav = [0,0], opacity = [255,3],
  279. blend = 0)
  280. if !object.is_a?(NilClass)
  281. super(viewport)
  282. self.bitmap = Cache.picture('Particles/' + sprite)
  283. self.x = object.x*32 + 16 - $game_map.display_x * 32 + x
  284. self.y = object.y*32 + 32 - $game_map.display_y * 32 + y
  285. self.ox = self.oy = self.bitmap.width/2
  286. self.blend_type = blend
  287. self.opacity = opacity[0]
  288. @object = object
  289. @origin = [object.x*32 + x + 16, object.y*32 + y + 32]
  290. @acceleration = acc
  291. @gravity = grav
  292. @coords = [0.00, 0.00]
  293. @opacity = opacity[1]
  294. update
  295. end
  296. end
  297. #--------------------------------------------------------------------------
  298. # * Frame Update
  299. #--------------------------------------------------------------------------
  300. def update
  301. if !@object.is_a?(NilClass)
  302. @acceleration[0] -= @gravity[0] if @gravity[0] != 0
  303. @acceleration[1] -= @gravity[1] if @gravity[1] != 0
  304. @coords[0] += @acceleration[0]
  305. @coords[1] += @acceleration[1]
  306. self.opacity -= @opacity
  307. self.x = @origin[0] + @coords[0] - $game_map.display_x * 32
  308. self.y = @origin[1] + @coords[1] - $game_map.display_y * 32 - 16
  309. if self.y > (@object.screen_y - 16)
  310. self.z = @object.screen_z + 40
  311. else
  312. self.z = @object.screen_z - 40
  313. end
  314. end
  315. end
  316. end
  317.  
  318. #==============================================================================
  319. # ** Scene_Map
  320. #------------------------------------------------------------------------------
  321. # This class performs the map screen processing.
  322. #==============================================================================
  323.  
  324. class Scene_Map < Scene_Base
  325. #--------------------------------------------------------------------------
  326. # * Public Instance Variables
  327. #--------------------------------------------------------------------------
  328. attr_reader :spriteset
  329. end
  330.  
  331. #==============================================================================
  332. # ** Game_Interpreter
  333. #------------------------------------------------------------------------------
  334. # An interpreter for executing event commands. This class is used within the
  335. # Game_Map, Game_Troop, and Game_Event classes.
  336. #==============================================================================
  337.  
  338. class Game_Interpreter
  339. #--------------------------------------------------------------------------
  340. # * Add effect
  341. #--------------------------------------------------------------------------
  342. def particle_effect(event=@event_id, effect='', lock='event', x=0, y=0)
  343. event, effect, x, y = Array(event), Array(effect), Array(x), Array(y)
  344. event.each{ |event_i| effect.each{ |effect_i| x.each{ |x_i| y.each{ |y_i|
  345. SceneManager.scene.spriteset.add_effect(event_i, effect_i, lock, x_i, y_i)
  346. } } } }
  347. end
  348. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement