Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (11.6 KB)

1
#ifndef ENT_H_INCLUDED
2
#define ENT_H_INCLUDED
3

    
4
/**
5
 * @defgroup ent ent
6
 * @brief Entities module
7
 *
8
 * @{
9
 */
10

    
11
#include "libs.h"
12

    
13
/**
14
 * @brief Set scale.
15
 * @param   n   Scale
16
 */
17
void (ent_set_scale) (double n);
18
/**
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
void (ent_set_origin)(double x, double y);
24
/**
25
 * @brief Get scale.
26
 * @return  Scale
27
 */
28
double (ent_get_scale)  (void);
29
/**
30
 * @brief Get X-length of the screen in game referencial coordinates.
31
 * @return X-length
32
 */
33
double (ent_get_XLength)(void);
34
/**
35
 * @brief Get Y-length of the screen in game referencial coordinates.
36
 * @return Y-length
37
 */
38
double (ent_get_YLength)(void);
39

    
40
/**
41
 * @}
42
 */
43

    
44
/**
45
 * @defgroup gunner_t gunner_t
46
 * @ingroup ent
47
 * @brief Gunner module.
48
 *
49
 * @{
50
 */
51

    
52
/// @brief Identifier of a melee gunner
53
#define GUNNER_MELEE    BIT(0)
54
/// @brief Identifier of a ranged gunner
55
#define GUNNER_RANGED   BIT(1)
56
/// @brief Identifier of a player-controlled gunner
57
#define GUNNER_PLAYER   BIT(2)
58
/// @brief Identifier of an automatic follower gunner
59
#define GUNNER_FOLLOW   BIT(3)
60

    
61
/**
62
 * @brief Gunner.
63
 */
64
typedef struct gunner gunner_t;
65
/**
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
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon, uint16_t type, int team);
73
/**
74
 * @brief Destruct gunner.
75
 * @param   p   Pointer to gunner to be destructed
76
 */
77
void      (gunner_dtor)(gunner_t *p);
78
/**
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
void (gunner_set_pos)               (gunner_t *p, double x, double y);
85
/**
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
void (gunner_set_spawn)             (gunner_t *p, double x, double y);
92
/**
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
void (gunner_set_health)            (gunner_t *p, double health);
104
/**
105
 * @brief   Set gunner current health.
106
 * @param   p       Pointer to gunner
107
 * @param   health  Current health
108
 */
109
void (gunner_set_curr_health)       (gunner_t *p, double health);
110
/**
111
 * @brief   Get gunner X-position.
112
 * @param   p   Pointer to gunner
113
 * @return  X-position of the gunner
114
 */
115
double  (gunner_get_x)              (const gunner_t *p);
116
/**
117
 * @brief   Get gunner Y-position.
118
 * @param   p   Pointer to gunner
119
 * @return  Y-position of the gunner
120
 */
121
double  (gunner_get_y)              (const gunner_t *p);
122
/**
123
 * @brief   Get gunner spawn X-position.
124
 * @param   p   Pointer to gunner
125
 * @return  Spawn X-position of the gunner
126
 */
127
double  (gunner_get_spawn_x)        (const gunner_t *p);
128
/**
129
 * @brief   Get gunner spawn Y-position.
130
 * @param   p   Pointer to gunner
131
 * @return  Spawn Y-position of the gunner
132
 */
133
double  (gunner_get_spawn_y)        (const gunner_t *p);
134
/**
135
 * @brief   Get gunner angle.
136
 * @param   p   Pointer to gunner
137
 * @return  Angle of the gunner
138
 */
139
double  (gunner_get_angle)          (const gunner_t *p);
140
/**
141
 * @brief   Get gunner max health.
142
 * @param   p   Pointer to gunner
143
 * @return  Max health of the gunner
144
 */
145
double  (gunner_get_health)         (const gunner_t *p);
146
/**
147
 * @brief   Get gunner current health.
148
 * @param   p   Pointer to gunner
149
 * @return  Current health of the gunner
150
 */
151
double  (gunner_get_curr_health)    (const gunner_t *p);
152
/**
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
int16_t (gunner_get_x_screen)       (const gunner_t *p);
158
/**
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
int16_t (gunner_get_y_screen)       (const gunner_t *p);
164
/**
165
 * @brief   Get gunner type.
166
 * @param   p   Pointer to gunner
167
 * @return  Type of gunner
168
 */
169
uint16_t (gunner_get_type)          (const gunner_t *p);
170
/**
171
 * @brief   Get gunner team.
172
 * @param   p   Pointer to gunner
173
 * @return  Team of gunner
174
 */
175
int     (gunner_get_team)           (const gunner_t *p);
176
/**
177
 * @brief   Draw gunner on screen buffer.
178
 * @param   p   Pointer to gunner
179
 */
180
void (gunner_draw)(gunner_t *p);
181
/**
182
 * @brief   Draw gunner health bar on screen buffer.
183
 * @param   p   Pointer to gunner
184
 */
