summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/creature.cpp5
-rw-r--r--src/dna.cpp17
-rw-r--r--src/list.cpp2
3 files changed, 21 insertions, 3 deletions
diff --git a/src/creature.cpp b/src/creature.cpp
index 0b7a438..1cd0a52 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -107,7 +107,7 @@ void Creature::Action()
hasTarget = false;
}
else if( Distance(rect,target->getRect()) < mine.reach && target->getType() == CREATURE_TYPE && target->getGender() != gender ){
- target->impregnate();
+ target->impregnate(mine);
hasTarget = false;
}
else
@@ -157,10 +157,11 @@ void Creature::Move(SDL_Rect R)
}
}
-void Creature::impregnate()
+void Creature::impregnate(Dna D)
{
if(!pregnate){
pregnate = true;
pregnancyTime = 0;
+ childs = mine.combine(D);
}
}
diff --git a/src/dna.cpp b/src/dna.cpp
index 36eda3d..1145276 100644
--- a/src/dna.cpp
+++ b/src/dna.cpp
@@ -12,3 +12,20 @@ Dna::Dna()
expectedAge = CREATURE_EXP_AGE;
sizeMax = CREATURE_SIZE_MAX;
}
+
+Dna Dna::combine(Dna D)
+{
+ Dna N;
+
+ N.maxHealth = (this->maxHealth + D.maxHealth)/2;
+ N.speed = (this->speed + D.speed)/2;
+ N.reach = (this->reach + D.reach)/2;
+ N.bestSense = (this->bestSense + D.bestSense)/2;
+ N.bite = (this->bite + D.bite)/2;
+ N.amountToGrow = (this->amountToGrow + D.amountToGrow)/2;
+ N.expectedPregnancyTime = (this->expectedPregnancyTime + D.expectedPregnancyTime)/2;
+ N.expectedAge = (this->expectedAge + D.expectedAge)/2;
+ N.sizeMax = (this->sizeMax + D.sizeMax)/2;
+
+ return N;
+}
diff --git a/src/list.cpp b/src/list.cpp
index 0439278..4f2ddc4 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -43,7 +43,7 @@ void List::Behavior()
it->Behavior();
if(it->getPregnancyReady()){
- Dna D = it->getDNA();
+ Dna D = it->getChildDNA();
SDL_Rect Rect = it->getRect();
Rect.h = Rect.w = D.sizeMax / 5;
Creature X(main,Rect,D);