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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
| # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
# FenixFyreX's Light Effects (FFXLFX)
# Version 1.0
# http://www.rpgmakervx.net
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
#
# To use this script, either make a preset then setup an event's comment like so:
#
# <prelfx string> OR <prelfx=string> OR <prelfx = string> # You get the idea.
#
# Where string is the name of the preset below,
# or setup an event's comment like so:
#
# <lfx opts>
#
# Where opts is any option defined below that you can put in a preset.
#
# fn = string # The filename of the image to use. Always pulls from Graphics/Lights.
# zx = number # The zoom x of the effect.
# zy = number # The zoom y of the effect.
# bl = number # Either 0(normal), 1(add), or 2(subtract).
# op = number # Anything from 0 to 255. Sets maximum opacity for effect.
# z = number # 0 is in front, the default. 1 is behind.
# s = number # Adheres to the light switch? 0 is false, 1 is true. Default is 1.
# fl = number # [n,n]. First n determines randomness of visibility. Second n
# determines the range of opacity change.
# cl = array # [n,n,n] or [n,n,n,n]. [red,green,blue,transparency].
# os = array # [x,y]. will offset the graphic by x,y.
# w = array # [n,n,n] or [n,n,n,n]. [strength,length,speed,phase].
#
# You must include filename if you make a direct light effect in a comment.
#
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
module FFXLFX
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
#
# Set up preset light fx here. the preset can be named anything as long as it
# is a string(e.g. within " ")
# Options for the preset are as follows; if a * is next to it, its mandatory:
#
# :filename * The name of the file in Graphics/Lights/
# :flicker Should the light flicker? Must be an array of two numbers.
# :zx Zoom X of the effect, 1 is default
# :zy Zoom Y of the effect, 1 is default
# :z Z coordinate of the effect. 0 is in front, 1 is behind.
# :blend 0 is normal, 1 is add, 2 is subtract
# :switch Adheres to the light switch? 0 is false, 1 is true. Default is 1.
# :color An array of 3-4 numbers, like so: [155,100,0] # Yellow
# To make a random color, put -1 in the color index spot, so
# a fully random color would be [-1,-1,-1]
# :offset An array of two numbers. [-1,1] will offset the image left
# and down one pixel.
# :opacity Anything from 0 to 255. Sets maximum opacity for the effect.
# :wave An array of 3-4 numbers, [amp, length, speed, phase]
#
# :wave makes the image wiggle. Use the help file for further information on
# wave effects. Look up Sprite in the help file.
Presets = { # do NOT delete this.
# -=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=- #
# Preset 1: Ground
# -=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=- #
"Ground" => {
:filename => "ground",
:flicker => [200,100],
:zx => 4,
:zy => 4,
:blend => 1,
:color => [155,100,0],
},
# -=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=- #
# Preset 2: Lantern
# -=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=- #
"Lantern" => {
:filename => "lantern",
:flicker => [500,100],
:zx => 1,
:zy => 1,
:blend => 1,
:color => [190,100,0],
:offset => [0,0],
},
# -=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=- #
# Preset 3: Lightbug
# -=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=- #
"Lightbug" => {
:filename => "ground",
:flicker => [500,200],
:zx => 1,
:zy => 1,
:z => 0,
:blend => 1,
:color => [-1,-1,-1],
:offset => [0,-6],
:switch => 0,
},
# -=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=- #
# Preset 4: Headstone
# -=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=- #
"Ghost" => {
:filename => "ghost",
:flicker => [0,0],
:zx => 2,
:zy => 2,
:blend => 1,
:color => [-1,-1,-1],
:offset => [0,-16],
:opacity => -170,
:wave => [2,5,1],
},
# -=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=- #
# Preset 5: Fireplace
# -=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=- #
"Fireplace" => {
:filename => "fireplace",
#~ :flicker => [100,200],
#~ :blend => 0,
:z => 0,
},
# -=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=--=- #
} # DO NOT DELETE THIS
# The switch that turns the whole system on or off. If on, the system will be off.
On_Off_Switch = 1
# This number determines the speed at which light effects fade on and off.
# Higher numbers result in faster fading.
Fade_Time = 3
end
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
# DO NOT EDIT FURTHER UNLESS YOU KNOW WHAT YOU ARE DOING.
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
module Cache
def self.lights(filename)
load_bitmap("Graphics/Lights/",filename)
end
end
class Sprite
def start_wave(amp,speed,length,phase=nil)
self.wave_amp = amp
self.wave_speed = speed
self.wave_length = length
self.wave_phase = phase.to_i unless phase.nil?
end
end
class Game_Event < Game_Character
def name
return @event.name
end
def light
rgxp = /<lfx[ ]*[=]?/i
rgxp2 = /<prelfx[ ]*[=]?[ ]*(.*)>/i
return if @page.nil?
@page.list.each do |item|
if [108,408].include?(item.code)
if item.parameters[0] =~ rgxp2
txt = $1.to_s
return new_prelight(txt)
elsif item.parameters[0] =~ rgxp
txt = item.parameters[0]
ind = @page.list.index(item)+1
loop do
if [408,108].include?(@page.list[ind].code)
txt += @page.list[ind].parameters[0]
break if txt.include?(">")
else
break
end
end
cache = parse_lfx(txt)
return new_light(cache)
end
end
end
return nil
end
def parse_lfx(txt="")
cache = {}
ary = txt.split(";")
ary.each do |item|
case item
when /fn[ ]*[=]?[ ]*(.*)/i
cache[:filename] = $1.to_s.gsub(">","")
when /fl[ ]*[=]?[ ]*\[[ ]*(\d+)[ ]*,[ ]*(\d+)\][>]?/i
cache[:flicker] = $1.to_i
when /zx[ ]*[=]?[ ]*(\d+)[>]?/i
cache[:zx] = $1.to_i
when /zy[ ]*[=]?[ ]*(\d+)[>]?/i
cache[:zy] = $1.to_i
when /z[ ]*[=]?[ ]*(0|1)[>]?/i
cache[:z] = ($1.to_i == 1)
when /a[ ]*[=]?[ ]*(0|1)[>]?/i
cache[:switch] = ($1.to_i == 1)
when /bl[ ]*[=]?[ ]*(0|1|2)[>]?/i
cache[:blend] = $1.to_i
when /op[ ]*[=]?[ ]*(\d+)[>]?/i
cache[:opacity] = $1.to_i
when /cl[ ]*[=]?[ ]*\[[ ]*(\d+)[ ]*,[ ]*(\d+)[ ]*,[ ]*(\d+)[ ]*[,]?[ ]*(\d+)?\][>]?/i
cache[:color] = [$1.to_i,$2.to_i,$3.to_i]
cache[:color] << $4.to_i unless $4.nil?
when /os[ ]*[=]?[ ]*\[[ ]*([-]?\d+)[ ]*,[ ]*([-]?\d+)\][>]?/i
cache[:offset] = [$1.to_i,$2.to_i]
when /w[ ]*[=]?[ ]*\[[ ]*(\d+)[ ]*,[ ]*(\d+)[ ]*,[ ]*(\d+)[ ]*[,]?[ ]*(\d+)?\][>]?/i
cache[:wave] = [$1.to_i,$2.to_i,$3.to_i]
cache[:wave] << $4.to_i unless $4.nil?
end
end
return cache
end
def new_light(cache)
s = Sprite_Light.new(self)
s.setup(cache)
return s
end
def new_prelight(nam)
cache = FFXLFX::Presets[nam]
return nil unless FileTest.exist?("Graphics/Lights/"+cache[:filename]+".png")
s = Sprite_Light.new(self)
s.setup(cache)
return s
end
def on_screen?
return true if self.x.between?(-1,Graphics.width+1) && self.y.between?(-1,Graphics.height+1)
return false
end
end
class Spriteset_Map
attr_accessor :lightfxs
alias init_lightfxs initialize unless $@
def initialize(*args, &block)
@lightfxs = []
@refresh_lightz = nil
init_lightfxs(*args, &block)
setup_lightz
update_lightz
end
def setup_lightz
dispose_lightz
@lightfxs = []
$game_map.events.values.each do |i|
@lightfxs[i.id] = i.light
unless @lightfxs[i.id].nil? or @lightfxs[i.id].disposed?
@lightfxs[i.id].opacity = 0
@lightfxs[i.id].fadein
end
end
end
alias update_lightfxs update unless $@
def update(*args, &block)
update_lightfxs(*args, &block)
update_lightz
end
def show_lightz?
return true if $game_switches[FFXLFX::On_Off_Switch]
return false
end
def player_lfx(preset)
cache = FFXLFX::Presets[nam]
return nil if cache[:filename].nil?
s = Sprite_Light.new($game_player)
s.setup(cache)
@lightfxs[$game_map.events.values.size] = s
end
alias dispose_lightfxs dispose unless $@
def dispose(*args, &block)
dispose_lightz
dispose_lightfxs(*args, &block)
end
def update_lightz
unless @refresh_lightz.nil?
@refresh_lightz -= 1
if @refresh_lightz <= 0
@refresh_lightz = nil
setup_lightz
end
end
if show_lightz? && @lightfxs.size == 0
setup_lightz
elsif !show_lightz?
@lightfxs.each do |s|
next if s.nil? or s.disposed?
s.fadeout
end
end
@lightfxs.each do |s| s.update unless s.nil? or s.disposed? end
end
def dispose_lightz
@lightfxs.each do |s| s.dispose unless s.nil? or s.disposed? end
@lightfxs = []
end
def refresh_lightz
@refresh_lightz = 30
end
end
class Sprite_Light < Sprite_Base
attr_accessor :flicker, :offset
attr_reader :cache
def initialize(event)
@cache = {}
@event = event
@flicker = nil
@offset = [0,0]
@fadein = false
@fadeout = false
super(nil)
set_xyz
end
def setup(cache={})
@cache = cache
self.bitmap = Cache.lights(cache[:filename]).clone
self.flicker = cache[:flicker] unless cache[:flicker].nil?
self.zoom_x = cache[:zx] unless cache[:zx].nil?
self.zoom_y = cache[:zy] unless cache[:zy].nil?
unless cache[:color].nil?
self.color = Color.new(*cache[:color])
self.color.red = rand(256) if cache[:color][0] == -1
self.color.green = rand(256) if cache[:color][1] == -1
self.color.blue = rand(256) if cache[:color][2] == -1
end
self.blend_type = cache[:blend] unless cache[:blend].nil?
self.offset = cache[:offset] unless cache[:offset].nil?
self.start_wave(*cache[:wave]) unless cache[:wave].nil?
end
def max_opacity
result = 150
result = @cache[:opacity] unless @cache[:opacity].nil?
return result
end
def update
set_xyz
return if !@event.on_screen?
super
fade_time = FFXLFX::Fade_Time
if @fadein
self.opacity = [[self.opacity+fade_time,0].max, max_opacity].min
if self.opacity >= max_opacity
self.opacity = max_opacity
@fadein = false
else
return
end
elsif @fadeout
self.opacity -= fade_time
if self.opacity == 0
@fadeout = false
else
return
end
end
return if !show_lightz?
if !@flicker.nil?
self.visible = (rand(@flicker[0]) != @flicker[0]-1)
self.opacity = 255-rand(@flicker[1])
self.opacity = max_opacity if self.opacity > max_opacity
else
self.visible = true
self.opacity = max_opacity
end
end
def fadein
@fadeout = false
@fadein = true
end
def fadeout
return if @cache[:switch]
@fadein = false
@fadeout = true
end
def set_xyz
a = (@event.screen_x.to_f)
b = (@event.screen_y.to_f)
a -= 16+((self.zoom_x-1)*self.width/2)
b -= 32+((self.zoom_y-1)*self.height/2)
if self.width > 32
n1 = (self.width - 32) / 2
a -= n1
elsif self.width < 32
n1 = (32 - self.width) / 2
a += n1
end
if self.height > 32
n2 = (self.height - 32) / 2
b -= n2
elsif self.height < 32
n2 = (32 - self.height) / 2
b += n2
end
a += @offset[0]
b += @offset[1]
self.x = a
self.y = b
fz = @event.screen_z
if @cache[:z]
fz -= 1
else
fz += 1
end
self.z = fz
end
def show_lightz?
return true if $game_switches[FFXLFX::On_Off_Switch]
return false
end
end
class Game_Interpreter
def lfx_player(preset)
if $scene.is_a?(Scene_Map)
$scene_map.player_lfx(preset) if FFXLFX::Presets.keys.include?(preset)
end
end
def refresh_lightfxs
$scene.refresh_lightfxs
end
end
class Scene_Map
def player_lfx(preset)
@spriteset.player_lfx(preset)
end
def refresh_lightfxs
@spriteset.refresh_lightz
end
end |