Changeset View
Changeset View
Standalone View
Standalone View
board.h
Show All 24 Lines | |||||
25 | #include <QSize> | 25 | #include <QSize> | ||
26 | 26 | | |||
27 | #include "gameobject.h" | 27 | #include "gameobject.h" | ||
28 | #include "renderer.h" | 28 | #include "renderer.h" | ||
29 | 29 | | |||
30 | #define TILE_NUM_H 20 | 30 | #define TILE_NUM_H 20 | ||
31 | #define TILE_NUM_W 32 | 31 | #define TILE_NUM_W 32 | ||
32 | 32 | | |||
33 | | ||||
34 | class KBounceBall; | 33 | class KBounceBall; | ||
35 | class KBounceWall; | 34 | class KBounceWall; | ||
36 | 35 | | |||
37 | class KBounceBoard: public QGraphicsObject | 36 | class KBounceBoard: public QGraphicsObject | ||
38 | { | 37 | { | ||
39 | Q_OBJECT | 38 | Q_OBJECT | ||
40 | 39 | | |||
41 | public: | 40 | public: | ||
42 | enum TileType{ Empty, Free, Border, Wall, Temp }; | 41 | enum TileType{ Empty, Free, Border, Wall, Temp }; | ||
43 | 42 | | |||
43 | /** | ||||
44 | * Constructor to set game board configurations | ||||
45 | * @see board.cpp | ||||
46 | */ | ||||
44 | explicit KBounceBoard( KBounceRenderer *renderer ); | 47 | explicit KBounceBoard(KBounceRenderer *renderer); | ||
48 | | ||||
49 | /** | ||||
50 | * KbounceBoard destructor | ||||
51 | * @see board.cpp | ||||
52 | */ | ||||
45 | ~KBounceBoard(); | 53 | ~KBounceBoard(); | ||
46 | 54 | | |||
55 | /** | ||||
56 | * Paint walls on board | ||||
57 | * @param background canvas context | ||||
58 | * @return canvas painted | ||||
59 | * @see board.cpp | ||||
60 | */ | ||||
47 | QPixmap applyWallsOn(const QPixmap &background) const; | 61 | QPixmap applyWallsOn(const QPixmap &background) const; | ||
62 | | ||||
63 | /** | ||||
64 | * Resize the board and their components | ||||
65 | * @param size new size | ||||
66 | * @see board.cpp | ||||
67 | */ | ||||
48 | void resize( QSize& size ); | 68 | void resize(QSize& size); | ||
49 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE {} | 69 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE {} | ||
50 | 70 | | |||
71 | /** | ||||
72 | * Set variables to start a new level | ||||
73 | * @param level new level | ||||
74 | * @see board.cpp | ||||
75 | */ | ||||
51 | void newLevel( int level ); | 76 | void newLevel(int level); | ||
77 | | ||||
78 | /** | ||||
79 | * Pause the timer | ||||
80 | * @param flag "T" to pause "F" to unpause | ||||
81 | * @see board.cpp | ||||
82 | */ | ||||
52 | void setPaused( bool ); | 83 | void setPaused(bool); | ||
53 | 84 | | |||
85 | /** | ||||
86 | * Build a wall | ||||
87 | * @param pos mouse position | ||||
88 | * @param vertical wall orientation | ||||
89 | * @see board.cpp | ||||
90 | */ | ||||
54 | void buildWall( const QPointF& pos, bool vertical ); | 91 | void buildWall(const QPointF& pos, bool vertical); | ||
55 | 92 | | |||
93 | /** | ||||
94 | * Get ball ammount | ||||
95 | * @return ball ammount | ||||
96 | * @see board.cpp | ||||
97 | */ | ||||
56 | int balls(); | 98 | int balls(); | ||
99 | | ||||
100 | /** | ||||
101 | * Get filled percentage | ||||
102 | * @return filled percentage | ||||
103 | * @see board.cpp | ||||
104 | */ | ||||
57 | int filled(); | 105 | int filled(); | ||
58 | 106 | | |||
59 | KBounceCollision checkCollision( void* object, const QRectF& rect, int type ); | 107 | /** | ||
60 | KBounceCollision checkCollisionTiles( const QRectF& rect ); | 108 | * Check for collisions on all objects | ||
109 | * @see board.cpp | ||||
110 | */ | ||||
61 | void checkCollisions(); | 111 | void checkCollisions(); | ||
62 | 112 | | |||
113 | /** | ||||
114 | * Set ball velocity | ||||
115 | * @param vel new velocity | ||||
yurchor: @param velocity | |||||
116 | * @see board.cpp | ||||
117 | */ | ||||
118 | void setBallVelocity(qreal velocity); | ||||
119 | | ||||
120 | /** | ||||
121 | * Set wall velocity | ||||
122 | * @param vel new velocity | ||||
yurchor: @param velocity | |||||
123 | * @see board.cpp | ||||
124 | */ | ||||
125 | void setWallVelocity(qreal velocity); | ||||
126 | | ||||
127 | /** | ||||
128 | * Get map tile position | ||||
129 | * @param pos mouse position | ||||
130 | * @return tile position | ||||
131 | * @see board.cpp | ||||
132 | */ | ||||
63 | QPoint mapPosition( const QPointF& pos ) const; | 133 | QPoint mapPosition(const QPointF& pos) const; | ||
134 | | ||||
135 | /** | ||||
136 | * Get tile template | ||||
137 | * @return tile template | ||||
138 | * @see board.cpp | ||||
139 | */ | ||||
64 | QRectF boundingRect() const Q_DECL_OVERRIDE; | 140 | QRectF boundingRect() const Q_DECL_OVERRIDE; | ||
65 | 141 | | |||
66 | void setBallVelocity(qreal velocity); | 142 | /** | ||
67 | void setWallVelocity(qreal velocity); | 143 | * Check object collision | ||
144 | * @param object Object to be checked | ||||
145 | * @param rect tile rectangle | ||||
146 | * @param type object type | ||||
147 | * @return collision result | ||||
148 | * @see board.cpp | ||||
149 | */ | ||||
150 | KBounceCollision checkCollision(void* object, const QRectF& rect, int type); | ||||
151 | | ||||
152 | /** | ||||
153 | * Check for collision to get bounce "normal" | ||||
154 | * @param rect tile rectangle | ||||
155 | * @return collision result | ||||
156 | * @see board.cpp | ||||
157 | */ | ||||
158 | KBounceCollision checkCollisionTiles(const QRectF& rect); | ||||
159 | | ||||
68 | signals: | 160 | signals: | ||
161 | /** | ||||
162 | * Signal to update balls ammount | ||||
163 | * @see board.cpp | ||||
164 | */ | ||||
69 | void ballsChanged( int balls ); | 165 | void ballsChanged(int balls); | ||
166 | | ||||
167 | /** | ||||
168 | * Signal to update fill percentage | ||||
169 | * @see board.cpp | ||||
170 | */ | ||||
70 | void fillChanged( int fill ); | 171 | void fillChanged(int fill); | ||
172 | | ||||
173 | /** | ||||
174 | * Signal to update a wall death | ||||
175 | * @see board.cpp | ||||
176 | */ | ||||
71 | void wallDied(); | 177 | void wallDied(); | ||
72 | 178 | | |||
73 | protected slots: | 179 | protected slots: | ||
180 | | ||||
181 | /** | ||||
182 | * Event to apply tick changes | ||||
183 | * @see board.cpp | ||||
184 | */ | ||||
74 | void tick(); | 185 | void tick(); | ||
186 | | ||||
187 | /** | ||||
188 | * Insert wall and paint them | ||||
189 | * @param x1 initial x position | ||||
190 | * @param y1 initial x position | ||||
191 | * @param x2 final y position | ||||
192 | * @param y2 final y position | ||||
193 | * @see board.cpp | ||||
194 | */ | ||||
75 | void wallFinished( int x1, int y1, int x2, int y2 ); | 195 | void wallFinished(int x1, int y1, int x2, int y2); | ||
76 | 196 | | |||
77 | private: | 197 | private: | ||
198 | | ||||
199 | /** | ||||
200 | * Clear the board | ||||
201 | * @see board.cpp | ||||
202 | */ | ||||
78 | void clear(); | 203 | void clear(); | ||
204 | | ||||
205 | /** | ||||
206 | * Fill the tile | ||||
207 | * @param x position x | ||||
208 | * @param y position y | ||||
209 | * @see board.cpp | ||||
210 | */ | ||||
79 | void fill( int x, int y ); | 211 | void fill(int x, int y); | ||
80 | 212 | | |||
81 | KBounceRenderer* m_renderer; | 213 | KBounceRenderer* m_renderer; | ||
82 | 214 | | |||
83 | TileType m_tiles[TILE_NUM_W][TILE_NUM_H]; | 215 | TileType m_tiles[TILE_NUM_W][TILE_NUM_H]; | ||
84 | QSize m_tileSize; | 216 | QSize m_tileSize; | ||
85 | int m_filled; | | |||
86 | 217 | | |||
87 | QList<KBounceBall*> m_balls; | 218 | QList<KBounceBall*> m_list_balls; | ||
aacid: this rename is useless | |||||
88 | QList<KBounceWall*> m_walls; | 219 | QList<KBounceWall*> m_list_walls; | ||
89 | 220 | | |||
90 | QTimer* m_clock; | 221 | QTimer* m_clock; | ||
91 | 222 | | |||
92 | | ||||
93 | qreal m_ballVelocity; | 223 | qreal m_ballVelocity; | ||
94 | qreal m_wallVelocity; | 224 | qreal m_wallVelocity; | ||
225 | | ||||
226 | int m_filled; | ||||
95 | }; | 227 | }; | ||
96 | 228 | | |||
97 | #endif // BOARD_H | 229 | #endif // BOARD_H |
@param velocity