module RPG
module Cache
def self.particles(filename, hue)
self.load_bitmap("Graphics/Particles/", filename, hue)
end
end
end
class ParticleEffect
class Particle < RPG::Sprite
attr_accessor :accel_x
attr_accessor :accel_y
def initialize(accel_x, accel_y, viewport = Viewport.new(0, 0, 640, 480))
super(viewport)
@accel_x = accel_x
@accel_y = accel_y
end
end
attr_reader :particles
def initialize(name, max, hue, add_hue, duration, opacity, start_x, start_y, speed,
accel_x, accel_y, x_grav, y_grav, blend, mag = 0)
@name = name
@max = max
@hue = hue
@add_hue = add_hue
@hi_opacity = opacity
@duration = duration
@start_x = start_x
@start_y = start_y
@speed = speed
@start_accel_x = accel_x
@start_accel_y = accel_y
@x_grav = x_grav
@y_grav = y_grav
@mag = mag
@screen = [0, 0, 640, 480]
@particles = []
for i in 0...@max
@particles[i] = Particle.new(@start_accel_x + @speed * (rand(10)-5),
@start_accel_y + @speed * (rand(10)-5))
@particles[i].zoom_x = 0.5 * @mag + 0.5
@particles[i].zoom_y = 0.5 * @mag + 0.5
@particles[i].bitmap = RPG::Cache.particles(@name, @hue)
@particles[i].blend_type = blend
@particles[i].x = @start_x
@particles[i].y = @start_y
@particles[i].opacity = @hi_opacity
end
end
def update
for i in 0...@particles.compact.size
next unless @particles[i]
@hue = 0 if @hue == 360
@hue += @add_hue
@particles[i].bitmap = RPG::Cache.particles(@name, @hue)
@particles[i].accel_x -= @x_grav
@particles[i].x += @particles[i].accel_x
@particles[i].accel_y -= @y_grav
@particles[i].y += @particles[i].accel_y
@particles[i].opacity -= (@hi_opacity / @duration).ceil
if @particles[i].opacity <= 0
@particles[i].dispose
@particles[i] = nil
@particles.compact
next
end
end
end
end
class Scene_Map
attr_accessor :particles
alias prex_particles_s_map_update update
def initialize
@particles = []
end
def update
prex_particles_s_map_update
for particle in @particles
next unless particle
particle.update
particle.dispose if particle.particles.size <= 0
end
end
def add_effect(id)
case id
when 'sign01'
@particles.push(ParticleEffect.new("sign01", 5, 0, 0, 25, 200, $particle_x-53, $particle_y-53, 1, 0, 0, 0, 0, 1))
when 'sign02'
@particles.push(ParticleEffect.new("sign02", 5, 0, 0, 25, 200, $particle_x-53, $particle_y-53, 1, 0, 0, 0, 0, 1))
when 'sign03'
@particles.push(ParticleEffect.new("sign03", 5, 0, 0, 25, 200, $particle_x-53, $particle_y-53, 1, 0, 0, 0, 0, 1))
when 'sign04'
@particles.push(ParticleEffect.new("sign04", 15, 0, 0, 25, 255, $particle_x-8, $particle_y-24, 1, 0, 0, 0, 0, 1))
when 'fire'
@particles.push(ParticleEffect.new("fire", 15, 45, 0, 15, 200, $particle_x-6, $particle_y-24, 0.3, 0, 0, -0.1, 0.1, 1))
when 'rainbow'
@particles.push(ParticleEffect.new("fire", 15, 45, 2, 35, 255, $particle_x-4, $particle_y-24, 1, 0, 0, 0, 0, 1))
when 'sparks'
@particles.push(ParticleEffect.new("fire", 25, 60, 0, 15, 255, $particle_x-4, $particle_y-24, 1, 0, -1, 0, -0.5, 1))
when 'smoke'
@particles.push(ParticleEffect.new("smoke", 10, 0, 0, 15, 64, $particle_x-6, $particle_y-24, 0.1, 1, -1, 0.1, 0.1, 1))
when 'campfire'
@particles.push(ParticleEffect.new("fire", 15, 45, 0, 15, 200, $particle_x-6, $particle_y-24, 0.2, 0, 0, -0.1, 0.1, 1))
@particles.push(ParticleEffect.new("smoke", 10, 0, 0, 15, 128, $particle_x-6, $particle_y-32, 0.1, 1, -1, 0.1, 0.1, 1))
when 'candle'
@particles.push(ParticleEffect.new("fire", 1, 60, 0, 10, 250, $particle_x - 5, $particle_y - 18, 0, 0, 0, 0, 0.2, 1))
when 'mist'
@particles.push(ParticleEffect.new("star", 5, 0, 0, 15, 128, $particle_x-32, $particle_y-48, 1, 0, 0, 0, 0, 1))
when 'darkness'
@particles.push(ParticleEffect.new("star", 5, 0, 0, 15, 128, $particle_x-32, $particle_y-48, 1, 0, 0, 0, 0, 2))
@particles.push(ParticleEffect.new("fire", 2, 60, 0, 15, 250, $particle_x-4, $particle_y - 32, 0.2, 0, 0, 0, 0, 1, 1))
when 'aura'
@particles.push(ParticleEffect.new("fire", 5, 0, 4, 15, 250, $particle_x-4, $particle_y - 8, 0.2, 0.1, 0.1, -0.1, 0.2, 1))
when 'portal'
@particles.push(ParticleEffect.new("wideportal", 1, 270, 0, 20, 200, $particle_x - 32, $particle_y - 48, 0, 0, -2, 0, 0.2, 1, 1))
end
end
end