File indexing completed on 2023-10-01 08:02:05
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 KAPMAN_H 0008 #define KAPMAN_H 0009 0010 #include "character.h" 0011 0012 /** 0013 * @brief This class represents the main character of the game. 0014 */ 0015 class Kapman : public Character 0016 { 0017 Q_OBJECT 0018 0019 private: 0020 /** Max speed ratio, compared with the initial speed */ 0021 static const qreal MAX_SPEED_RATIO; 0022 0023 /** Kapman asked speed */ 0024 qreal m_askedXSpeed, m_askedYSpeed; 0025 0026 public: 0027 /** 0028 * Creates a new Kapman instance. 0029 * @param p_x the initial x-coordinate 0030 * @param p_y the initial y-coordinate 0031 * @param p_maze the Maze the Kapman is on 0032 */ 0033 Kapman(qreal p_x, qreal p_y, Maze *p_maze); 0034 0035 /** 0036 * Deletes the Kapman instance. 0037 */ 0038 ~Kapman() override; 0039 0040 /** 0041 * Initializes the Kapman. 0042 */ 0043 void init(); 0044 0045 /** 0046 * Makes the Kapman ask to go up 0047 */ 0048 void goUp() override; 0049 0050 /** 0051 * Makes the Kapman ask to go down 0052 */ 0053 void goDown() override; 0054 0055 /** 0056 * Makes the Kapman ask to go to the right 0057 */ 0058 void goRight() override; 0059 0060 /** 0061 * Makes the Kapman ask to go to the left 0062 */ 0063 void goLeft() override; 0064 0065 /** 0066 * Updates the Kapman move 0067 */ 0068 void updateMove() override; 0069 0070 /** 0071 * @return the asked x speed value 0072 */ 0073 qreal getAskedXSpeed() const; 0074 0075 /** 0076 * @return the asked y speed value 0077 */ 0078 qreal getAskedYSpeed() const; 0079 0080 /** 0081 * Manages the points won 0082 * @param p_element reference to the element eaten 0083 */ 0084 void winPoints(Element *p_element); 0085 0086 /** 0087 * Implements the Character function 0088 */ 0089 void die(); 0090 0091 /** 0092 * Emits a signal to Kapmanitem in order to manage collisions 0093 */ 0094 void emitGameUpdated(); 0095 0096 /** 0097 * Initializes the Kapman speed from the Character speed. 0098 */ 0099 void initSpeedInc() override; 0100 0101 private: 0102 /** 0103 * Updates the Kapman direction with the asked direction 0104 */ 0105 void updateDirection(); 0106 0107 /** 0108 * @return the next cell the kapman will move on with its asked direction 0109 */ 0110 Cell getAskedNextCell(); 0111 0112 /** 0113 * Stops moving the Kapman 0114 */ 0115 void stopMoving(); 0116 0117 Q_SIGNALS: 0118 0119 /** 0120 * Emitted when the direction changed 0121 */ 0122 void directionChanged(); 0123 0124 /** 0125 * Signals to the game that the kapman win points 0126 * @param p_element reference to the element eaten 0127 */ 0128 void sWinPoints(Element *p_element); 0129 0130 /** 0131 * Signals to Kapmanitem that the game has been updated 0132 */ 0133 void gameUpdated(); 0134 0135 /** 0136 * Emitted when the kapman stops moving 0137 */ 0138 void stopped(); 0139 }; 0140 0141 #endif