File indexing completed on 2024-04-21 04:01:57

0001 /*
0002     SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef CHARACTERITEM_H
0008 #define CHARACTERITEM_H
0009 
0010 #include "character.h"
0011 #include "elementitem.h"
0012 
0013 #include <QTimer>
0014 
0015 /**
0016  * @brief This class is the graphical representation of a Character.
0017  */
0018 class CharacterItem : public ElementItem
0019 {
0020     Q_OBJECT
0021 
0022 protected:
0023     /** Timer used to make the character blink */
0024     QTimer *m_blinkTimer = nullptr;
0025 
0026     /** Number of ticks of the blink timer */
0027     int m_nbBlinks;
0028 
0029 public:
0030     /**
0031      * Creates a new CharacterItem instance.
0032      * @param p_model the Character model
0033      */
0034     explicit CharacterItem(Character *p_model);
0035 
0036     /**
0037      * Deletes the CharacterItem instance.
0038      */
0039     ~CharacterItem() override;
0040 
0041     /**
0042      * Overrides the default shape function to make it a small circle
0043      * This function is used to determinate collision between items
0044      * @return QPainterPath the new shape of the Character
0045      */
0046     QPainterPath shape() const override;
0047 
0048 public Q_SLOTS:
0049 
0050     /**
0051      * Updates the CharacterItem coordinates.
0052      * @param p_x the new x-coordinate
0053      * @param p_y the new y-coordinate
0054      */
0055     void update(qreal p_x, qreal p_y) override;
0056 
0057     /**
0058      * Starts the character blinking.
0059      */
0060     virtual void startBlinking();
0061 
0062     /**
0063      * Makes the character blink.
0064      */
0065     virtual void blink();
0066 };
0067 
0068 #endif