petli 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,80 @@
1
+ width: 11
2
+ height: 4
3
+ name: walk_great
4
+ loop: true
5
+ ---
6
+ | | | | | | | |
7
+ | (°‿° ) | | (°‿° ) | | ( °‿°) | | ( °‿°) |
8
+ (._.) | | (._.) | | (._.) | | (._.) | |
9
+ | | | | | | | |
10
+ ---
11
+ name: walk_happy
12
+ alias: walk_normal
13
+ ---
14
+ | | | | | | | |
15
+ | | | | | | | |
16
+ (._.) | (°.° ) | (._.) | (°.° ) | (._.) | ( °.°) | (._.) | ( °.°) |
17
+ | | | | | | | |
18
+ ---
19
+ name: walk_angry
20
+ alias: walk_annoyed
21
+ ---
22
+ | | | | | | | |
23
+ | | | | | | | |
24
+ (ಠ_ಠ) | (ᴗ.ᴗ ) | (ಠ_ಠ) | (ᴗ.ᴗ ) | (ಠ_ಠ) | ( ᴗ.ᴗ) | (ಠ_ಠ) | ( ᴗ.ᴗ) |
25
+ | | | | | | | |
26
+ ---
27
+ name: walk_sick
28
+ ---
29
+ | | | | | | | |
30
+ | | | | | | | |
31
+ (ළ_ළ) | (ತ.ತ ) | (ළ_ළ) | (ತ.ತ ) | (ළ_ළ) | ( ತ.ತ) | (ළ_ළ) | ( ತ.ತ) |
32
+ | | | | | | | |
33
+ ---
34
+ name: stand
35
+ speed: 3
36
+ ---
37
+ | |
38
+ | |
39
+ (._.) | (°.°) |
40
+ | |
41
+ ---
42
+ name: celebrate
43
+ loop_for: 3
44
+ ---
45
+ | |
46
+ | |
47
+ (O□O) | (☆‿☆) |
48
+ | |
49
+ ---
50
+ name: embarass
51
+ loop_for: 3
52
+ ---
53
+ | |
54
+ | |
55
+ (ಥ.ಥ) | (⇀o⇀) |
56
+ | |
57
+ ---
58
+ name: eat_bread
59
+ loop: false
60
+ ---
61
+ | | | | | | | | | | | | | |
62
+ | | | | | | | | | | | | | |
63
+ (O▽O) | (☆‿☆) | (O▽O) | (☆‿☆) | (O□O) | (ᗒ‿ᗕ) | (O□O) | (ᗒ‿ᗕ) | (O□O) | (ᗒ‿ᗕ) | (O▽O) | (☆‿☆) | (O▽O) | (☆‿☆) |
64
+ ʕ=ʔ | ʕ=ʔ | ʕ=ʔ | ʕ=ʔ | ʕ=ʔ | =ʔ | =ʔ | ʔ | ʔ | | | | | |
65
+ ---
66
+ name: eat_candy
67
+ loop: false
68
+ ---
69
+ | | | | | | | | | | | | | |
70
+ | | | | | | | | | | | | | |
71
+ (O▽O) | (☆‿☆) | (O▽O) | (☆‿☆) | (O□O) | (ᗒ‿ᗕ) | (O□O) | (ᗒ‿ᗕ) | (O□O) | (ᗒ‿ᗕ) | (O▽O) | (☆‿☆) | (O▽O) | (☆‿☆) |
72
+ ▷☯◁ | ▷☯◁ | ▷☯◁ | ▷☯◁ | ▷☯◁ | ☯◁ | ☯◁ | ◁ | ◁ | | | | | |
73
+ ---
74
+ name: eat_medicine
75
+ loop: false
76
+ ---
77
+ | | | | | | | | | | | | | |
78
+ | | | | | | | | | | | | | |
79
+ (O▽O) | (☆‿☆) | (O▽O) | (☆‿☆) | (O□O) | (ᗒ‿ᗕ) | (O□O) | (ᗒ‿ᗕ) | (O□O) | (ᗒ‿ᗕ) | (O▽O) | (☆‿☆) | (O▽O) | (☆‿☆) |
80
+ ◖◻◗ | ◖◻◗ | ◖◻◗ | ◖◻◗ | ◖◻◗ | ◻◗ | ◻◗ | ◗ | ◗ | | | | | |
data/data/poop.txtanim ADDED
@@ -0,0 +1,6 @@
1
+ width: 5
2
+ height: 2
3
+ loop: true
4
+ ---
5
+ ı ı ı|ϟ ϟ ϟ|
6
+ ༼ᵔ◡ᵔ༽|༼ಠ益ಠ༽|
@@ -0,0 +1,16 @@
1
+ width: 11
2
+ height: 4
3
+ loop: true
4
+ name: sleep
5
+ ---
6
+ | | z |
7
+ | z | |
8
+ ‿ z | ‿ ‿ | ‿ ‿ |
9
+ ‾ | ° | ‾ |
10
+ ---
11
+ name: blink
12
+ ---
13
+ | | | | | | | |
14
+ | | | | | | | |
15
+ . . | _ _ | . . | _ _ | . . | . . | . . | . . |
16
+ ‾ | ‾ | ‾ | ‾ | ‾ | ‾ | ‾ | ‾ |
@@ -0,0 +1,91 @@
1
+ width: 11
2
+ height: 4
3
+ loop: true
4
+ name: walk_great
5
+ ---
6
+ | | | |
7
+ |ᕦ(O ‿ O )ᕡ | |ᕦ( O ‿ O)ᕡ |
8
+ ᕠ(^ ▽ ^)ᕤ | |ᕠ(^ ▽ ^)ᕤ | |
9
+ | | | |
10
+ ---
11
+ name: walk_happy
12
+ ---
13
+ | | | |
14
+ | | | |
15
+ ᕠ(O o O)ᕤ |ᕦ(o _ o )ᕡ |ᕠ(O o O)ᕤ |ᕦ( o _ o)ᕡ |
16
+ | | | |
17
+ ---
18
+ name: walk_normal
19
+ ---
20
+ | | | |
21
+ | | | |
22
+ ᕠ(O . O)ᕤ |ᕦ(O _ O )ᕡ |ᕠ(O . O)ᕤ |ᕦ( O _ O)ᕡ |
23
+ | | | |
24
+ ---
25
+ name: walk_annoyed
26
+ ---
27
+ | | | |
28
+ | | | |
29
+ ᕠ(⊜ _ ⊜)ᕤ |ᕦ(ಠ - ಠ )ᕡ |ᕠ(⊜ _ ⊜)ᕤ |ᕦ( ಠ - ಠ)ᕡ |
30
+ | | | |
31
+ ---
32
+ name: walk_angry
33
+ ---
34
+ | | | |
35
+ | | | |
36
+ ᕠ(ಠ 益 ಠ)ᕤ |ᕦ(ಠ ෴ ಠ )ᕡ |ᕠ(ಠ 益 ಠ)ᕤ |ᕦ( ಠ ෴ ಠ)ᕡ |
37
+ | | | |
38
+ ---
39
+ name: walk_sick
40
+ ---
41
+ | | | |
42
+ | | | |
43
+ _(ළ - ළ)_ |~(ತ . ತ )~ |_(ළ - ළ)_ |~( ತ . ತ)~ |
44
+ | | | |
45
+ ---
46
+ name: stand
47
+ ---
48
+ | |
49
+ | |
50
+ ᕠ(O . O)ᕤ | ᕦ(O _ O)ᕡ |
51
+ | |
52
+ ---
53
+ name: celebrate
54
+ loop_for: 3
55
+ ---
56
+ | |
57
+ | |
58
+ ᕠ(☯ ᴥ ☯)ᕤ | ᕦ(✧ O ✧)ᕡ |
59
+ | |
60
+ ---
61
+ name: embarass
62
+ loop_for: 3
63
+ ---
64
+ | |
65
+ | |
66
+ ᕠ(ಥ ◠ ಥ)ᕤ | ᕦ(ಥ - ಥ)ᕡ |
67
+ | |
68
+ ---
69
+ name: eat_bread
70
+ loop: false
71
+ ---
72
+ | | | | | | | | | | | | | |
73
+ | | | | | | | | | | | | | |
74
+ ᕠ(☯ ᴥ ☯)ᕤ | ᕦ(✧ O ✧)ᕡ | ᕠ(☯ ᴥ ☯)ᕤ | ᕦ(✧ O ✧)ᕡ | \(O ▽ O)/ | _(ᗒ ‿ ᗕ)_ | \(O ▽ O)/ | _(ᗒ ‿ ᗕ)_ | \(O ▽ O)/ | _(ᗒ ‿ ᗕ)_ | ᕠ(☯ ᴥ ☯)ᕤ | ᕦ(✧ O ✧)ᕡ | ᕠ(☯ ᴥ ☯)ᕤ | ᕦ(✧ O ✧)ᕡ |
75
+ ʕ=ʔ | ʕ=ʔ | ʕ=ʔ | ʕ=ʔ | ʕ=ʔ | =ʔ | =ʔ | ʔ | ʔ | | | | | |
76
+ ---
77
+ name: eat_candy
78
+ loop: false
79
+ ---
80
+ | | | | | | | | | | | | | |
81
+ | | | | | | | | | | | | | |
82
+ ᕠ(☯ ᴥ ☯)ᕤ | ᕦ(✧ O ✧)ᕡ | ᕠ(☯ ᴥ ☯)ᕤ | ᕦ(✧ O ✧)ᕡ | \(O ▽ O)/ | _(ᗒ ‿ ᗕ)_ | \(O ▽ O)/ | _(ᗒ ‿ ᗕ)_ | \(O ▽ O)/ | _(ᗒ ‿ ᗕ)_ | ᕠ(☯ ᴥ ☯)ᕤ | ᕦ(✧ O ✧)ᕡ | ᕠ(☯ ᴥ ☯)ᕤ | ᕦ(✧ O ✧)ᕡ |
83
+ ▷☯◁ | ▷☯◁ | ▷☯◁ | ▷☯◁ | ▷☯◁ | ☯◁ | ☯◁ | ◁ | ◁ | | | | | |
84
+ ---
85
+ name: eat_medicine
86
+ loop: false
87
+ ---
88
+ | | | | | | | | | | | | | |
89
+ | | | | | | | | | | | | | |
90
+ ᕠ(☯ ᴥ ☯)ᕤ | ᕦ(✧ O ✧)ᕡ | ᕠ(☯ ᴥ ☯)ᕤ | ᕦ(✧ O ✧)ᕡ | \(O ▽ O)/ | _(ᗒ ‿ ᗕ)_ | \(O ▽ O)/ | _(ᗒ ‿ ᗕ)_ | \(O ▽ O)/ | _(ᗒ ‿ ᗕ)_ | ᕠ(☯ ᴥ ☯)ᕤ | ᕦ(✧ O ✧)ᕡ | ᕠ(☯ ᴥ ☯)ᕤ | ᕦ(✧ O ✧)ᕡ |
91
+ ◖◻◗ | ◖◻◗ | ◖◻◗ | ◖◻◗ | ◖◻◗ | ◻◗ | ◻◗ | ◗ | ◗ | | | | | |
@@ -0,0 +1,91 @@
1
+ width: 11
2
+ height: 4
3
+ loop: true
4
+ name: walk_great
5
+ ---
6
+ | | | |
7
+ |_[▢ ‿ ▢ ]_ | |_[ ▢ ‿ ▢]_ |
8
+ \[‾ ▽ ‾]/ | |\[‾ ▽ ‾]/ | |
9
+ | | | |
10
+ ---
11
+ name: walk_happy
12
+ ---
13
+ | | | |
14
+ | | | |
15
+ \[▢ ▫ ▢]/ |_[▢ _ ▢ ]_ |\[▢ ▫ ▢]/ |_[ ▢ _ ▢]_ |
16
+ | | | |
17
+ ---
18
+ name: walk_normal
19
+ ---
20
+ | | | |
21
+ | | | |
22
+ \[□ . □]/ |_[□ _ □ ]_ |\[□ . □]/ |_[ □ _ □]_ |
23
+ | | | |
24
+ ---
25
+ name: walk_annoyed
26
+ ---
27
+ | | | |
28
+ | | | |
29
+ \[⟥ _ ⟤]/ |_[⟥ - ⟤ ]_ |\[⟥ _ ⟤]/ |_[ ⟥ - ⟤]_ |
30
+ | | | |
31
+ ---
32
+ name: walk_angry
33
+ ---
34
+ | | | |
35
+ | | | |
36
+ \[⧅ ~ ⧅]/ |_[◫ ෴ ◫ ]_ |\[⧅ ~ ⧅]/ |_[ ◫ ෴ ◫]_ |
37
+ | | | |
38
+ ---
39
+ name: walk_sick
40
+ ---
41
+ | | | |
42
+ | | | |
43
+ _[▫ - ▫]_ |~[▪ . ▪ ]~ |_[▫ - ▫]_ |~[ ▪ . ▪]~ |
44
+ | | | |
45
+ ---
46
+ name: stand
47
+ ---
48
+ | |
49
+ | |
50
+ \[▢ ▫ ▢]/ | _[▢ _ ▢]_ |
51
+ | |
52
+ ---
53
+ name: celebrate
54
+ loop_for: 3
55
+ ---
56
+ | |
57
+ | |
58
+ \[⛋ - ⛋]/ | _[◰ ▢ ◰]_ |
59
+ | |
60
+ ---
61
+ name: embarass
62
+ loop_for: 3
63
+ ---
64
+ | |
65
+ | |
66
+ \[ಥ ◠ ಥ]/ | _[ಥ - ಥ]_ |
67
+ | |
68
+ ---
69
+ name: eat_bread
70
+ loop: false
71
+ ---
72
+ | | | | | | | | | | | | | |
73
+ | | | | | | | | | | | | | |
74
+ \[⛋ - ⛋]/ | _[◰ ▢ ◰]_ | \[⛋ - ⛋]/ | _[◰ ▢ ◰]_ | \[▫ □ ▫]/ | _[ᗒ ‿ ᗕ]_ | \[▫ □ ▫]/ | _[ᗒ ‿ ᗕ]_ | \[▫ □ ▫]/ | _[ᗒ ‿ ᗕ]_ | \[⛋ - ⛋]/ | _[◰ ▢ ◰]_ | \[⛋ - ⛋]/ | _[◰ ▢ ◰]_ |
75
+ ʕ=ʔ | ʕ=ʔ | ʕ=ʔ | ʕ=ʔ | ʕ=ʔ | =ʔ | =ʔ | ʔ | ʔ | | | | | |
76
+ ---
77
+ name: eat_candy
78
+ loop: false
79
+ ---
80
+ | | | | | | | | | | | | | |
81
+ | | | | | | | | | | | | | |
82
+ \[⛋ - ⛋]/ | _[◰ ▢ ◰]_ | \[⛋ - ⛋]/ | _[◰ ▢ ◰]_ | \[▫ □ ▫]/ | _[ᗒ ‿ ᗕ]_ | \[▫ □ ▫]/ | _[ᗒ ‿ ᗕ]_ | \[▫ □ ▫]/ | _[ᗒ ‿ ᗕ]_ | \[⛋ - ⛋]/ | _[◰ ▢ ◰]_ | \[⛋ - ⛋]/ | _[◰ ▢ ◰]_ |
83
+ ▷☯◁ | ▷☯◁ | ▷☯◁ | ▷☯◁ | ▷☯◁ | ☯◁ | ☯◁ | ◁ | ◁ | | | | | |
84
+ ---
85
+ name: eat_medicine
86
+ loop: false
87
+ ---
88
+ | | | | | | | | | | | | | |
89
+ | | | | | | | | | | | | | |
90
+ \[⛋ - ⛋]/ | _[◰ ▢ ◰]_ | \[⛋ - ⛋]/ | _[◰ ▢ ◰]_ | \[▫ □ ▫]/ | _[ᗒ ‿ ᗕ]_ | \[▫ □ ▫]/ | _[ᗒ ‿ ᗕ]_ | \[▫ □ ▫]/ | _[ᗒ ‿ ᗕ]_ | \[⛋ - ⛋]/ | _[◰ ▢ ◰]_ | \[⛋ - ⛋]/ | _[◰ ▢ ◰]_ |
91
+ ◖◻◗ | ◖◻◗ | ◖◻◗ | ◖◻◗ | ◖◻◗ | ◻◗ | ◻◗ | ◗ | ◗ | | | | | |
@@ -0,0 +1,94 @@
1
+ module Petli
2
+ class Pet
3
+ module Animation
4
+ extend Tatty::DB::Attributes
5
+ db_attr :phase, default: :infant
6
+ db_attr :phase_select, default: 0
7
+ db_attr :lights_out, default: false
8
+
9
+ def setup_animation
10
+ hatch if (Time.now - self.birth) < 10
11
+ end
12
+
13
+ def update_animation
14
+ reset if animation.step && !animation.loop
15
+ if phase == :infant && hours_since(birth) > 1
16
+ self.phase = :teen
17
+ self.phase_select = rand(0...avail_animations[phase].count)
18
+ elsif phase == :teen && days_since(birth) > 1
19
+ self.phase = :adult
20
+ self.phase_select = rand(0...avail_animations[phase].count)
21
+ end
22
+ end
23
+
24
+ def reset
25
+ @doing = nil
26
+ end
27
+
28
+ def busy?
29
+ !@doing.nil?
30
+ end
31
+
32
+ def celebrate
33
+ react(:celebrate)
34
+ end
35
+
36
+ def embarass
37
+ react(:embarass)
38
+ end
39
+
40
+ def hatch
41
+ @doing = avail_animations[:hatch]
42
+ end
43
+
44
+ def light_switch
45
+ self.lights_out = !lights_out
46
+ self.happiness = [1, self.happiness-1].max if self.lights_out && !sleeping?
47
+ end
48
+
49
+ def sleeping?
50
+ hour = Time.now.hour
51
+ hour >= 16 || hour <= 8
52
+ end
53
+
54
+ def react(action)
55
+ anim = atlas[action]
56
+ anim.reset
57
+ @doing = anim
58
+ end
59
+
60
+ def animation
61
+ if self.dead?
62
+ avail_animations[:death]
63
+ elsif !@doing.nil?
64
+ @doing
65
+ elsif self.lights_out
66
+ if sleeping?
67
+ avail_animations[:sleep][:sleep]
68
+ else
69
+ avail_animations[:sleep][:blink]
70
+ end
71
+ elsif self.sick > 0
72
+ atlas[:walk_sick]
73
+ else
74
+ atlas["walk_#{self.mood}"]
75
+ end
76
+ end
77
+
78
+ def atlas
79
+ avail_animations[phase][phase_select]
80
+ end
81
+
82
+ def avail_animations
83
+ @avail_animations ||= {
84
+ hatch: Tatty::Anim.from_atlas(Petli.data_path('hatch.txtanim')),
85
+ infant: Dir[Petli.data_path('infant',"*.txtanim")].map {|p| Tatty::Atlas.new(p) },
86
+ teen: Dir[Petli.data_path('teen',"*.txtanim")].map {|p| Tatty::Atlas.new(p) },
87
+ adult: Dir[Petli.data_path('adult',"*.txtanim")].map {|p| Tatty::Atlas.new(p) },
88
+ death: Tatty::Anim.from_atlas(Petli.data_path('death.txtanim')),
89
+ sleep: Tatty::Atlas.new(Petli.data_path('sleep.txtanim')),
90
+ }
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,45 @@
1
+ module Petli
2
+ class Pet
3
+ module Death
4
+ extend Tatty::DB::Attributes
5
+ db_attr :birth, default: Time.now, readonly: true
6
+ db_attr :died_at
7
+
8
+ def check_if_dead
9
+ die! if unhappy? && unhealthy? && (too_sick? || too_hungry?)
10
+ end
11
+
12
+ def die!
13
+ self.died_at = Time.now
14
+ end
15
+
16
+ def sick?
17
+ self.sick > 0
18
+ end
19
+
20
+ def too_sick?
21
+ self.sick > 2
22
+ end
23
+
24
+ def too_hungry?
25
+ days_since(self.last_meal) >= 1
26
+ end
27
+
28
+ def unhappy?
29
+ self.happiness <= 1
30
+ end
31
+
32
+ def unhealthy?
33
+ self.health <= 1
34
+ end
35
+
36
+ def dead?
37
+ !self.died_at.nil?
38
+ end
39
+
40
+ def lifetime
41
+ (self.died_at.nil? ? days_since(self.birth) : days_since(self.birth, self.died_at)).to_i
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ module Petli
2
+ class Pet
3
+ module Food
4
+ extend Tatty::DB::Attributes
5
+
6
+ POOP_LOCATIONS = [[1,1], [1,4], [1,7], [11,1], [11,7], [20,1], [20,4], [20,7]]
7
+
8
+ db_attr :health, default: 5
9
+ db_attr :last_meal, default: Time.now
10
+ db_attr :sick, default: 0
11
+ db_attr :poops, default: []
12
+
13
+ def update_hunger
14
+ for_hours_since(last_meal) do |i, hr_ago|
15
+ hunger(hr_ago) if rand >= 0.3
16
+ end
17
+ end
18
+
19
+ def feed(food: :bread)
20
+ return self.embarass if ((food == :medicine && self.sick <= 0) || (self.health == 10 && food != :medicine))
21
+ self.last_meal = Time.now unless food == :medicine
22
+ react("eat_#{food}")
23
+ self.feed!(food: food)
24
+ end
25
+
26
+ def feed!(food: :bread)
27
+ self.health = [10, self.health+2].min unless food == :medicine
28
+ self.happiness = [10, self.happiness+2].min if food == :candy
29
+ self.sick = [0, self.sick - 1].max if food == :medicine
30
+ end
31
+
32
+ def hunger(hr_ago=hours_ago(1))
33
+ self.health = [1, self.health-1].max
34
+ self.happiness = [1, self.happiness-1].max
35
+ self.poops = self.poops + [hr_ago] if rand <= 0.4 && self.poops.count < POOP_LOCATIONS.count
36
+ self.sick = [self.poops.filter{|poop| hours_since(poop) > 1 }.count, 3].min
37
+ self.last_meal = Time.now
38
+ end
39
+
40
+ def clean
41
+ self.poops = []
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,34 @@
1
+ module Petli
2
+ class Pet
3
+ module Happy
4
+ extend Tatty::DB::Attributes
5
+ MOOD_SCALE = %i(angry annoyed normal happy great)
6
+
7
+ db_attr :mood, default: :normal
8
+ db_attr :last_play, default: Time.now
9
+ db_attr :happiness, default: 5
10
+
11
+ def update_happiness
12
+ for_hours_since(last_play) do |i|
13
+ self.last_play = Time.now
14
+ next if rand <= 0.3
15
+ self.happiness = [[1, self.happiness-1].max, self.health <= 3 ? 5 : 10].min
16
+ end
17
+ self.mood = MOOD_SCALE[((self.happiness.to_f/10.0)*(MOOD_SCALE.count - 1)).floor]
18
+ end
19
+
20
+ def play(game: :dice)
21
+ self.last_play = Time.now
22
+ react(:stand)
23
+ end
24
+
25
+ def win
26
+ self.happiness = [10, self.happiness+1].min
27
+ end
28
+
29
+ def lose
30
+ # todo I dont really want it to become more unhappy if they lose
31
+ end
32
+ end
33
+ end
34
+ end
data/lib/petli/pet.rb CHANGED
@@ -1,131 +1,29 @@
1
1
  module Petli
2
2
  class Pet
3
- include Watch
4
- extend Tatty::DB::Attributes
5
-
6
- MOOD_SCALE = [:angry, :annoyed, :normal, :happy, :great]
3
+ autoload :Food, "petli/pet/food"
4
+ autoload :Happy, "petli/pet/happy"
5
+ autoload :Death, "petli/pet/death"
6
+ autoload :Animation, "petli/pet/animation"
7
7
 
8
- db_attr :birth, default: Time.now, readonly: true
9
- db_attr :health, default: 5
10
- db_attr :mood, default: :normal
11
- db_attr :happiness, default: 5
12
- db_attr :sick, default: 0
13
- db_attr :died_at
14
- db_attr :last_play, default: Time.now
15
- db_attr :last_meal, default: Time.now
16
- db_attr :poops, default: []
8
+ extend Tatty::DB::Attributes
9
+ include Animation
10
+ include Death
11
+ include Food
12
+ include Happy
13
+ include Watch
17
14
 
18
15
  def initialize
19
16
  super()
20
- @animation = Animator.new(
21
- hatching: (Time.now - self.birth) < 10,
22
- mood: self.mood,
23
- action: self.died_at.nil? ? :walk : :death
24
- )
25
- end
26
-
27
- def reset
28
- @animation.action = :walk
17
+ setup_animation
29
18
  end
