File indexing completed on 2024-04-28 07:51:01

0001 /*
0002     SPDX-FileCopyrightText: 2009 Mathias Kraus <k.hias@gmx.de>
0003     SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
0004     SPDX-FileCopyrightText: 2007-2008 Pierre-BenoƮt Besse <besse.pb@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef CHARACTER_H
0010 #define CHARACTER_H
0011 
0012 #include "element.h"
0013 
0014 #include <QKeySequence>
0015 
0016 
0017 /**
0018  * @brief This class describes the common characteristics and behaviour of the game characters (Players).
0019  */
0020 class Character : public Element {
0021 
0022 Q_OBJECT
0023 
0024 public:
0025 
0026     /** Keyboard shortcuts for moving and dropping a bomb */
0027     struct Shortcuts
0028     {
0029         QKeySequence moveLeft;
0030         QKeySequence moveRight;
0031         QKeySequence moveUp;
0032         QKeySequence moveDown;
0033         QKeySequence dropBomb;
0034     };
0035     Shortcuts m_key;
0036 
0037 protected:
0038 
0039     /** The Character x-speed */
0040     qreal m_xSpeed;
0041 
0042     /** The Character y-speed */
0043     qreal m_ySpeed;
0044 
0045     /** The character speed */
0046     qreal m_speed;
0047 
0048     /** Reference to the speed of the character when in "normal" behaviour */
0049     qreal m_normalSpeed;
0050 
0051     /** The maximum character speed */
0052     qreal m_maxSpeed;
0053 
0054 public:
0055 
0056     /**
0057       * Creates a new Character instance.
0058       * @param p_x the initial x-coordinate
0059       * @param p_y the initial y-coordinate
0060       * @param p_arena the Arena the Character is on
0061       */
0062     Character(qreal p_x, qreal p_y, Arena* p_arena);
0063 
0064     /**
0065       * Deletes the Character instance.
0066       */
0067     ~Character() override;
0068 
0069     /**
0070       * Makes the Character go up.
0071       */
0072     virtual void goUp() = 0;
0073 
0074     /**
0075       * Makes the Character go down.
0076       */
0077     virtual void goDown() = 0;
0078 
0079     /**
0080       * Makes the Character go to the right.
0081       */
0082     virtual void goRight() = 0;
0083 
0084     /**
0085       * Makes the Character go to the left.
0086       */
0087     virtual void goLeft() = 0;
0088 
0089     /**
0090       * Updates the Character move.
0091       */
0092     virtual void updateMove() = 0;
0093 
0094     /**
0095       * Moves the Character function of its current coordinates and speed.
0096       * If the character reaches a border, it circles around the arena and continue its way from the other side.
0097       */
0098     void move();
0099 
0100     /**
0101       * Manages the character death (essentially blinking).
0102       */
0103     void die();
0104 
0105     /**
0106       * Gets the Character x-speed value.
0107       * @return the x-speed value
0108       */
0109     qreal getXSpeed() const;
0110 
0111     /**
0112       * Gets the Character y-speed value.
0113       * @return the y-speed value
0114       */
0115     qreal getYSpeed() const;
0116 
0117     /**
0118       * Gets the Character speed.
0119       * @return the character speed
0120       */
0121     qreal getSpeed() const;
0122 
0123     /**
0124       * Gets the Character normal speed.
0125       * @return the character speed reference, when in "normal" behaviour
0126       */
0127     qreal getNormalSpeed() const;
0128 
0129     /**
0130       * Set the Character x-speed value.
0131       * @param p_xSpeed the x-speed to set
0132       */
0133       void setXSpeed(qreal p_xSpeed);
0134 
0135     /**
0136       * Set the Character y-speed value.
0137       * @param p_ySpeed the y-speed to set
0138       */
0139       void setYSpeed(qreal p_ySpeed);
0140 
0141     /**
0142       * Initializes the Character speed considering the difficulty level.
0143       */
0144     void initSpeed();
0145 
0146     /**
0147       * Checks the Character is in the line of sight of the given other Character.
0148       * @param p_character the other Character
0149       * @return true if the Character is in the same line than the given one
0150       */
0151     bool isInLineSight(Character* p_character) const;
0152 
0153 Q_SIGNALS:
0154 
0155     /**
0156       * Emitted when the character is dead.
0157       */
0158     void dead();
0159 };
0160 
0161 #endif
0162