blob: 36f32c63b5a1acd9970ba83a02123d0d84e27658 (
plain)
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
|
#include "Player.h"
#include <iostream>
Player::Player(PlayerNumber PlayerID, Coordinates InitialPoint, VelocityVector initialVel) : m_playerID(PlayerID), m_currentCoordinates(InitialPoint), m_velocityVector(initialVel)
{
m_alive = true;
// m_controller=KeyboardController(self);
}
Player::~Player(void)
{
}
std::vector<Coordinates> Player::move() {
std::vector<Coordinates> cases;
int sgn_x = m_velocityVector.x >= 0 ? 1 : -1;
int sgn_y = m_velocityVector.y >= 0 ? 1 : -1;
for (int i = 0; i <= abs(m_velocityVector.x) ; ++i ) {
for (int j = 0; j <= abs(m_velocityVector.y) ; ++j ) {
cases.push_back(Coordinates(m_currentCoordinates.x+i*sgn_x, m_currentCoordinates.y+j*sgn_y));
}
}
m_currentCoordinates.x += m_velocityVector.x;
m_currentCoordinates.y += m_velocityVector.y;
return(cases);
}
void Player::setVelocityVector(VelocityVector v) {
m_velocityVector = v;
}
void Player::turnLeft() {
int t = m_velocityVector.x;
m_velocityVector.x = m_velocityVector.y;
m_velocityVector.y = - m_velocityVector.x;
}
void Player::turnRight() {
int t = m_velocityVector.x;
m_velocityVector.x = - m_velocityVector.y;
m_velocityVector.y = m_velocityVector.x;
}
bool Player::changeDirection(VelocityVector v) {
if ((m_velocityVector.x != 0 && v.x != 0) || (m_velocityVector.y != 0 && v.y != 0)) {
return(false);
} else {
m_velocityVector = v;
return(true);
}
}
bool Player::isAlive() {
return(m_alive);
}
void Player::kill() {
m_alive = false;
}
PlayerNumber Player::getNumber() {
return(m_playerID);
}
Controller* Player::getController() {
return(m_controller);
}
VelocityVector Player::getVelocity() {
return(m_velocityVector);
}
Coordinates Player::getCoordinates() {
return(m_currentCoordinates);
}
|