Module: Lotu::Drawable

Defined in:
lib/lotu/behaviors/drawable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(instance) ⇒ Object



4
5
6
# File 'lib/lotu/behaviors/drawable.rb', line 4

def self.extended(instance)
  instance.init_behavior
end

Instance Method Details

#dieObject



55
56
57
58
# File 'lib/lotu/behaviors/drawable.rb', line 55

def die
  super
  @parent.draw_queue.delete(self)
end

#drawObject



50
51
52
53
# File 'lib/lotu/behaviors/drawable.rb', line 50

def draw
  super
  @image.draw_rot(@x, @y, @z, @angle, @center_x, @center_y, @factor_x, @factor_y, @color, @mode) unless @image.nil?
end

#draw_meObject



37
38
39
# File 'lib/lotu/behaviors/drawable.rb', line 37

def draw_me
  @parent.draw_queue << self unless @parent.draw_queue.include?(self)
end

#imageObject



41
42
43
# File 'lib/lotu/behaviors/drawable.rb', line 41

def image
  @image
end

#init_behaviorObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lotu/behaviors/drawable.rb', line 8

def init_behavior
  class << self
    attr_accessor :z, :angle, :center_x, :center_y,
    :factor_x, :factor_y, :color, :mode
  end

  default_opts = {
    :z => 0,
    :angle => 0.0,
    :center_x => 0.5,
    :center_y => 0.5,
    :factor_x => 1.0,
    :factor_y => 1.0,
    :color => 0xffffffff,
    :mode => :default
  }
  @opts = default_opts.merge!(@opts)

  @image = nil
  @z = @opts[:z]
  @angle = @opts[:angle]
  @center_x = @opts[:center_x]
  @center_y = @opts[:center_y]
  @factor_x = @opts[:factor_x]
  @factor_y = @opts[:factor_y]
  @color = @opts[:color]
  @mode = @opts[:mode]
end

#set_image(image) ⇒ Object



45
46
47
48
# File 'lib/lotu/behaviors/drawable.rb', line 45

def set_image(image)
  @image = @parent.image(image)
  draw_me
end