25 #include <QGraphicsScene>
26 #include <KgDifficulty>
28 const int KapmanItem::NB_FRAMES = 32;
29 const int KapmanItem::ANIM_LOW_SPEED = 500;
30 const int KapmanItem::ANIM_MEDIUM_SPEED = 400;
31 const int KapmanItem::ANIM_HIGH_SPEED = 300;
34 connect(p_model, SIGNAL(directionChanged()),
this, SLOT(
updateDirection()));
36 connect(p_model, SIGNAL(stopped()),
this, SLOT(
stopAnim()));
39 m_animationTimer =
new QTimeLine();
40 m_animationTimer->setCurveShape(QTimeLine::SineCurve);
41 m_animationTimer->setLoopCount(0);
42 m_animationTimer->setFrameRange(0, NB_FRAMES - 1);
44 switch ((
int) Kg::difficultyLevel())
46 case KgDifficultyLevel::Easy:
47 m_animationTimer->setDuration(KapmanItem::ANIM_LOW_SPEED);
49 case KgDifficultyLevel::Medium:
50 m_animationTimer->setDuration(KapmanItem::ANIM_MEDIUM_SPEED);
52 case KgDifficultyLevel::Hard:
53 m_animationTimer->setDuration(KapmanItem::ANIM_HIGH_SPEED);
56 connect(m_animationTimer, SIGNAL(frameChanged(
int)),
this, SLOT(
setFrame(
int)));
65 delete m_animationTimer;
85 if (m_rotationFlag==0) {
89 transform.translate(boundingRect().width() / 2, boundingRect().height() / 2);
90 transform.rotate(angle);
91 transform.translate(-boundingRect().width() / 2, -boundingRect().height() / 2);
92 setTransform(transform);
96 QList<QGraphicsItem*> collidingList = collidingItems();
100 if (collidingList.size() > 1) {
101 for (
int i = 0; i < collidingList.size(); ++i) {
103 if (collidingList[i]->zValue() >= 0) {
124 if (m_animationTimer->state() != QTimeLine::Running) {
125 m_animationTimer->start();
130 if (m_animationTimer->state() == QTimeLine::Running)
131 m_animationTimer->setPaused(
true);
135 if (m_animationTimer->state() == QTimeLine::Running)
136 m_animationTimer->setPaused(
false);
140 setElementId(
"kapman_0");
141 if (m_animationTimer->state() == QTimeLine::Running)
142 m_animationTimer->stop();
146 setElementId(QString(
"kapman_%1").arg(p_frame));
151 setElementId(
"kapman_0");
158 setElementId(
"kapman_0");
160 setElementId(
"kapman_blink");
qreal getXSpeed() const
Gets the Character x-speed value.
virtual void update(qreal p_x, qreal p_y)
Updates the ElementItem coordinates.
void pauseAnim()
Pauses the KapmanItem animation.
virtual void startBlinking()
Starts the character blinking.
QTimer * m_blinkTimer
Timer used to make the character blink.
~KapmanItem()
Deletes the KapmanItem instance.
void stopAnim()
Stops the KapmanItem animation.
void update(qreal p_x, qreal p_y)
Updates the KapmanItem coordinates.
Element * getModel() const
Gets the Element model.
This class is the graphical representation of a Character.
void startAnim()
Starts the KapmanItem animation.
qreal getYSpeed() const
Gets the Character y-speed value.
virtual void doActionOnCollision(Kapman *p_kapman)
Computes an action on a collision with the Kapman.
void startBlinking()
Implements the CharacterItem method.
KapmanItem(Kapman *p_model)
Creates a new KapmanItem instance.
void resumeAnim()
Resumes the KapmanItem animation.
void setFrame(const int p_frame)
Sets the given frame to the KapmanItem.
This class is the graphical representation of a game Element.
void updateDirection()
Rotates the image function of the Kapman direction.
virtual void blink()
Makes the character blink.
void blink()
Implements the CharacterItem method.
int m_nbBlinks
Number of ticks of the blink timer.
void manageCollision()
Manages the collisions with any Element.
This class represents the main character of the game.