-
Notifications
You must be signed in to change notification settings - Fork 0
/
huntermodel.cpp
56 lines (49 loc) · 1.38 KB
/
huntermodel.cpp
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
#include "huntermodel.hpp"
#include <ctime>
#include "random.hpp"
HunterModel::HunterModel(const stf::Vec2d &mapSize)
: SegmentedEntityModel(mapSize)
{}
bool HunterModel::onUpdate(const float dt)
{
if(m_target == nullptr) return true;
if(m_duration > m_lvlDuration)
{
m_entity->update();
m_entity->wrapping(2, 1, m_mapSize.x-1, m_mapSize.y-1);
m_duration = 0.f;
}
m_duration += dt;
return true;
}
void HunterModel::reset()
{
m_lvlDuration = hunter_model_settings::MAX_DURATION;
m_score = 0u;
m_lvl = 1u;
}
void HunterModel::collisionWithTargetHandler()
{
using namespace hunter_model_settings;
m_entity->feed();
m_score += m_target->nutritionalValue();
if(m_lvl < MAX_LEVEL && m_entity->length() % LVLUP_STEP == 0) {
if(m_lvlDuration > MIN_DURATION) m_lvlDuration -= DURATION_STEP;
++m_lvl;
}
}
SegmentedEntityModel *HunterModel::collisionWithEntityHandler(SegmentedEntityModel *entity)
{
for(size_t s1 = 0; s1 < m_entity->length(); ++s1) {
for (size_t s2 = 0; s2 < (*entity)()->length(); ++s2) {
if(m_entity->isSegmetOverlapped(s1, entity->segmet(s2))) {
if(m_entity->length() > (*entity)()->length()) {
return entity;
} else {
return this;
}
}
}
}
return nullptr;
}