Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (11.7 KB)

1
#ifndef ENT_H_INCLUDED
2
#define ENT_H_INCLUDED
3

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

    
12
#include "libs.h"
13

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

    
41
/**
42
 * @}
43
 */
44

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

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

    
62
/**
63
 * @brief Gunner.
64
 */
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
 */
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
 */
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
 */
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
 */
92
void (gunner_set_spawn)             (gunner_t *p, double x, double y);
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
176
int     (gunner_get_team)           (const gunner_t *p);
177
/**
178
 * @brief   Draw gunner on screen buffer.
179
 * @param   p   Pointer to gunner
180
 */
181
void (gunner_draw)(gunner_t *p);
182
/**
183
 * @brief   Draw gunner health bar on screen buffer.
184
 * @param   p   Pointer to gunner
185
 */
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
 */
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
 */
198
double (gunner_distance)(const gunner_t *p1, const gunner_t *p2);
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);
206

    
207
/**
208
 * @}
209
 */
210

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

    
219
/**
220
 * @brief Bullet.
221
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
312
void (bullet_draw_list)(list_t *bullet_list);
313

    
314
/**
315
 * @}
316
 */
317

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

    
326
/**
327
 * @brief Map.
328
 */
329
typedef struct map map_t;
330
/**
331
 * @brief Construct map.
332
 * @param   background  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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
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
 */
382
void   (map_draw)(map_t *p);
383
/**
384
 * @brief Evaluate if point collides with map.
385
 * @param   p   Pointer to map
386
 * @param   x   X-position of the point
387
 * @param   y   Y-position of the point
388
 * @return true if the point collides with the map, false otherwise
389
 */
390
int    (map_collides_point)(const map_t *p, double x, double y);
391

    
392
/**
393
 * @}
394
 */
395

    
396
/**
397
 * @brief Evaluate if gunner is colliding with map.
398
 * @param   p       Pointer to map
399
 * @param   gunner  Pointer to gunner
400
 * @return true if the gunner collides with the map, false otherwise
401
 */
402
int    (map_collides_gunner)(const map_t *p, const gunner_t *gunner);
403
/**
404
 * @brief Evaluate if bullet is colliding with map.
405
 * @param   p       Pointer to map
406
 * @param   bullet  Pointer to bullet
407
 * @return true if the bullet collides with the map, false otherwise
408
 */
409
int    (map_collides_bullet)(const map_t *p, const bullet_t *bullet);
410
/**
411
 * @brief Evaluate if bullet is colliding with gunner.
412
 * @param   shooter     Pointer to gunner
413
 * @param   bull        Pointer to bullet
414
 * @return true if the bullet collides with the gunner, false otherwise
415
 */
416
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull);
417

    
418
#endif //ENT_H_INCLUDED