File indexing completed on 2024-12-08 06:45:33
0001 /* 0002 SPDX-FileCopyrightText: 2009 Mathias Kraus <k.hias@gmx.de> 0003 SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef PLAYERITEM_H 0009 #define PLAYERITEM_H 0010 0011 #include "characteritem.h" 0012 0013 class QTimeLine; 0014 class Player; 0015 class BonusItem; 0016 class KGameRenderer; 0017 0018 /** 0019 * @brief This class manage the display of the Player. 0020 */ 0021 class PlayerItem : public CharacterItem 0022 { 0023 Q_OBJECT 0024 0025 private: 0026 0027 /** Number of frames to animate the PlayerItem */ 0028 static const int NB_FRAMES; 0029 0030 /** Animation update interval */ 0031 static const int ANIM_SPEED; 0032 0033 /** Timer used to animate the PlayerItem */ 0034 QTimeLine* m_animationTimer; 0035 0036 /** Counter for falling animation */ 0037 int m_fallingAnimationCounter; 0038 0039 /** Counter for resurrection animation */ 0040 int m_resurrectionAnimationCounter; 0041 0042 /** player ID */ 0043 QString m_strPlayerId; 0044 0045 public: 0046 0047 /** 0048 * Creates a new PlayerItem instance. 0049 * @param p_model the Player model 0050 * @param renderer the KGameRenderer 0051 */ 0052 explicit PlayerItem(Player* p_model, KGameRenderer* renderer); 0053 0054 /** 0055 * Deletes the PlayerItem instance. 0056 */ 0057 ~PlayerItem() override; 0058 0059 public Q_SLOTS: 0060 0061 /** 0062 * Rotates the image function of the Player direction. 0063 */ 0064 void updateDirection(); 0065 0066 void updateGraphics(qreal svgScaleFactor) override; 0067 0068 /** 0069 * Manages the collisions with any Element. 0070 */ 0071 void manageCollision(); 0072 0073 /** 0074 * Updates the PlayerItem coordinates. 0075 * @param p_x the new x-coordinate 0076 * @param p_y the new y-coordinate 0077 */ 0078 void update(qreal p_x, qreal p_y) override; 0079 0080 /** 0081 * Starts the PlayerItem animation. 0082 */ 0083 void startAnim(); 0084 0085 /** 0086 * Pauses the PlayerItem animation. 0087 */ 0088 void pauseAnim(); 0089 0090 /** 0091 * Resumes the PlayerItem animation. 0092 */ 0093 void resumeAnim(); 0094 0095 /** 0096 * Stops the PlayerItem animation. 0097 */ 0098 void stopAnim(); 0099 0100 /** 0101 * the animation when falling in a hole 0102 */ 0103 void fallingAnimation(); 0104 0105 /** 0106 * Sets the given frame to the PlayerItem. 0107 * @param p_frame the frame to set 0108 */ 0109 void setFrame(const int p_frame); 0110 0111 /** 0112 * Implements the CharacterItem method. 0113 */ 0114 void setDead() override; 0115 0116 /** 0117 * resurrects the playeritem 0118 */ 0119 void resurrect(); 0120 0121 Q_SIGNALS: 0122 void bonusItemTaken(BonusItem* bonusItem); 0123 }; 0124 0125 #endif 0126