31 #include <KStandardDirs>
32 #include <KGameRenderer>
34 const int PlayerItem::NB_FRAMES = 13;
35 const int PlayerItem::ANIM_SPEED = 240;
39 connect(p_model, SIGNAL(directionChanged()),
this, SLOT(
updateDirection()));
41 connect(p_model, SIGNAL(stopped()),
this, SLOT(
stopAnim()));
43 connect(p_model, SIGNAL(resurrected()),
this, SLOT(
resurrect()));
46 m_animationTimer =
new QTimeLine();
47 m_animationTimer->setCurveShape(QTimeLine::LinearCurve);
48 m_animationTimer->setLoopCount(0);
49 m_animationTimer->setFrameRange(0, NB_FRAMES - 1);
51 m_animationTimer->setDuration(PlayerItem::ANIM_SPEED);
52 connect(m_animationTimer, SIGNAL(frameChanged(
int)),
this, SLOT(
setFrame(
int)));
69 setSpriteKey(
"player_0");
74 m_fallingAnimationCounter = 0;
75 m_resurrectionAnimationCounter = 0;
80 delete m_animationTimer;
85 int nDirection = dynamic_cast <
Player*> (
m_model)->direction();
87 m_fallingAnimationCounter = 0;
88 m_resurrectionAnimationCounter = 10;
92 setSpriteKey(
"player_0");
104 transform.rotate(90);
107 transform.rotate(-90);
110 transform.rotate(180);
117 setTransform(transform);
126 int nDirection = dynamic_cast <
Player*> (
m_model)->direction();
129 QTransform transform;
138 transform.rotate(90);
141 transform.rotate(-90);
144 transform.rotate(180);
151 setTransform(transform);
162 QList<QGraphicsItem*> collidingList = collidingItems();
167 if (collidingList.size() > 1)
169 for (
int i = 0; i < collidingList.size(); ++i)
172 if (collidingList[i]->zValue() >= 300 && collidingList[i]->zValue() < 400)
176 if(collidingList[i]->zValue() == 315)
179 nExplosionID = dynamic_cast <
Bomb*> (bombItem->
getModel())->explosionID();
183 nExplosionID = dynamic_cast <
BombExplosionItem*> (collidingList[i])->explosionID();
186 if(dynamic_cast <Player*> (
m_model)->shield(nExplosionID) ==
false)
192 else if (collidingList[i]->zValue() == 100)
194 bonusItem = dynamic_cast <
BonusItem*> (collidingList[i]);
195 if(dynamic_cast <Bonus*> (bonusItem->
getModel())->isTaken() ==
false)
220 if (m_animationTimer->state() != QTimeLine::Running)
222 m_animationTimer->start();
229 if (m_animationTimer->state() == QTimeLine::Running)
231 m_animationTimer->setPaused(
true);
238 if (m_animationTimer->state() == QTimeLine::Paused)
240 m_animationTimer->setPaused(
false);
248 setSpriteKey(
"player_0");
250 if (m_animationTimer->state() != QTimeLine::NotRunning && m_resurrectionAnimationCounter == 0)
252 m_animationTimer->stop();
258 m_fallingAnimationCounter = 1;
263 if(
m_renderer->spriteExists(QString(
"player_%1").arg(p_frame)))
265 setSpriteKey(QString(
"player_%1").arg(p_frame));
267 if(m_fallingAnimationCounter > 0 || m_resurrectionAnimationCounter > 0)
270 int nDirection = dynamic_cast <
Player*> (
m_model)->direction();
292 if(m_fallingAnimationCounter > 0)
297 QTransform transform;
299 transform.rotate(angle);
300 setRenderSize(
m_renderSize * (1-m_fallingAnimationCounter*0.02));
301 transform.translate(-
m_itemSizeReal.width() * (1-m_fallingAnimationCounter*0.02) / 2.0, -
m_itemSizeReal.width() * (1-m_fallingAnimationCounter*0.02) / 2.0);
302 setTransform(transform);
303 m_fallingAnimationCounter++;
305 if(m_fallingAnimationCounter > 50)
308 dynamic_cast <Player*> (
m_model)->die();
313 if(m_resurrectionAnimationCounter > 0)
315 qreal resurrectionScale = 1;
316 QTransform transform;
318 transform.rotate(angle);
319 if(m_resurrectionAnimationCounter > 9)
321 resurrectionScale = 1.1;
323 else if(m_resurrectionAnimationCounter > 8)
325 resurrectionScale = 0.9;
327 else if(m_resurrectionAnimationCounter > 7)
329 resurrectionScale = 0.6;
331 else if(m_resurrectionAnimationCounter > 6)
333 resurrectionScale = 0.7;
335 else if(m_resurrectionAnimationCounter > 5)
337 resurrectionScale = 0.85;
339 else if(m_resurrectionAnimationCounter > 4)
341 resurrectionScale = 1;
343 else if(m_resurrectionAnimationCounter > 3)
345 resurrectionScale = 1.05;
347 else if(m_resurrectionAnimationCounter > 2)
349 resurrectionScale = 1.1;
351 else if(m_resurrectionAnimationCounter > 1)
353 resurrectionScale = 1.05;
355 else if(m_resurrectionAnimationCounter > 0)
357 resurrectionScale = 1;
360 m_resurrectionAnimationCounter--;
361 if(m_resurrectionAnimationCounter == 0)
363 resurrectionScale = 1;
369 setTransform(transform);
379 if(m_resurrectionAnimationCounter != 0)
381 QTransform transform;
385 setTransform(transform);
389 setSpriteKey(
"player_death");
void pauseAnim()
Pauses the PlayerItem animation.
virtual void update(qreal p_x, qreal p_y)
Updates the ElementItem coordinates.
This class represents a Bonus for the Player.
void startAnim()
Starts the PlayerItem animation.
This class is the graphical representation of a Bomb.
void resumeAnim()
Resumes the PlayerItem animation.
Element * getModel() const
Gets the Element model.
This class is the graphical representation of a Bonus.
~PlayerItem()
Deletes the PlayerItem instance.
void updateDirection()
Rotates the image function of the Player direction.
This class is the graphical representation of a Character.
const qreal CellSize
The Cell size.
Element * m_model
The instance of Element the ElementItem will represent.
PlayerItem(Player *p_model, KGameRenderer *renderer)
Creates a new PlayerItem instance.
This class is the graphical representation of a Bomb explosion.
This class describes the common characteristics and behaviour of the bomb item.
virtual void doActionOnCollision(Player *p_player)
Computes an action on a collision with the Player.
virtual void updateGraphicsInternal(qreal svgScaleFactor)
KGameRenderer * m_renderer
Shared renderer for the player frames.
void stopAnim()
Stops the PlayerItem animation.
void setFrame(const int p_frame)
Sets the given frame to the PlayerItem.
void manageCollision()
Manages the collisions with any Element.
void resurrect()
resurrects the playeritem
void updateGraphics(qreal svgScaleFactor)
void update(qreal p_x, qreal p_y)
Updates the PlayerItem coordinates.
void fallingAnimation()
the animation when falling in a hole
void bonusItemTaken(BonusItem *bonusItem)
void setDead()
Implements the CharacterItem method.
This class represents the main character of the game.