File indexing completed on 2024-02-18 04:03:24

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 ELEMENT_H
0009 #define ELEMENT_H
0010 
0011 #include "granatierglobals.h"
0012 
0013 #include <QObject>
0014 
0015 class Arena;
0016 class Player;
0017 
0018 /**
0019  * @brief This class describes the common characteristics and behaviour of any game Element (character or item).
0020  */
0021 class Element : public QObject {
0022 
0023 Q_OBJECT
0024 
0025 protected:
0026 
0027     /** The Element type */
0028     Granatier::Element::Type m_type;
0029 
0030     /** The Element initial x-coordinate */
0031     qreal m_xInit;
0032 
0033     /** The Element initial y-coordinate */
0034     qreal m_yInit;
0035 
0036     /** The Element current x-coordinate */
0037     qreal m_x;
0038 
0039     /** The Element current y-coordinate */
0040     qreal m_y;
0041 
0042     /** The Arena the Element is on */
0043     Arena* m_arena;
0044 
0045     /** The Id of the Element */
0046     QString m_imageId;
0047 
0048 public:
0049 
0050     /**
0051       * Creates a new Element instance.
0052       * @param p_x the initial x-coordinate
0053       * @param p_y the initial y-coordinate
0054       * @param p_arena the Arena the Element is on
0055       */
0056     Element(qreal p_x, qreal p_y, Arena* p_arena);
0057 
0058     /**
0059       * Deletes the Element instance.
0060       */
0061     ~Element() override;
0062 
0063     /**
0064       * Computes an action on a collision with the Player.
0065       * @param p_player the instance of Player which collides with the Element
0066       */
0067     virtual void doActionOnCollision(Player* p_player);
0068 
0069     /**
0070       * Sets arena for the element.
0071       * @param p_arena arena
0072       */
0073     void setArena(Arena* p_arena);
0074 
0075     /**
0076       * Sets the path initial position.
0077       * @param p_x x coordinate of the initial position
0078       * @param p_y y coordinate of the initial position
0079       */
0080     void setInitialCoordinates (qreal p_x, qreal p_y);
0081 
0082     /**
0083       * Gets the path to the Element image.
0084       * @return the path to the Element image
0085       */
0086     QString getImageId() const;
0087 
0088     /**
0089       * Gets the type of the Element.
0090       * @return the Element type
0091       */
0092     Granatier::Element::Type getType() const;
0093 
0094     /**
0095       * Sets the Element image.
0096       * @param p_imageId the image to set
0097       */
0098     void setImageId(const QString & p_imageId);
0099 
0100     /**
0101       * Gets the Element x-coordinate.
0102       * @return the x-coordinate
0103       */
0104     qreal getX() const;
0105 
0106     /**
0107       * Gets the Element y-coordinate.
0108       * @return the y-coordinate
0109       */
0110     qreal getY() const;
0111 
0112     /**
0113       * Sets the Element x-coordinate to the given value
0114       * @param p_x the x-coordinate to set
0115       */
0116     void setX(qreal p_x);
0117 
0118     /**
0119       * Sets the Element y-coordinate to the given value
0120       * @param p_y the y-coordinate to set
0121       */
0122     void setY(qreal p_y);
0123 
0124     /**
0125     * Initializes Element x-coordinate and y-coordinate with
0126     * initial values
0127     */
0128     void initCoordinate();
0129 
0130 Q_SIGNALS:
0131 
0132     /**
0133       * Emitted on Element move.
0134       * @param p_x the new x-coordinate
0135       * @param p_y the new y-coordinate
0136       */
0137     void moved(qreal p_x, qreal p_y);
0138 };
0139 
0140 #endif
0141