Class: ExplosionGraphics

Inherits:
Component show all
Defined in:
lib/entities/components/explosion_graphics.rb

Constant Summary collapse

FRAME_DELAY =

ms

16.66

Instance Attribute Summary

Attributes inherited from Component

#object

Instance Method Summary collapse

Constructor Details

#initialize(game_object) ⇒ ExplosionGraphics

Returns a new instance of ExplosionGraphics.



4
5
6
7
# File 'lib/entities/components/explosion_graphics.rb', line 4

def initialize(game_object)
  super
  @current_frame = 0
end

Instance Method Details

#draw(viewport) ⇒ Object



9
10
11
12
13
14
15
# 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

#updateObject



17
18
19
20
21
22
23
24
25
# 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