30
19
 
31
20
  def display
32
- return @animation.step if self.dead?
33
-
34
- if hours_since(self.last_meal) > 1
35
- hours_past = hours_since(self.last_meal)
36
- self.last_meal = Time.now
37
- (0...hours_past).each do |i|
38
- next if rand <= 0.3
39
- self.health = [1, self.health-1].max
40
- self.happiness = [1, self.happiness-1].max
41
- self.poops << hours_ago(i) if rand <= 0.8 && self.poops.count < Poop::LOCATIONS.count
42
- end
43
- self.sick = self.poops.filter{|poop| hours_since(poop) > 1 }.count
44
- end
45
-
46
- if hours_since(self.last_play) > 1
47
- hours_past = hours_since(self.last_play)
48
- self.last_play = Time.now
49
- (0...hours_past).each do
50
- next if rand <= 0.3
51
- self.happiness = [1, self.happiness-1].max
52
- end
53
- end
54
-
55
- self.happiness = [self.happiness, 5].min if self.health <= 3
56
- self.mood = MOOD_SCALE[((self.happiness.to_f/10.0)*(MOOD_SCALE.count - 1)).floor ]
57
-
58
- self.check_if_dead
59
-
60
- @animation.mood = self.sick > 0 ? :sick : self.mood
61
- @animation.step
62
- end
63
-
64
- def check_if_dead
65
- not_happy = self.happiness <= 1
66
- not_healthy = self.health <= 1
67
- is_sick = self.sick > 2
68
- too_much_time = days_since(self.last_meal) >= 1
69
-
70
- if not_happy && not_healthy && (is_sick || too_much_time)
71
- self.died_at = Time.now
72
- @animation.action = :death
73
- end
74
- end
75
-
76
- def feed(food: :bread)
77
- return self.embarass if ((food == :medicine && self.sick <= 0) || (self.health == 10 && food != :medicine))
78
- self.last_meal = Time.now unless food == :medicine
79
- @animation.eat(food: food) do
80
- self.feed!(food: food)
81
- end
82
- end
83
-
84
- def feed!(food: :bread)
85
- self.health = [10, self.health+1].min unless food == :medicine
86
- self.happiness = [10, self.happiness+1].min if food == :candy
87
- self.sick = [0, self.sick - 1].max if food == :medicine
88
- end
89
-
90
- def win
91
- self.happiness = [10, self.happiness+1].min
92
- end
93
-
94
- def lose
95
- # todo I dont really want it to become more unhappy if they lose
96
- end
97
-
98
- def play(game: :dice)
99
- self.last_play = Time.now
100
- @animation.action = :stand
101
- end
102
-
103
- def clean
104
- self.poops = []
105
- end
106
-
107
- def busy?
108
- @animation.busy?
109
- end
110
-
111
- def dead?
112
- @animation.action == :death
113
- end
114
-
115
- def celebrate
116
- @animation.celebrate
117
- end
118
-
119
- def embarass
120
- @animation.embarass
121
- end
122
-
123
- def lifetime
124
- if self.died_at.nil?
125
- days_since(self.birth).to_i
126
- else
127
- days_since(self.birth, self.died_at).to_i
128
- end
21
+ return animation.next if self.dead?
22
+ update_hunger
23
+ update_happiness
24
+ check_if_dead
25
+ update_animation
26
+ animation.display
129
27
  end
130
28
  end
131
29
  end