2
* Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of
7
* the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
#include <KgDifficulty>
23
const qreal Kapman::MAX_SPEED_RATIO = 1.5;
25
Kapman::Kapman(qreal p_x, qreal p_y, Maze* p_maze) : Character(p_x, p_y, p_maze) {
26
m_type = Element::KAPMAN;
27
m_maxSpeed = m_normalSpeed * MAX_SPEED_RATIO;
43
m_askedYSpeed = -m_speed;
46
void Kapman::goDown() {
48
m_askedYSpeed = m_speed;
51
void Kapman::goRight() {
52
m_askedXSpeed = m_speed;
56
void Kapman::goLeft() {
57
m_askedXSpeed = -m_speed;
61
void Kapman::updateDirection() {
62
setXSpeed(m_askedXSpeed);
63
setYSpeed(m_askedYSpeed);
66
// Signal to the kapman item that the direction changed
67
emit(directionChanged());
70
void Kapman::updateMove() {
71
// If the kapman does not move
72
if (m_xSpeed == 0 && m_ySpeed == 0) {
73
// If the user asks for moving
74
if (m_askedXSpeed != 0 || m_askedYSpeed != 0) {
75
// Check the next cell with the asked direction
76
if (getAskedNextCell().getType() == Cell::CORRIDOR) {
77
// Update the direction
84
// If the kapman is already moving
86
// If the kapman wants to go back it does not wait to be on a center
87
if ( (m_xSpeed!=0 && m_askedXSpeed==-m_xSpeed) || (m_ySpeed!=0 && m_askedYSpeed==-m_ySpeed) ) {
93
// If the kapman gets on a cell center
95
// If there is an asked direction (but not a half-turn)
96
if ((m_askedXSpeed != 0 || m_askedYSpeed != 0) && (m_askedXSpeed != m_xSpeed || m_askedYSpeed != m_ySpeed)) {
97
// Check the next cell with the kapman asked direction
98
if (getAskedNextCell().getType() == Cell::CORRIDOR) {
99
// Move the kapman on the cell center
101
// Update the direction
104
// Check the next cell with the kapman current direction
105
if (getNextCell().getType() != Cell::CORRIDOR) {
106
// Move the kapman on the cell center
116
// Check the next cell with the kapman current direction
117
if (getNextCell().getType() != Cell::CORRIDOR) {
118
// Move the kapman on the cell center
135
void Kapman::winPoints(Element* p_element) {
136
// Emits a signal to the game
137
emit(sWinPoints(p_element));
144
void Kapman::emitGameUpdated() {
148
qreal Kapman::getAskedXSpeed() const {
149
return m_askedXSpeed;
152
qreal Kapman::getAskedYSpeed() const {
153
return m_askedYSpeed;
156
Cell Kapman::getAskedNextCell() {
157
// Get the current cell coordinates from the character coordinates
158
int curCellRow = m_maze->getRowFromY(m_y);
159
int curCellCol = m_maze->getColFromX(m_x);
162
// Get the next cell function of the character asked direction
163
if (m_askedXSpeed > 0) {
164
nextCell = m_maze->getCell(curCellRow, curCellCol + 1);
165
} else if (m_askedXSpeed < 0) {
166
nextCell = m_maze->getCell(curCellRow, curCellCol - 1);
167
} else if (m_askedYSpeed > 0) {
168
nextCell = m_maze->getCell(curCellRow + 1, curCellCol);
169
} else if (m_askedYSpeed < 0) {
170
nextCell = m_maze->getCell(curCellRow - 1, curCellCol);
176
void Kapman::stopMoving() {
184
void Kapman::initSpeedInc() {
185
// Kapman speed increase when level up
186
switch ((int) Kg::difficultyLevel())
188
case KgDifficultyLevel::Easy:
189
m_speedIncrease = Character::LOW_SPEED_INC / 2;
191
case KgDifficultyLevel::Medium:
192
m_speedIncrease = Character::MEDIUM_SPEED_INC / 2;
194
case KgDifficultyLevel::Hard:
195
m_speedIncrease = Character::HIGH_SPEED_INC / 2;