Module: Petli::Pet::Animation
Instance Method Summary collapse
- #animation ⇒ Object
- #atlas ⇒ Object
- #avail_animations ⇒ Object
- #busy? ⇒ Boolean
- #celebrate ⇒ Object
- #embarass ⇒ Object
- #hatch ⇒ Object
- #light_switch ⇒ Object
- #react(action) ⇒ Object
- #reset ⇒ Object
- #setup_animation ⇒ Object
- #sleeping? ⇒ Boolean
- #update_animation ⇒ Object
Methods included from Tatty::DB::Attributes
Instance Method Details
#animation ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/petli/pet/animation.rb', line 60 def animation if self.dead? avail_animations[:death] elsif !@doing.nil? @doing elsif self.lights_out if sleeping? avail_animations[:sleep][:sleep] else avail_animations[:sleep][:blink] end elsif self.sick > 0 atlas[:walk_sick] else atlas["walk_#{self.mood}"] end end |
#atlas ⇒ Object
78 79 80 |
# File 'lib/petli/pet/animation.rb', line 78 def atlas avail_animations[phase][phase_select] end |
#avail_animations ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/petli/pet/animation.rb', line 82 def avail_animations @avail_animations ||= { hatch: Tatty::Anim.from_atlas(Petli.data_path('hatch.txtanim')), infant: Dir[Petli.data_path('infant',"*.txtanim")].map {|p| Tatty::Atlas.new(p) }, teen: Dir[Petli.data_path('teen',"*.txtanim")].map {|p| Tatty::Atlas.new(p) }, adult: Dir[Petli.data_path('adult',"*.txtanim")].map {|p| Tatty::Atlas.new(p) }, death: Tatty::Anim.from_atlas(Petli.data_path('death.txtanim')), sleep: Tatty::Atlas.new(Petli.data_path('sleep.txtanim')), } end |
#busy? ⇒ Boolean
28 29 30 |
# File 'lib/petli/pet/animation.rb', line 28 def busy? !@doing.nil? end |
#celebrate ⇒ Object
32 33 34 |
# File 'lib/petli/pet/animation.rb', line 32 def celebrate react(:celebrate) end |
#embarass ⇒ Object
36 37 38 |
# File 'lib/petli/pet/animation.rb', line 36 def react(:embarass) end |
#hatch ⇒ Object
40 41 42 |
# File 'lib/petli/pet/animation.rb', line 40 def hatch @doing = avail_animations[:hatch] end |
#light_switch ⇒ Object
44 45 46 47 |
# File 'lib/petli/pet/animation.rb', line 44 def light_switch self.lights_out = !lights_out self.happiness = [1, self.happiness-1].max if self.lights_out && !sleeping? end |
#react(action) ⇒ Object
54 55 56 57 58 |
# File 'lib/petli/pet/animation.rb', line 54 def react(action) anim = atlas[action] anim.reset @doing = anim end |
#reset ⇒ Object
24 25 26 |
# File 'lib/petli/pet/animation.rb', line 24 def reset @doing = nil end |
#setup_animation ⇒ Object
9 10 11 |
# File 'lib/petli/pet/animation.rb', line 9 def setup_animation hatch if (Time.now - self.birth) < 10 end |
#sleeping? ⇒ Boolean
49 50 51 52 |
# File 'lib/petli/pet/animation.rb', line 49 def sleeping? hour = Time.now.hour hour >= 16 || hour <= 8 end |
#update_animation ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/petli/pet/animation.rb', line 13 def update_animation reset if animation.step && !animation.loop if phase == :infant && hours_since(birth) > 1 self.phase = :teen self.phase_select = rand(0...avail_animations[phase].count) elsif phase == :teen && days_since(birth) > 1 self.phase = :adult self.phase_select = rand(0...avail_animations[phase].count) end end |