granatier
player.cpp
Go to the documentation of this file.
35 Player::Player(qreal p_x, qreal p_y, const QString& p_playerID, const PlayerSettings* p_playerSettings, Arena* p_arena) : Character(p_x, p_y, p_arena)
190 int straightDirection = 0; //straight direction: -1: backward; 1:foreward; while foreward is right for moving in x-direction and down for y-direction
192 qreal deltaPerpendicularMove = 0; //the move in perpendicular direction; e.g. the player is not in cell center and will collide with a wall in the cell above, so the player has to be moved to the cell center
194 qreal deltaStraightCellCorner; //move in x-direction: the x-pos from the top left cell corner; move in y-direction: the y-pos from the top left cell corner
195 qreal deltaPerpendicularCellCorner; //move in x-direction: the y-pos from the top left cell corner; move in y-direction: the x-pos from the top left cell corner
196 qreal deltaStraightCellCenter; //distance to the cell center in moving direction; positive if left/up from cell center, negative if right/down
197 qreal deltaPerpendicularCellCenter; //distance to the cell center perpendicular to moving direction; positive if up/left from cell center, negative if down/right
260 if(deltaStraightCellCenter * straightDirection > 0 && !m_arena->getCell(moveStartRow, moveStartCol).isWalkable(this) && !m_omitBombCurrentCell)
266 bombElements = m_arena->getCell(moveStartRow, moveStartCol).getElements(Granatier::Element::BOMB);
269 //moving away of cell center; don't move if there is a bomb in the next cell; ignore a bomb in the current cell
270 else if(deltaStraightCellCenter * straightDirection < 0 && !m_arena->getCell(moveStartRow + yDirection, moveStartCol + xDirection).isWalkable(this))
276 bombElements = m_arena->getCell(moveStartRow + yDirection, moveStartCol + xDirection).getElements(Granatier::Element::BOMB);
291 if(deltaPerpendicularCellCenter != 0 && (straightDirection * deltaStraightCellCenter) < 0) //not in perpendicular center and entering a new cell
293 if(fabs(deltaPerpendicularCellCenter) > Granatier::CellSize/2 - fabs(deltaStraightMove - deltaStraightCellCenter)) //check if it already can collide with a hurdle
295 cellRow = curCellRow + yDirection - qAbs(xDirection)*signZeroPositive(deltaPerpendicularCellCenter);
296 cellCol = curCellCol + xDirection - qAbs(yDirection)*signZeroPositive(deltaPerpendicularCellCenter);
299 deltaPerpendicularMove = deltaPerpendicularCellCenter + signZeroPositive(deltaPerpendicularCellCenter) * (fabs(deltaStraightMove - deltaStraightCellCenter) - Granatier::CellSize/2);
300 if(fabs(deltaPerpendicularMove) > fabs(deltaPerpendicularCellCenter)) //check if moved over perpendicular center
314 if(straightDirection * deltaStraightCellCenter < 0) //the cell center to move is in the next cell
322 cellRow = curCellRow + yDirection - qAbs(xDirection)*signZeroPositive(deltaPerpendicularCellCenter);
323 cellCol = curCellCol + xDirection - qAbs(yDirection)*signZeroPositive(deltaPerpendicularCellCenter);
336 if(m_arena->getCell(curCellRow + yDirection, curCellCol + xDirection).isWalkable(this)) //check if next cell is walkable
338 if(fabs(deltaAskedMove) > Granatier::CellSize) //move to next cell center if the remaining move exceeds a cell center
345 cellRow = curCellRow + yDirection - qAbs(xDirection)*signZeroPositive(deltaPerpendicularCellCenter);
346 cellCol = curCellCol + xDirection - qAbs(yDirection)*signZeroPositive(deltaPerpendicularCellCenter);
357 if(deltaPerpendicularMove != deltaPerpendicularCellCenter && fabs(deltaPerpendicularCellCenter) > (Granatier::CellSize/2 - fabs(deltaStraightMove - deltaStraightCellCenter))) //check if it is in or already moved to perpendicular center and if it already can collide with a hurdle ***TODO: it seems to be wrong to use deltaStraightMove here, because ist could be greater than Granatier::CellSize
359 cellRow = curCellRow + yDirection - qAbs(xDirection)*signZeroPositive(deltaPerpendicularCellCenter);
360 cellCol = curCellCol + xDirection - qAbs(yDirection)*signZeroPositive(deltaPerpendicularCellCenter);
366 deltaPerpendicularMove = deltaPerpendicularCellCenter; //check if moved over perpendicular center
384 QList<Element*> bombElements = m_arena->getCell(cellRow, cellCol).getElements(Granatier::Element::BOMB);
499 if(m_badBonusCountdownTimer->isActive() && m_badBonusType == Granatier::Bonus::SCATTY && m_bombArmory > 0)
861 bonusUpdated(this, m_badBonusType, (badBonusCountdown - m_badBonusMillisecondsToElapse)/(badBonusCountdown/100.));
948 if(key == m_key.moveLeft || key == m_key.moveRight || key == m_key.moveUp || key == m_key.moveDown || key == m_key.dropBomb)
1005 if(key == m_key.moveLeft || key == m_key.moveRight || key == m_key.moveUp || key == m_key.moveDown || key == m_key.dropBomb)
void setInterval(int msec)
void clear()
const QString playerDesktopFilePath(const QString &strPlayerID) const
Definition: playersettings.cpp:134
void emitGameUpdated()
Emits a signal to PlayerItem in order to manage collisions.
Definition: player.cpp:804
Definition: granatierglobals.h:77
void setCellElement(const int p_row, const int p_column, Element *p_element)
Sets the Element that is on the Cell whose coordinates are given in parameters.
Definition: arena.cpp:72
Definition: granatierglobals.h:111
Definition: granatierglobals.h:109
This class describes the common characteristics and behaviour of the game characters (Players)...
Definition: character.h:31
Definition: granatierglobals.h:93
QString getDesktopFilePath() const
Gets the path to the Player Desktop file.
Definition: player.cpp:75
const QKeySequence keyUp(const QString &strPlayerID) const
Definition: playersettings.cpp:149
void keyPressed(QKeyEvent *keyEvent)
Manages the keys for moving and dropping bombs.
Definition: player.cpp:939
void bombDropped(Player *player, qreal x, qreal y, bool newBomb, int throwDistance)
Emitted when the player drops a bomb.
const QString playerName(const QString &strPlayerID) const
Definition: playersettings.cpp:129
QList< Element * > getElements() const
Gets all the Elements that are on the Cell.
Definition: cell.cpp:62
const QKeySequence keyRight(const QString &strPlayerID) const
Definition: playersettings.cpp:154
bool isAutoRepeat() const
void removeCellElement(const int p_row, const int p_column, Element *p_element)
Removes the Element that is on the Cell whose coordinates are given in parameters.
Definition: arena.cpp:81
Definition: granatierglobals.h:107
const QKeySequence keyDown(const QString &strPlayerID) const
Definition: playersettings.cpp:159
Definition: granatierglobals.h:115
void keyReleased(QKeyEvent *keyEvent)
Manages the keys for moving and dropping bombs.
Definition: player.cpp:996
const QKeySequence keyPutBomb(const QString &strPlayerID) const
Definition: playersettings.cpp:169
Player(qreal p_x, qreal p_y, const QString &p_playerID, const PlayerSettings *p_playerSettings, Arena *p_arena)
Creates a new Player instance.
Definition: player.cpp:35
int count(const T &value) const
void append(const T &value)
Definition: granatierglobals.h:129
void bonusUpdated(Player *player, Granatier::Bonus::Type bonusType, int percentageElapsed)
Emitted when the player has taken a bonus.
bool isEmpty() const
This class describes the common characteristics and behaviour of the bomb item.
Definition: bomb.h:30
void move()
Moves the Character function of its current coordinates and speed.
Definition: character.cpp:33
void setShortcuts(const Shortcuts &keys)
Shortcuts for moving and dropping bombs.
Definition: player.cpp:65
Definition: playersettings.h:27
const QString playerGraphicsFile(const QString &strPlayerID) const
Definition: playersettings.cpp:139
Definition: granatierglobals.h:110
int key() const
This class describes the common characteristics and behaviour of any game Element (character or item)...
Definition: element.h:32
void accept()
Definition: granatierglobals.h:94
void stop()
Definition: granatierglobals.h:114
Definition: granatierglobals.h:116
Definition: granatierglobals.h:106
int signZeroPositive(const qreal value)
Returns the sign of a value with a positive sign for zero.
Definition: player.cpp:1048
void resurrectBonusTaken()
Emitted when the player has taken the resurrect bonus.
T & last()
int getColFromX(const qreal p_x) const
Gets the column index corresponding to the given x-coordinate.
Definition: arena.cpp:154
bool isWalkable(Element *p_element) const
Returns if it is possible to move into the cell or not, because of a wall, bomb, etc.
Definition: cell.cpp:30
Definition: granatierglobals.h:128
void start(int msec)
const QKeySequence keyLeft(const QString &strPlayerID) const
Definition: playersettings.cpp:164
Definition: granatierglobals.h:108
bool isActive() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Definition: granatierglobals.h:73
Cell getCell(const int p_row, const int p_column) const
Gets the Cell at the given coordinates.
Definition: arena.cpp:120
Definition: granatierglobals.h:112
void slot_refillBombArmory()
refills the bomb armory after a bomb is exploded
Definition: player.cpp:838
int getRowFromY(const qreal p_y) const
Gets the row index corresponding to the given y-coordinate.
Definition: arena.cpp:144
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.