-
Notifications
You must be signed in to change notification settings - Fork 0
/
mousebot.cpp
41 lines (32 loc) · 1.03 KB
/
mousebot.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
#include "mousebot.hpp"
#include "mouse.hpp"
#include "random.hpp"
#include <ctime>
MouseBotModel::MouseBotModel(const stf::Vec2d &mapSize, const stf::Vec2d &startPos)
: BotModel(mapSize, startPos)
{
m_entity = new Mouse(startPos);
}
bool MouseBotModel::onUpdate(const float dt)
{
if(m_target == nullptr) return HunterModel::onUpdate(dt);
if(m_entity->body().at(1).x > m_target->pos().x) A();
if(m_entity->body().at(1).x < m_target->pos().x) D();
if(m_entity->body().at(1).y > m_target->pos().y) W();
if(m_entity->body().at(1).y < m_target->pos().y) S();
return HunterModel::onUpdate(dt);
}
void MouseBotModel::reset() {
delete m_entity;
m_entity = new Mouse({stf::Random(time(0)).getNum(2, m_mapSize.x-2),
stf::Random(time(0)).getNum(2, m_mapSize.y-2)});
HunterModel::reset();
}
bool MouseBotModel::isCollideWithTarget() const
{
if(m_target == nullptr) return false;
if(m_entity->body().at(1).diff(m_target->pos()) < 1.f) {
return true;
}
return false;
}