Module: Chingu::Traits::Effect

Defined in:
lib/chingu/traits/effect.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fadingObject

Adds .rotating .fading and .zooming to any GameObject.

TODO: better naming? suggestions:

basic gosu unit <-> automation name

angle <-> rotation? rotating? automatic_angle? factor <-> growth? scale? automatic_zoom? alpha <-> fade



37
38
39
# File 'lib/chingu/traits/effect.rb', line 37

def fading
  @fading
end

#rotatingObject

Adds .rotating .fading and .zooming to any GameObject.

TODO: better naming? suggestions:

basic gosu unit <-> automation name

angle <-> rotation? rotating? automatic_angle? factor <-> growth? scale? automatic_zoom? alpha <-> fade



37
38
39
# File 'lib/chingu/traits/effect.rb', line 37

def rotating
  @rotating
end

#zoomingObject

Adds .rotating .fading and .zooming to any GameObject.

TODO: better naming? suggestions:

basic gosu unit <-> automation name

angle <-> rotation? rotating? automatic_angle? factor <-> growth? scale? automatic_zoom? alpha <-> fade



37
38
39
# File 'lib/chingu/traits/effect.rb', line 37

def zooming
  @zooming
end

Instance Method Details

#draw_traitObject



58
59
60
61
# File 'lib/chingu/traits/effect.rb', line 58

def draw_trait
  puts "Effect#draw"      if @effect_options[:debug]
  super
end

#fade(amount = 1) ⇒ Object

Fade object by decreasing/increasing color.alpha



90
91
92
93
94
95
96
97
98
99
# File 'lib/chingu/traits/effect.rb', line 90

def fade(amount = 1)
  return if amount == 0
      
  new_alpha = @color.alpha + amount
  if amount < 0
    @color.alpha =  [0, new_alpha].max
  else
    @color.alpha =  [0, new_alpha].min
  end
end

#fade_in(amount = 1) ⇒ Object

Fade in objects color by increasing color.alpha



107
108
109
# File 'lib/chingu/traits/effect.rb', line 107

def fade_in(amount = 1)
  fade(amount)
end

#fade_out(amount = 1) ⇒ Object

Fade out objects color by decreasing color.alpha



102
103
104
# File 'lib/chingu/traits/effect.rb', line 102

def fade_out(amount = 1)
  fade(-amount)
end

#rotate(amount = 1) ⇒ Object

Rotate object ‘amount’ degrees



85
86
87
# File 'lib/chingu/traits/effect.rb', line 85

def rotate(amount = 1)
  @angle += amount
end

#setup_trait(options) ⇒ Object

Setup



48
49
50
51
52
53
54
55
56
# File 'lib/chingu/traits/effect.rb', line 48

def setup_trait(options)
  @effect_options = {:debug => false}.merge(options)
  puts "Effect#setup"     if @effect_options[:debug]
  
  @rotating = options[:rotating] || nil
  @zooming = options[:zooming] || nil
  @fading = options[:fading] || nil
  super
end

#update_traitObject



63
64
65
66
67
68
69
70
# File 'lib/chingu/traits/effect.rb', line 63

def update_trait
  puts "Effect#update"    if @effect_options[:debug]
  
  rotate(@rotating)    if @rotating
  fade(@fading)        if @fading
  zoom(@zooming)       if @zooming
  super
end

#zoom(amount = 0.1) ⇒ Object

Zoom - increase @factor_x and @factor_y at the same time.



73
74
75
76
# File 'lib/chingu/traits/effect.rb', line 73

def zoom(amount = 0.1)
  @factor_x += amount
  @factor_y += amount
end

#zoom_out(amount = 0.1) ⇒ Object

Zoom Out - decrease @factor_x and @factor_y at the same time.



79
80
81
82
# File 'lib/chingu/traits/effect.rb', line 79

def zoom_out(amount = 0.1)
  @factor_x -= amount
  @factor_y -= amount
end