Revision 340
more changes in ent.h, ent.c
ent.h | ||
---|---|---|
11 | 11 |
#include "basic_sprite.h" |
12 | 12 |
#include "list.h" |
13 | 13 |
|
14 |
/** |
|
15 |
* @brief Set scale. |
|
16 |
* @param n Scale |
|
17 |
*/ |
|
14 | 18 |
void (ent_set_scale) (double n); |
19 |
/** |
|
20 |
* @brief Set origin of screen (upper-left corner) in game referential coordinates. |
|
21 |
* @param x X-position of the upper-left corner of the screen |
|
22 |
* @param y Y-position of the upper-left corner of the screen |
|
23 |
*/ |
|
15 | 24 |
void (ent_set_origin)(double x, double y); |
16 |
|
|
25 |
/** |
|
26 |
* @brief Get scale. |
|
27 |
* @return Scale |
|
28 |
*/ |
|
17 | 29 |
double (ent_get_scale) (void); |
30 |
/** |
|
31 |
* @brief Get X-length of the screen in game referencial coordinates. |
|
32 |
* @return X-length |
|
33 |
*/ |
|
18 | 34 |
double (ent_get_XLength)(void); |
35 |
/** |
|
36 |
* @brief Get Y-length of the screen in game referencial coordinates. |
|
37 |
* @return Y-length |
|
38 |
*/ |
|
19 | 39 |
double (ent_get_YLength)(void); |
20 | 40 |
|
21 | 41 |
/** |
... | ... | |
30 | 50 |
* @{ |
31 | 51 |
*/ |
32 | 52 |
|
53 |
/// @brief Identifier of a melee gunner |
|
33 | 54 |
#define GUNNER_MELEE BIT(0) |
55 |
/// @brief Identifier of a ranged gunner |
|
34 | 56 |
#define GUNNER_RANGED BIT(1) |
57 |
/// @brief Identifier of a player-controlled gunner |
|
35 | 58 |
#define GUNNER_PLAYER BIT(2) |
59 |
/// @brief Identifier of an automatic follower gunner |
|
36 | 60 |
#define GUNNER_FOLLOW BIT(3) |
37 | 61 |
|
62 |
/** |
|
63 |
* @brief Gunner. |
|
64 |
*/ |
|
38 | 65 |
typedef struct gunner gunner_t; |
66 |
/** |
|
67 |
* @brief Construct gunner. |
|
68 |
* @param dude Basic sprite representing the gunner |
|
69 |
* @param weapon Basic sprite representing the weapon of the gunner |
|
70 |
* @param type Type of gunner. Can be one of the identifier macros and also the OR-merge of any combination of them |
|
71 |
* @param team Team of the gunner. 1 for player 1, 2 for player 2, 3 for opponents and 0 for no team (temporary gunner) |
|
72 |
*/ |
|
39 | 73 |
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon, uint16_t type, int team); |
74 |
/** |
|
75 |
* @brief Destruct gunner. |
|
76 |
* @param p Pointer to gunner to be destructed |
|
77 |
*/ |
|
40 | 78 |
void (gunner_dtor)(gunner_t *p); |
79 |
/** |
|
80 |
* @brief Set gunner position. |
|
81 |
* @param p Pointer to gunner |
|
82 |
* @param x X-position of the gunner in game coordinates |
|
83 |
* @param y Y-position of the gunner in game coordinates |
|
84 |
*/ |
|
41 | 85 |
void (gunner_set_pos) (gunner_t *p, double x, double y); |
86 |
/** |
|
87 |
* @brief Set gunner spawn position. |
|
88 |
* @param p Pointer to gunner |
|
89 |
* @param x Spawn X-position of the gunner in game coordinates |
|
90 |
* @param y Spawn Y-position of the gunner in game coordinates |
|
91 |
*/ |
|
42 | 92 |
void (gunner_set_spawn) (gunner_t *p, double x, double y); |
43 |
void (gunner_set_angle) (gunner_t *p, double angle ); |
|
93 |
/** |
|
94 |
* @brief Set gunner angle. |
|
95 |
* @param p Pointer to gunner |
|
96 |
* @param angle Angle in radians |
|
97 |
*/ |
|
98 |
void (gunner_set_angle) (gunner_t *p, double angle); |
|
99 |
/** |
|
100 |
* @brief Set gunner health (total, max health). |
|
101 |
* @param p Pointer to gunner |
|
102 |
* @param health Health |
|
103 |
*/ |
|
44 | 104 |
void (gunner_set_health) (gunner_t *p, double health); |
105 |
/** |
|
106 |
* @brief Set gunner current health. |
|
107 |
* @param p Pointer to gunner |
|
108 |
* @param health Current health |
|
109 |
*/ |
|
45 | 110 |
void (gunner_set_curr_health) (gunner_t *p, double health); |
111 |
/** |
|
112 |
* @brief Get gunner X-position. |
|
113 |
* @param p Pointer to gunner |
|
114 |
* @return X-position of the gunner |
|
115 |
*/ |
|
46 | 116 |
double (gunner_get_x) (const gunner_t *p); |
117 |
/** |
|
118 |
* @brief Get gunner Y-position. |
|
119 |
* @param p Pointer to gunner |
|
120 |
* @return Y-position of the gunner |
|
121 |
*/ |
|
47 | 122 |
double (gunner_get_y) (const gunner_t *p); |
123 |
/** |
|
124 |
* @brief Get gunner spawn X-position. |
|
125 |
* @param p Pointer to gunner |
|
126 |
* @return Spawn X-position of the gunner |
|
127 |
*/ |
|
48 | 128 |
double (gunner_get_spawn_x) (const gunner_t *p); |
129 |
/** |
|
130 |
* @brief Get gunner spawn Y-position. |
|
131 |
* @param p Pointer to gunner |
|
132 |
* @return Spawn Y-position of the gunner |
|
133 |
*/ |
|
49 | 134 |
double (gunner_get_spawn_y) (const gunner_t *p); |
135 |
/** |
|
136 |
* @brief Get gunner angle. |
|
137 |
* @param p Pointer to gunner |
|
138 |
* @return Angle of the gunner |
|
139 |
*/ |
|
50 | 140 |
double (gunner_get_angle) (const gunner_t *p); |
141 |
/** |
|
142 |
* @brief Get gunner max health. |
|
143 |
* @param p Pointer to gunner |
|
144 |
* @return Max health of the gunner |
|
145 |
*/ |
|
51 | 146 |
double (gunner_get_health) (const gunner_t *p); |
147 |
/** |
|
148 |
* @brief Get gunner current health. |
|
149 |
* @param p Pointer to gunner |
|
150 |
* @return Current health of the gunner |
|
151 |
*/ |
|
52 | 152 |
double (gunner_get_curr_health) (const gunner_t *p); |
153 |
/** |
|
154 |
* @brief Get gunner X-position in screen coordinates. |
|
155 |
* @param p Pointer to gunner |
|
156 |
* @return X-position of the gunner in screen coordinates |
|
157 |
*/ |
|
53 | 158 |
int16_t (gunner_get_x_screen) (const gunner_t *p); |
159 |
/** |
|
160 |
* @brief Get gunner Y-position in screen coordinates. |
|
161 |
* @param p Pointer to gunner |
|
162 |
* @return Y-position of the gunner in screen coordinates |
|
163 |
*/ |
|
54 | 164 |
int16_t (gunner_get_y_screen) (const gunner_t *p); |
165 |
/** |
|
166 |
* @brief Get gunner type. |
|
167 |
* @param p Pointer to gunner |
|
168 |
* @return Type of gunner |
|
169 |
*/ |
|
55 | 170 |
uint16_t (gunner_get_type) (const gunner_t *p); |
171 |
/** |
|
172 |
* @brief Get gunner team. |
|
173 |
* @param p Pointer to gunner |
|
174 |
* @return Team of gunner |
|
175 |
*/ |
|
56 | 176 |
int (gunner_get_team) (const gunner_t *p); |
177 |
/** |
|
178 |
* @brief Draw gunner on screen buffer. |
|
179 |
* @param p Pointer to gunner |
|
180 |
*/ |
|
57 | 181 |
void (gunner_draw)(gunner_t *p); |
182 |
/** |
|
183 |
* @brief Draw gunner health bar on screen buffer. |
|
184 |
* @param p Pointer to gunner |
|
185 |
*/ |
|
58 | 186 |
void (gunner_draw_health)(const gunner_t *p); |
187 |
/** |
|
188 |
* @brief Draw list of gunners on screen buffer. |
|
189 |
* @param shooter_list List of gunners |
|
190 |
*/ |
|
59 | 191 |
void (gunner_draw_list)(list_t *shooter_list); |
192 |
/** |
|
193 |
* @brief Get distance between two gunners. |
|
194 |
* @param p1 Gunner 1 |
|
195 |
* @param p2 Gunner 2 |
|
196 |
* @return Euclidian distance between the two gunners |
|
197 |
*/ |
|
60 | 198 |
double (gunner_distance)(const gunner_t *p1, const gunner_t *p2); |
61 |
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2); |
|
199 |
/** |
|
200 |
* @brief Check if two gunners are colliding. |
|
201 |
* @param p1 Gunner 1 |
|
202 |
* @param p2 Gunner 2 |
|
203 |
* @return true if the two gunners are colliding, false otherwise |
|
204 |
*/ |
|
205 |
int (gunner_collides_gunner)(const gunner_t *p1, const gunner_t *p2); |
|
62 | 206 |
|
63 | 207 |
/** |
64 | 208 |
* @} |
... | ... | |
72 | 216 |
* @{ |
73 | 217 |
*/ |
74 | 218 |
|
219 |
/** |
|
220 |
* @brief Bullet. |
|
221 |
*/ |
|
75 | 222 |
typedef struct bullet bullet_t; |
223 |
/** |
|
224 |
* @brief Construct bullet. |
|
225 |
* @param shooter Pointer to gunner that shot that bullet |
|
226 |
* @param b Basic sprite of the bullet |
|
227 |
* @param x X-position |
|
228 |
* @param y Y-position |
|
229 |
* @param vx X-speed |
|
230 |
* @param vy Y-speed |
|
231 |
* @return Pointer to constructed bullet, or NULL if failed |
|
232 |
*/ |
|
76 | 233 |
bullet_t* (bullet_ctor)(const gunner_t *shooter, const basic_sprite_t *b, double x, double y, double vx, double vy); |
234 |
/** |
|
235 |
* @brief Destruct bullet. |
|
236 |
* @param p Pointer to bullet to be destructed |
|
237 |
*/ |
|
77 | 238 |
void (bullet_dtor)(bullet_t *p); |
239 |
/** |
|
240 |
* @brief Get bullet X-position. |
|
241 |
* @param p Pointer to bullet |
|
242 |
* @return X-position of the bullet |
|
243 |
*/ |
|
78 | 244 |
double (bullet_get_x) (const bullet_t *p); |
245 |
/** |
|
246 |
* @brief Get bullet Y-position. |
|
247 |
* @param p Pointer to bullet |
|
248 |
* @return Y-position of the bullet |
|
249 |
*/ |
|
79 | 250 |
double (bullet_get_y) (const bullet_t *p); |
251 |
/** |
|
252 |
* @brief Get bullet X-speed. |
|
253 |
* @param p Pointer to bullet |
|
254 |
* @return X-speed of the bullet |
|
255 |
*/ |
|
80 | 256 |
double (bullet_get_vx) (const bullet_t *p); |
257 |
/** |
|
258 |
* @brief Get bullet Y-speed. |
|
259 |
* @param p Pointer to bullet |
|
260 |
* @return Y-speed of the bullet |
|
261 |
*/ |
|
81 | 262 |
double (bullet_get_vy) (const bullet_t *p); |
263 |
/** |
|
264 |
* @brief Get bullet X-position in screen coordinates. |
|
265 |
* @param p Pointer to bullet |
|
266 |
* @return X-position of the bullet in screen coordinates |
|
267 |
*/ |
|
82 | 268 |
int16_t (bullet_get_x_screen)(const bullet_t *p); |
269 |
/** |
|
270 |
* @brief Get bullet Y-position in screen coordinates. |
|
271 |
* @param p Pointer to bullet |
|
272 |
* @return Y-position of the bullet in screen coordinates |
|
273 |
*/ |
|
83 | 274 |
int16_t (bullet_get_y_screen)(const bullet_t *p); |
275 |
/** |
|
276 |
* @brief Get bullet damage. |
|
277 |
* @param p Pointer to bullet |
|
278 |
* @return Damage |
|
279 |
*/ |
|
84 | 280 |
double (bullet_get_damage) (const bullet_t *p); |
281 |
/** |
|
282 |
* @brief Set bullet damage. |
|
283 |
* @param p Pointer to bullet |
|
284 |
* @param damage Damage |
|
285 |
*/ |
|
85 | 286 |
void (bullet_set_damage) (bullet_t *p, double damage); |
287 |
/** |
|
288 |
* @brief Get gunner that shot the bullet. |
|
289 |
* @param p Pointer to bullet |
|
290 |
* @return Pointer to gunner that shot the bullet |
|
291 |
*/ |
|
86 | 292 |
const gunner_t* (bullet_get_shooter)(const bullet_t *p); |
293 |
/** |
|
294 |
* @brief Update bullet position (i.e., advance it according to its speed). |
|
295 |
* @param p Pointer to bullet |
|
296 |
*/ |
|
87 | 297 |
void (bullet_update_movement)(bullet_t *p); |
298 |
/** |
|
299 |
* @brief Update movement of bullets in a list. |
|
300 |
* @param bullet_list Pointer to bullet list |
|
301 |
*/ |
|
88 | 302 |
void (bullet_update_movement_list)(list_t *bullet_list); |
303 |
/** |
|
304 |
* @brief Draw bullet on screen buffer. |
|
305 |
* @param p Pointer to bullet |
|
306 |
*/ |
|
89 | 307 |
void (bullet_draw)(bullet_t *p); |
308 |
/** |
|
309 |
* @brief Draw bullets in list on screen buffer. |
|
310 |
* @param bullet_list Pointer to bullet list |
|
311 |
*/ |
|
90 | 312 |
void (bullet_draw_list)(list_t *bullet_list); |
91 | 313 |
|
92 | 314 |
/** |
... | ... | |
101 | 323 |
* @{ |
102 | 324 |
*/ |
103 | 325 |
|
326 |
/** |
|
327 |
* @brief Map. |
|
328 |
*/ |
|
104 | 329 |
typedef struct map map_t; |
330 |
/** |
|
331 |
* @brief Construct map. |
|
332 |
* @param backgroup XPM describing map as it should be rendered |
|
333 |
* @param collide XPM with transparency describing what parts of the map will cause collision |
|
334 |
* @return Pointer to constructed map, or NULL if failed |
|
335 |
*/ |
|
105 | 336 |
map_t* (map_ctor)(const char *const *background, const char *const *collide); |
337 |
/** |
|
338 |
* @brief Destruct map. |
|
339 |
* @param p Pointer to map to be destructed |
|
340 |
*/ |
|
106 | 341 |
void (map_dtor)(map_t *p); |
342 |
/** |
|
343 |
* @brief Get map width. |
|
344 |
* @param p Pointer to map |
|
345 |
* @return Width of map |
|
346 |
*/ |
|
107 | 347 |
uint16_t (map_get_width) (const map_t *p); |
348 |
/** |
|
349 |
* @brief Get map height. |
|
350 |
* @param p Pointer to map |
|
351 |
* @return Height of map |
|
352 |
*/ |
|
108 | 353 |
uint16_t (map_get_height) (const map_t *p); |
354 |
/** |
|
355 |
* @brief Use Dijkstra's path-finding algorithm. |
|
356 |
* |
|
357 |
* Allows a follower to know where to move so it gets closer to a given target. |
|
358 |
* |
|
359 |
* This function is implemented in a clever way that reduces the time of execution. |
|
360 |
* On the other hand, it might not always give the shortest path, but it is |
|
361 |
* guaranteeed to provide a decent, valid path to the target. |
|
362 |
* |
|
363 |
* @param p Pointer to map |
|
364 |
* @param x_ X-position of the target |
|
365 |
* @param y_ Y-position of the target |
|
366 |
* @return SUCCESS if operation is successful, false otherwise |
|
367 |
*/ |
|
109 | 368 |
int (map_make_dijkstra)(map_t *p, double x_, double y_); |
369 |
/** |
|
370 |
* @brief Get the direction a follower should move to get closer to the target. |
|
371 |
* @param p Pointer to map |
|
372 |
* @param x X-position of the follower |
|
373 |
* @param y Y-position of the follower |
|
374 |
* @param theta Pointer to angle that will be updated |
|
375 |
* @return SUCCESS if operation was successful, other value otherwise |
|
376 |
*/ |
|
110 | 377 |
int (map_where_to_follow)(const map_t *p, double x, double y, double *theta); |
378 |
/** |
|
379 |
* @brief Draw map on screen buffer. |
|
380 |
* @param p Pointer to map |
|
381 |
*/ |
|
111 | 382 |
void (map_draw)(map_t *p); |
383 |
/** |
|
384 |
* @brief Evaluate if point collides with map. |
|
385 |
* @param x X-position of the point |
|
386 |
* @param y Y-position of the point |
|
387 |
* @return true if the point collides with the map, false otherwise |
|
388 |
*/ |
|
112 | 389 |
int (map_collides_point)(const map_t *p, double x, double y); |
113 | 390 |
|
114 | 391 |
/** |
115 | 392 |
* @} |
116 | 393 |
*/ |
117 | 394 |
|
395 |
/** |
|
396 |
* @brief Evaluate if gunner is colliding with map. |
|
397 |
* @param p Pointer to map |
|
398 |
* @param gunner Pointer to gunner |
|
399 |
* @return true if the gunner collides with the map, false otherwise |
|
400 |
*/ |
|
118 | 401 |
int (map_collides_gunner)(const map_t *p, const gunner_t *gunner); |
402 |
/** |
|
403 |
* @brief Evaluate if bullet is colliding with map. |
|
404 |
* @param p Pointer to map |
|
405 |
* @param bullet Pointer to bullet |
|
406 |
* @return true if the bullet collides with the map, false otherwise |
|
407 |
*/ |
|
119 | 408 |
int (map_collides_bullet)(const map_t *p, const bullet_t *bullet); |
409 |
/** |
|
410 |
* @brief Evaluate if bullet is colliding with gunner. |
|
411 |
* @param shooter Pointer to gunner |
|
412 |
* @param bull Pointer to bullet |
|
413 |
* @return true if the bullet collides with the gunner, false otherwise |
|
414 |
*/ |
|
120 | 415 |
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull); |
121 | 416 |
|
417 |
void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l); |
|
418 |
|
|
122 | 419 |
#endif //ENT_H_INCLUDED |
Also available in: Unified diff