185
void (gunner_draw_health)(const gunner_t *p);
186
/**
187
 * @brief   Draw list of gunners on screen buffer.
188
 * @param   shooter_list    List of gunners
189
 */
190
void (gunner_draw_list)(list_t *shooter_list);
191
/**
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
double (gunner_distance)(const gunner_t *p1, const gunner_t *p2);
198
/**
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

    
206
/**
207
 * @}
208
 */
209

    
210
/**
211
 * @defgroup bullet_t bullet_t
212
 * @ingroup ent
213
 * @brief Bullet module.
214
 *
215
 * @{
216
 */
217

    
218
/**
219
 * @brief Bullet.
220
 */
221
typedef struct bullet bullet_t;
222
/**
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
bullet_t* (bullet_ctor)(const gunner_t *shooter, const basic_sprite_t *b, double x, double y, double vx, double vy);
233
/**
234
 * @brief Destruct bullet.
235
 * @param   p   Pointer to bullet to be destructed
236
 */
237
void      (bullet_dtor)(bullet_t *p);
238
/**
239
 * @brief   Get bullet X-position.
240
 * @param   p   Pointer to bullet
241
 * @return  X-position of the bullet
242
 */
243
double  (bullet_get_x)       (const bullet_t *p);
244
/**
245
 * @brief   Get bullet Y-position.
246
 * @param   p   Pointer to bullet
247
 * @return  Y-position of the bullet
248
 */
249
double  (bullet_get_y)       (const bullet_t *p);
250
/**
251
 * @brief   Get bullet X-speed.
252
 * @param   p   Pointer to bullet
253
 * @return  X-speed of the bullet
254
 */
255
double  (bullet_get_vx)      (const bullet_t *p);
256
/**
257
 * @brief   Get bullet Y-speed.
258
 * @param   p   Pointer to bullet
259
 * @return  Y-speed of the bullet
260
 */
261
double  (bullet_get_vy)      (const bullet_t *p);
262
/**
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
int16_t (bullet_get_x_screen)(const bullet_t *p);
268
/**
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
int16_t (bullet_get_y_screen)(const bullet_t *p);
274
/**
275
 * @brief   Get bullet damage.
276
 * @param   p   Pointer to bullet
277
 * @return  Damage
278
 */
279
double  (bullet_get_damage)  (const bullet_t *p);
280
/**
281
 * @brief   Set bullet damage.
282
 * @param   p   Pointer to bullet
283
 * @param   damage  Damage
284
 */
285
void    (bullet_set_damage)  (bullet_t *p, double damage);
286
/**
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
const gunner_t* (bullet_get_shooter)(const bullet_t *p);
292
/**
293
 * @brief Update bullet position (i.e., advance it according to its speed).
294
 * @param   p   Pointer to bullet
295
 */
296
void (bullet_update_movement)(bullet_t *p);
297
/**
298
 * @brief Update movement of bullets in a list.
299
 * @param   bullet_list     Pointer to bullet list
300
 */
301
void (bullet_update_movement_list)(list_t *bullet_list);
302
/**
303
 * @brief Draw bullet on screen buffer.
304
 * @param   p   Pointer to bullet
305
 */
306
void (bullet_draw)(bullet_t *p);
307
/**
308
 * @brief Draw bullets in list on screen buffer.
309
 * @param   bullet_list     Pointer to bullet list
310
 */
311
void (bullet_draw_list)(list_t *bullet_list);
312

    
313
/**
314
 * @}
315
 */
316

    
317
/**
318
 * @defgroup map_t map_t
319
 * @ingroup ent
320
 * @brief Bullet module.
321
 *
322
 * @{
323
 */
324

    
325
/**
326
 * @brief Map.
327
 */
328
typedef struct map map_t;
329
/**
330
 * @brief Construct map.
331
 * @param   background  XPM describing map as it should be rendered
332
 * @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
map_t* (map_ctor)(const char *const *background, const char *const *collide);
336
/**
337
 * @brief Destruct map.
338
 * @param   p   Pointer to map to be destructed
339
 */
340
void   (map_dtor)(map_t *p);
341
/**
342
 * @brief Get map width.
343
 * @param   p   Pointer to map
344
 * @return      Width of map
345
 */
346
uint16_t (map_get_width)   (const map_t *p);
347
/**
348
 * @brief Get map height.
349
 * @param   p   Pointer to map
350
 * @return      Height of map
351
 */
352
uint16_t (map_get_height)  (const map_t *p);
353
/**
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
int (map_make_dijkstra)(map_t *p, double x_, double y_);
368
/**
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
int (map_where_to_follow)(const map_t *p, double x, double y, double *theta);
377
/**
378
 * @brief Draw map on screen buffer.
379
 * @param   p   Pointer to map
380
 */
381
void   (map_draw)(map_t *p);
382
/**
383
 * @brief Evaluate if point collides with map.
384
 * @param   p   Pointer to 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
 */
389
int    (map_collides_point)(const map_t *p, double x, double y);
390

    
391
/**
392
 * @}
393
 */
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
 */
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
 */
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
 */
415
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull);
416

    
417
#endif //ENT_H_INCLUDED