generated from DragonRidersUnite/scale
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
234 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
module FireworksEffect | ||
DISSOLVE_SPEED = 2 | ||
class << self | ||
def emit_particle(sys) | ||
{ | ||
x: sys.x + rand(20), | ||
y: sys.y + rand(20), | ||
w: 1, | ||
h: 1, | ||
angle: 0, | ||
dir: rand(360), | ||
r: rand(255), g: rand(255), b: rand(255), a: 150, | ||
path: :pixel, | ||
blendmode_enum: 2 | ||
} | ||
end | ||
|
||
def tick(particle, sys) | ||
sys.particles.delete particle if dead_particle? particle | ||
|
||
particle.x += 1.5 * (Math.cos(particle.dir * DEG2RAD) - 1) / DISSOLVE_SPEED | ||
particle.y += 1.5 * (Math.sin(particle.dir * DEG2RAD) - 1) / DISSOLVE_SPEED | ||
particle.angle += (particle.dir < 180) ? -0.5 : 0.5 | ||
particle.h += 2 / DISSOLVE_SPEED | ||
particle.w += 2 / DISSOLVE_SPEED | ||
particle.a -= DISSOLVE_SPEED | ||
end | ||
|
||
def dead_particle?(particle) | ||
particle.a <= 0 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module SmokeEffect | ||
DISSOLVE_SPEED = 2 | ||
class << self | ||
def emit_particle(sys) | ||
color = random(150,255) | ||
puts "dir: #{sys.dir + rand(180) - 90}" | ||
{ | ||
x: sys.x, | ||
y: sys.y, | ||
w: 8, | ||
h: 8, | ||
angle: 0, | ||
dir: sys.dir + rand(180) - 90, | ||
r: color, g: color, b: color, a: 150, | ||
path: Sprite::SPRITES[:bullet], | ||
blendmode_enum: 2 | ||
} | ||
end | ||
|
||
def tick(particle, sys) | ||
sys.particles.delete particle if dead_particle? particle | ||
|
||
particle.x += (Math.cos(particle.dir * DEG2RAD)) *1.2 | ||
particle.y += (Math.sin(particle.dir * DEG2RAD)) *1.2 | ||
particle.angle += [-5, 5].sample | ||
particle.h -= 0.1 | ||
particle.w -= 0.1 | ||
particle.a -= 5 | ||
end | ||
|
||
def dead_particle?(particle) | ||
particle.a <= 0 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module ParticleSystem | ||
class << self | ||
def create(effect, x:, y:, w: 1, h: 1, rate: 20, dir: 0, duration: nil) | ||
{ | ||
effect: effect, # effect is a module that implements the Effect interface Eg: app/smoke_effect.rb | ||
rate: rate, | ||
x: x, | ||
y: y, | ||
w: w, | ||
h: h, | ||
dir: dir, | ||
duration: duration, | ||
ticks_since_last_emission: 0, | ||
particles: [] | ||
} | ||
end | ||
|
||
def tick(args, sys) | ||
sys.duration -= 1 if sys.duration | ||
|
||
sys.particles.each { sys.effect.tick _1, sys } | ||
|
||
if emit? sys | ||
# rate: 5 => 12 pps; 0.2 => 300 pps. If ticks_per_emision < 1, multiple particles will be emitted in a single tick | ||
ticks_per_emission = 60.fdiv(sys.rate) | ||
|
||
# count ticks until we reach a tick where we should emit a particle. | ||
sys.ticks_since_last_emission += 1 | ||
particles_to_emit = (sys.ticks_since_last_emission / ticks_per_emission).floor | ||
|
||
if particles_to_emit > 0 | ||
particles_to_emit.times { |i| sys.particles << sys.effect.emit_particle(sys) } | ||
sys.ticks_since_last_emission = 0 | ||
end | ||
end | ||
end | ||
|
||
def emit? sys | ||
true if sys.duration.nil? | ||
sys.duration > 0 | ||
end | ||
|
||
def dead? sys | ||
sys.duration <= 0 && sys.particles.empty? | ||
end | ||
|
||
def destroy(sys) | ||
sys.particles = [] | ||
end | ||
end | ||
end |
Oops, something went wrong.