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