-
Notifications
You must be signed in to change notification settings - Fork 0
/
Moveable.cpp
135 lines (110 loc) · 2.66 KB
/
Moveable.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "Moveable.h"
Moveable::Moveable() :m_defaul_speed(10)
{
m_speed = (int)m_defaul_speed;
}
//Moveable::Moveable(Moveable & other): m_defaul_speed(10)
//{
//
// this->_nextPos = other.myRec.getPosition();
// dir = NONE;
// killed = false;
//}
Moveable::Moveable(int i, int j, char type) : GameObject(i, j, type), m_defaul_speed(10)
{
dir = NONE;
killed = false;
success = false;
_nextPos = myRec.getPosition();
m_speed = (int)m_defaul_speed;
}
Moveable::Moveable(sf::Vector2f) : m_defaul_speed(10)
{
m_speed = (int)m_defaul_speed;
}
//void Moveable::setmovment(sf::Vector2i movment)
//{
// /*if (movment.x == 1) {
// _nextPos.x = myRec.getPosition().x + m_speed;
// _nextPos.y = myRec.getPosition().y;
// dir = RIGHT;
// }
// else if (movment.x == -1) {
// _nextPos.x = myRec.getPosition().x - m_speed;
// _nextPos.y = myRec.getPosition().y;
// dir = LEFT;
// }
// else if (movment.y == 1) {
// _nextPos.x = myRec.getPosition().x;
// _nextPos.y = myRec.getPosition().y + m_speed;
// dir = UP;
// }
// else if (movment.y == -1) {
// _nextPos.x = myRec.getPosition().x;
// _nextPos.y = myRec.getPosition().y - m_speed;
// dir = DOWN;
// }*/
//
//}
sf::Vector2f Moveable::getnext(sf::Vector2i robotPos, sf::Vector2u limits)
{
return _nextPos;
}
void Moveable::setDefault()
{
_nextPos = m_default_pos;
killed = false;
myRec.setPosition(m_default_pos);
}
void Moveable::changeSpeed(float, int time)
{
}
void Moveable::setScore(int)
{
}
int Moveable::getScore() const
{
return 0;
}
void Moveable::setColor(sf::Color)
{
}
sf::FloatRect Moveable::getDirectionPos() const
{
sf::FloatRect boundRect = myRec.getGlobalBounds();
switch (dir) {
case LEFT:
boundRect.left = boundRect.left - m_speed;
break;
case RIGHT:
boundRect.left = boundRect.left + m_speed ;
break;
case UP:
boundRect.top = boundRect.top + m_speed ;
break;
case DOWN:
boundRect.top = boundRect.top - m_speed ;
break;
}
return boundRect;
}
void Moveable::updateSpeed()
{
m_speed = (int)m_MoveableClock.getElapsedTime().asSeconds() + 10;
if (m_MoveableClock.getElapsedTime().asSeconds() >= 15) {
m_speed = (int) m_defaul_speed;
}
}
bool Moveable::checkLimits(sf::Vector2f position, sf::Vector2u limits)
{
if (position.x >= 0 && position.x + (55 - this->m_speed) < limits.y && position.y >= 0 && position.y + (55 - this->m_speed) < limits.x ) {
if (this->getType() == '/') {}
return true;
}
else if(position.x < 0 || position.x + (55 -this->m_speed) >= limits.y || position.y < 0 || position.y + (55 - this->m_speed) >= limits.x){
/*cout << position.x << " " << position.y << endl;
cout << limits.x << " " << limits.y << endl;*/
return false;
}
return false;
}