mirror of
https://github.com/SleepingInsomniac/asteroids
synced 2024-12-25 21:59:23 +01:00
Fix explosions
This commit is contained in:
parent
0d1592bf03
commit
a5aec01b6a
6 changed files with 21 additions and 13 deletions
|
@ -99,7 +99,7 @@ class Asteroids < Game
|
|||
bullet.position = wrap(bullet.position)
|
||||
end
|
||||
|
||||
@bullets = @bullets.reject { |b| b.age >= 4.0 }
|
||||
@bullets = @bullets.reject(&.dead?)
|
||||
@asteroids.each do |a|
|
||||
a.update(dt)
|
||||
a.position = wrap(a.position)
|
||||
|
|
|
@ -3,8 +3,11 @@ require "./lx_game/sprite/age"
|
|||
class Bullet < Sprite
|
||||
include LxGame::SpriteAge
|
||||
|
||||
@lifespan = 4.0
|
||||
|
||||
def update(dt)
|
||||
super
|
||||
update_age(dt)
|
||||
return if dead?
|
||||
update_position(dt)
|
||||
end
|
||||
|
||||
|
|
|
@ -2,4 +2,9 @@ require "./lx_game/sprite/age"
|
|||
|
||||
class Explosion < LxGame::Emitter
|
||||
include LxGame::SpriteAge
|
||||
|
||||
def update(dt)
|
||||
update_age(dt)
|
||||
super
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ module LxGame
|
|||
property max_age : Float64 = 1.0
|
||||
property emit_freq : Float64 = 0.05
|
||||
property strength : Float64 = 50.0
|
||||
@last_emitted : Float64 = 0.0
|
||||
getter last_emitted : Float64 = 0.0
|
||||
property emit_angle : Float64 = 2 * Math::PI
|
||||
property size : Float64 = 0.0
|
||||
|
||||
|
@ -41,7 +41,7 @@ module LxGame
|
|||
end
|
||||
|
||||
@particles.each { |particle| particle.update(dt) }
|
||||
@particles.reject! { |particle| particle.dead? }
|
||||
@particles.reject!(&.dead?)
|
||||
end
|
||||
|
||||
def draw(renderer : SDL::Renderer)
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
require "./sprite"
|
||||
require "./sprite/age"
|
||||
|
||||
module LxGame
|
||||
class Particle < Sprite
|
||||
property age : Float64 = 0.0
|
||||
property lifespan : Float64 = 4.0
|
||||
@dead : Bool = false
|
||||
|
||||
def dead?
|
||||
@age >= @lifespan
|
||||
end
|
||||
include SpriteAge
|
||||
|
||||
def update(dt : Float64)
|
||||
update_age(dt)
|
||||
return if dead?
|
||||
update_position(dt)
|
||||
@age += dt
|
||||
end
|
||||
|
||||
def draw(renderer : SDL::Renderer)
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
module LxGame
|
||||
module SpriteAge
|
||||
property lifespan : Float64 = Float64::INFINITY
|
||||
property age : Float64 = 0.0
|
||||
|
||||
def update(dt : Float64)
|
||||
def dead?
|
||||
self.age >= self.lifespan
|
||||
end
|
||||
|
||||
def update_age(dt : Float64)
|
||||
self.age += dt
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue