class ExplosionGraphics

Constants

FRAME_DELAY

Public Class Methods

new(game_object) click to toggle source
Calls superclass method Component::new
# File lib/entities/components/explosion_graphics.rb, line 4
def initialize(game_object)
  super
  @current_frame = 0
end

Public Instance Methods

draw(viewport) click to toggle source
# File lib/entities/components/explosion_graphics.rb, line 9
def draw(viewport)
  image = current_frame
  image.draw(
    x - image.width / 2 + 3,
    y - image.height / 2 - 35,
    20)
end
update() click to toggle source
# File lib/entities/components/explosion_graphics.rb, line 17
def update
  now = Gosu.milliseconds
  delta = now - (@last_frame ||= now)
  if delta > FRAME_DELAY
    @last_frame = now
  end
  @current_frame += (delta / FRAME_DELAY).floor
  object.mark_for_removal if done?
end

Private Instance Methods

animation() click to toggle source
# File lib/entities/components/explosion_graphics.rb, line 37
def animation
  @@animation ||=
  Gosu::Image.load_tiles(
    $window, Utils.media_path('explosion.png'),
    128, 128, false)
end
current_frame() click to toggle source
# File lib/entities/components/explosion_graphics.rb, line 29
def current_frame
  animation[@current_frame % animation.size]
end
done?() click to toggle source
# File lib/entities/components/explosion_graphics.rb, line 33
def done?
  @done ||= @current_frame >= animation.size
end