1 /*
2     SPDX-FileCopyrightText: 2009 Mathias Kraus <k.hias@gmx.de>
3     SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
4 
5     SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #ifndef ELEMENT_H
9 #define ELEMENT_H
10 
11 #include "granatierglobals.h"
12 
13 #include <QObject>
14 
15 class Arena;
16 class Player;
17 
18 /**
19  * @brief This class describes the common characteristics and behaviour of any game Element (character or item).
20  */
21 class Element : public QObject {
22 
23 Q_OBJECT
24 
25 protected:
26 
27     /** The Element type */
28     Granatier::Element::Type m_type;
29 
30     /** The Element initial x-coordinate */
31     qreal m_xInit;
32 
33     /** The Element initial y-coordinate */
34     qreal m_yInit;
35 
36     /** The Element current x-coordinate */
37     qreal m_x;
38 
39     /** The Element current y-coordinate */
40     qreal m_y;
41 
42     /** The Arena the Element is on */
43     Arena* m_arena;
44 
45     /** The Id of the Element */
46     QString m_imageId;
47 
48 public:
49 
50     /**
51       * Creates a new Element instance.
52       * @param p_x the initial x-coordinate
53       * @param p_y the initial y-coordinate
54       * @param p_arena the Arena the Element is on
55       */
56     Element(qreal p_x, qreal p_y, Arena* p_arena);
57 
58     /**
59       * Deletes the Element instance.
60       */
61     ~Element() override;
62 
63     /**
64       * Computes an action on a collision with the Player.
65       * @param p_player the instance of Player which collides with the Element
66       */
67     virtual void doActionOnCollision(Player* p_player);
68 
69     /**
70       * Sets arena for the element.
71       * @param p_arena arena
72       */
73     void setArena(Arena* p_arena);
74 
75     /**
76       * Sets the path initial position.
77       * @param p_x x coordinate of the initial position
78       * @param p_y y coordinate of the initial position
79       */
80     void setInitialCoordinates (qreal p_x, qreal p_y);
81 
82     /**
83       * Gets the path to the Element image.
84       * @return the path to the Element image
85       */
86     QString getImageId() const;
87 
88     /**
89       * Gets the type of the Element.
90       * @return the Element type
91       */
92     Granatier::Element::Type getType() const;
93 
94     /**
95       * Sets the Element image.
96       * @param p_imageId the image to set
97       */
98     void setImageId(const QString & p_imageId);
99 
100     /**
101       * Gets the Element x-coordinate.
102       * @return the x-coordinate
103       */
104     qreal getX() const;
105 
106     /**
107       * Gets the Element y-coordinate.
108       * @return the y-coordinate
109       */
110     qreal getY() const;
111 
112     /**
113       * Sets the Element x-coordinate to the given value
114       * @param p_x the x-coordinate to set
115       */
116     void setX(qreal p_x);
117 
118     /**
119       * Sets the Element y-coordinate to the given value
120       * @param p_y the y-coordinate to set
121       */
122     void setY(qreal p_y);
123 
124     /**
125     * Initializes Element x-coordinate and y-coordinate with
126     * initial values
127     */
128     void initCoordinate();
129 
130 Q_SIGNALS:
131 
132     /**
133       * Emitted on Element move.
134       * @param p_x the new x-coordinate
135       * @param p_y the new y-coordinate
136       */
137     void moved(qreal p_x, qreal p_y);
138 };
139 
140 #endif
141 
142