-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFemale.cpp
More file actions
105 lines (75 loc) · 2.11 KB
/
Female.cpp
File metadata and controls
105 lines (75 loc) · 2.11 KB
1
2
3
4
5
6
7
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "Headers/Female.hpp"
#include "Headers/Male.hpp"
#include <cmath>
#include <utility>
#include <iostream>
#include <memory>
#include <SFML/Graphics/RenderTarget.hpp>
/* constructors: */
Female_E::Female_E()
: Elephant_Base()
, mChild()
, mIsPregnant(false)
, mGestationTime(0.f) {
}
Female_E::Female_E(TextureHolder& text, bool hasTusks, age_value a)
: Elephant_Base(text, Elephant_Base::Sex::Female, hasTusks, a)
, mChild()
, mIsPregnant(false)
, mGestationTime(0.f) {
if(getTraits().tusks)
mShape.setTexture(getTraits().textures->get(Texture::TuskedFemale));
else
mShape.setTexture(getTraits().textures->get(Texture::UntuskedFemale));
}
/* public methods : */
void Female_E::update(sf::Time dt) {
//if elephant is dead, no need to go further
if(!isAlive())
return;
updateMovement(dt);
toAge(dt);
if(mIsPregnant) {
mGestationTime += dt.asSeconds() / Elephant_Base::YEAR_IN_SECONDS_VALUE.asSeconds();
if(mGestationTime > 1.75f) {
//if gestation comes to term, give birth
giveBirth();
}
} else if(mChild) {
//if not pregnant any more, it may now have a child to update
mChild.update(dt);
}
}
bool Female_E::canGetPregnant() const {
return !(mChild || mIsPregnant || getTraits().age > 50 || getTraits().age < 25);
}
bool Female_E::hasChildGrown() const {
return mChild.getTraits().age > 4;
}
Elephant_Base::Ptr Female_E::detachChild() {
Child_E ret = mChild;
mChild = Child_E();
return ret.getData();
}
bool Female_E::isPregnant() const {
return mIsPregnant;
}
/* private methods : */
void Female_E::makePregnant(const Elephant_Base::Gene& maleGamete) {
if(!canGetPregnant())
return;
mChild = Child_E(*getTraits().textures, std::make_pair(generateGametes(), maleGamete));
mIsPregnant = true;
}
void Female_E::giveBirth() {
std::cout << "giving birth" << std::endl;
mIsPregnant = false;
mGestationTime = 0.f;
mChild.setPosition(30.f, 30.f);
}
void Female_E::draw(sf::RenderTarget& target, sf::RenderStates states) const {
states.transform *= getTransform();
target.draw(mShape, states);
if(mChild && !mIsPregnant)
target.draw(mChild, states);
}