File indexing completed on 2024-04-28 04:01:50

0001 /*
0002     SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
0003     SPDX-FileCopyrightText: 2007-2008 Pierre-BenoƮt Besse <besse.pb@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef CHARACTER_H
0009 #define CHARACTER_H
0010 
0011 #include "element.h"
0012 
0013 /**
0014  * @brief This class describes the common characteristics and behaviour of the game characters (Kapman and the Ghost).
0015  */
0016 class Character : public Element
0017 {
0018     Q_OBJECT
0019 
0020 public:
0021     /** Speed on easy level */
0022     static const qreal LOW_SPEED;
0023 
0024     /** Speed on medium level */
0025     static const qreal MEDIUM_SPEED;
0026 
0027     /** Speed on hard level */
0028     static const qreal HIGH_SPEED;
0029 
0030     /** Speed increase on easy level (percentage)  */
0031     static const qreal LOW_SPEED_INC;
0032 
0033     /** Speed increase on medium level (percentage)  */
0034     static const qreal MEDIUM_SPEED_INC;
0035 
0036     /** Speed increase on hard level (percentage) */
0037     static const qreal HIGH_SPEED_INC;
0038 
0039 protected:
0040     /** The Character x-speed */
0041     qreal m_xSpeed;
0042 
0043     /** The Character y-speed */
0044     qreal m_ySpeed;
0045 
0046     /** The character speed */
0047     qreal m_speed;
0048 
0049     /** Reference to the speed of the character when in "normal" behaviour */
0050     qreal m_normalSpeed;
0051 
0052     /** The value the character's speed is incremented by when level up */
0053     qreal m_speedIncrease;
0054 
0055     /** The maximum character speed */
0056     qreal m_maxSpeed;
0057 
0058 public:
0059     /**
0060      * Creates a new Character instance.
0061      * @param p_x the initial x-coordinate
0062      * @param p_y the initial y-coordinate
0063      * @param p_maze the Maze the Character is on
0064      */
0065     Character(qreal p_x, qreal p_y, Maze *p_maze);
0066 
0067     /**
0068      * Deletes the Character instance.
0069      */
0070     ~Character() override;
0071 
0072     /**
0073      * Makes the Character go up.
0074      */
0075     virtual void goUp() = 0;
0076 
0077     /**
0078      * Makes the Character go down.
0079      */
0080     virtual void goDown() = 0;
0081 
0082     /**
0083      * Makes the Character go to the right.
0084      */
0085     virtual void goRight() = 0;
0086 
0087     /**
0088      * Makes the Character go to the left.
0089      */
0090     virtual void goLeft() = 0;
0091 
0092     /**
0093      * Updates the Character move.
0094      */
0095     virtual void updateMove() = 0;
0096 
0097     /**
0098      * Moves the Character function of its current coordinates and speed.
0099      * If the character reaches a border, it circles around the maze and continue its way from the other side.
0100      */
0101     void move();
0102 
0103     /**
0104      * Manages the character death (essentially blinking).
0105      */
0106     void die();
0107 
0108     /**
0109      * Gets the Character x-speed value.
0110      * @return the x-speed value
0111      */
0112     qreal getXSpeed() const;
0113 
0114     /**
0115      * Gets the Character y-speed value.
0116      * @return the y-speed value
0117      */
0118     qreal getYSpeed() const;
0119 
0120     /**
0121      * Gets the Character speed.
0122      * @return the character speed
0123      */
0124     qreal getSpeed() const;
0125 
0126     /**
0127      * Gets the Character normal speed.
0128      * @return the character speed reference, when in "normal" behaviour
0129      */
0130     qreal getNormalSpeed() const;
0131 
0132     /**
0133      * Set the Character x-speed value.
0134      * @param p_xSpeed the x-speed to set
0135      */
0136     void setXSpeed(qreal p_xSpeed);
0137 
0138     /**
0139      * Set the Character y-speed value.
0140      * @param p_ySpeed the y-speed to set
0141      */
0142     void setYSpeed(qreal p_ySpeed);
0143 
0144     /**
0145      * Initializes the Character speed considering the difficulty level.
0146      */
0147     void initSpeed();
0148 
0149     /**
0150      * Checks the Character is in the line of sight of the given other Character.
0151      * @param p_character the other Character
0152      * @return true if the Character is in the same line than the given one
0153      */
0154     bool isInLineSight(Character *p_character);
0155 
0156     /**
0157      * Increases the Character speed with each level completed.
0158      */
0159     void increaseCharactersSpeed();
0160 
0161 protected:
0162     /**
0163      * Initializes the Character speed increment considering the difficulty level.
0164      */
0165     virtual void initSpeedInc() = 0;
0166 
0167     /**
0168      * Gets the next Cell the Character is going to reach.
0169      * @return the next Cell the Character is going to reach
0170      */
0171     Cell getNextCell();
0172 
0173     /**
0174      * Checks the Character gets on a Cell center during its next movement.
0175      * @return true if the Character is on a Cell center, false otherwise
0176      */
0177     bool onCenter();
0178 
0179     /**
0180      * Checks whether the Character is currently on a Cell center.
0181      * @return true if the Character is on a Cell center, false otherwise
0182      */
0183     bool isOnCenter();
0184 
0185     /**
0186      * Moves the character on the center of its current Cell.
0187      */
0188     void moveOnCenter();
0189 
0190 Q_SIGNALS:
0191 
0192     /**
0193      * Emitted when the character is eaten.
0194      */
0195     void eaten();
0196 };
0197 
0198 #endif