Project

General

Profile

Statistics
| Revision:

root / proj / project / include / ent.h @ 355

History | View | Annotate | Download (11.6 KB)

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