-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbehavior_default.cpp
More file actions
70 lines (63 loc) · 2.46 KB
/
Copy pathbehavior_default.cpp
File metadata and controls
70 lines (63 loc) · 2.46 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
/***
* Maracatronics Robotics
* Federal University of Pernambuco (UFPE) at Recife
* http://www.maracatronics.com/
*
* This file is part of Armorial project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "behavior_default.h"
#include <src/entities/player/player.h>
#include <src/entities/worldmap/worldmap.h>
Behavior_Default::Behavior_Default() {
_skill_goTo = nullptr;
_skill_rotateTo = nullptr;
_skill_spin = nullptr;
}
void Behavior_Default::configure() {
// Starting skills
_skill_goTo = new Skill_GoTo();
_skill_rotateTo = new Skill_RotateTo();
_skill_spin = new Skill_Spin();
// Adding to behavior skill list
addSkill(SKILL_GOTO, _skill_goTo);
addSkill(SKILL_ROTATETO, _skill_rotateTo);
addSkill(SKILL_SPIN, _skill_spin);
// Defines initial target position
_targetPosition = Geometry::Vector2D(0.5f, 0.5f);
}
void Behavior_Default::run() {
// Test logic for the 3 main skills ocurring simultaneously
if(player()->robotId() == 0) {
// Move the robot to other positions and see if it rotate to the
// target position using the smarter rotation diretion route
_skill_rotateTo->setTargetAngle((_targetPosition - player()->getPosition()).angle());
runSkill(SKILL_ROTATETO);
} else if (player()->robotId() == 1) {
// Move the robot to other positions and see if it moves
// to the target position using the best face no move
_skill_goTo->setTargetPosition(_targetPosition);
_skill_goTo->setGUI(gui());
runSkill(SKILL_GOTO);
} else {
// Move the robot to positions where you can see both spin directions
if (_targetPosition.y() > player()->getPosition().y()) {
_skill_spin->setClockwiseDirection(false);
} else {
_skill_spin->setClockwiseDirection(true);
}
runSkill(SKILL_SPIN);
}
}