root / proj / project / include / ent.h @ 360
History | View | Annotate | Download (11.7 KB)
1 | 193 | up20180642 | #ifndef ENT_H_INCLUDED
|
---|---|---|---|
2 | #define ENT_H_INCLUDED
|
||
3 | |||
4 | 339 | up20180642 | /**
|
5 | * @defgroup ent ent
|
||
6 | 357 | up20180642 | * @ingroup proj
|
7 | 339 | up20180642 | * @brief Entities module
|
8 | *
|
||
9 | * @{
|
||
10 | */
|
||
11 | |||
12 | 351 | up20180642 | #include "libs.h" |
13 | 193 | up20180642 | |
14 | 340 | up20180642 | /**
|
15 | * @brief Set scale.
|
||
16 | * @param n Scale
|
||
17 | */
|
||
18 | 193 | up20180642 | void (ent_set_scale) (double n); |
19 | 340 | up20180642 | /**
|
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 | 193 | up20180642 | void (ent_set_origin)(double x, double y); |
25 | 340 | up20180642 | /**
|
26 | * @brief Get scale.
|
||
27 | * @return Scale
|
||
28 | */
|
||
29 | 194 | up20180642 | double (ent_get_scale) (void); |
30 | 340 | up20180642 | /**
|
31 | * @brief Get X-length of the screen in game referencial coordinates.
|
||
32 | * @return X-length
|
||
33 | */
|
||
34 | 193 | up20180642 | double (ent_get_XLength)(void); |
35 | 340 | up20180642 | /**
|
36 | * @brief Get Y-length of the screen in game referencial coordinates.
|
||
37 | * @return Y-length
|
||
38 | */
|
||
39 | 193 | up20180642 | double (ent_get_YLength)(void); |
40 | |||
41 | 339 | up20180642 | /**
|
42 | * @}
|
||
43 | */
|
||
44 | |||
45 | /**
|
||
46 | * @defgroup gunner_t gunner_t
|
||
47 | * @ingroup ent
|
||
48 | * @brief Gunner module.
|
||
49 | *
|
||
50 | * @{
|
||
51 | */
|
||
52 | |||
53 | 340 | up20180642 | /// @brief Identifier of a melee gunner
|
54 | 321 | up20180642 | #define GUNNER_MELEE BIT(0) |
55 | 340 | up20180642 | /// @brief Identifier of a ranged gunner
|
56 | 321 | up20180642 | #define GUNNER_RANGED BIT(1) |
57 | 340 | up20180642 | /// @brief Identifier of a player-controlled gunner
|
58 | 321 | up20180642 | #define GUNNER_PLAYER BIT(2) |
59 | 340 | up20180642 | /// @brief Identifier of an automatic follower gunner
|
60 | 321 | up20180642 | #define GUNNER_FOLLOW BIT(3) |
61 | 301 | up20180642 | |
62 | 340 | up20180642 | /**
|
63 | * @brief Gunner.
|
||
64 | */
|
||
65 | 201 | up20180642 | typedef struct gunner gunner_t; |
66 | 340 | up20180642 | /**
|
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 | 321 | up20180642 | gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon, uint16_t type, int team);
|
74 | 340 | up20180642 | /**
|
75 | * @brief Destruct gunner.
|
||
76 | * @param p Pointer to gunner to be destructed
|
||
77 | */
|
||
78 | 201 | up20180642 | void (gunner_dtor)(gunner_t *p);
|
79 | 340 | up20180642 | /**
|
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 | 229 | up20180655 | void (gunner_set_pos) (gunner_t *p, double x, double y); |
86 | 340 | up20180642 | /**
|
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 | 236 | up20180642 | void (gunner_set_spawn) (gunner_t *p, double x, double y); |
93 | 340 | up20180642 | /**
|
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 | 267 | up20180655 | void (gunner_set_health) (gunner_t *p, double health); |
105 | 340 | up20180642 | /**
|
106 | * @brief Set gunner current health.
|
||
107 | * @param p Pointer to gunner
|
||
108 | * @param health Current health
|
||
109 | */
|
||
110 | 267 | up20180655 | void (gunner_set_curr_health) (gunner_t *p, double health); |
111 | 340 | up20180642 | /**
|
112 | * @brief Get gunner X-position.
|
||
113 | * @param p Pointer to gunner
|
||
114 | * @return X-position of the gunner
|
||
115 | */
|
||
116 | 229 | up20180655 | double (gunner_get_x) (const gunner_t *p); |
117 | 340 | up20180642 | /**
|
118 | * @brief Get gunner Y-position.
|
||
119 | * @param p Pointer to gunner
|
||
120 | * @return Y-position of the gunner
|
||
121 | */
|
||
122 | 229 | up20180655 | double (gunner_get_y) (const gunner_t *p); |
123 | 340 | up20180642 | /**
|
124 | * @brief Get gunner spawn X-position.
|
||
125 | * @param p Pointer to gunner
|
||
126 | * @return Spawn X-position of the gunner
|
||
127 | */
|
||
128 | 232 | up20180655 | double (gunner_get_spawn_x) (const gunner_t *p); |
129 | 340 | up20180642 | /**
|
130 | * @brief Get gunner spawn Y-position.
|
||
131 | * @param p Pointer to gunner
|
||
132 | * @return Spawn Y-position of the gunner
|
||
133 | */
|
||
134 | 232 | up20180655 | double (gunner_get_spawn_y) (const gunner_t *p); |
135 | 340 | up20180642 | /**
|
136 | * @brief Get gunner angle.
|
||
137 | * @param p Pointer to gunner
|
||
138 | * @return Angle of the gunner
|
||
139 | */
|
||
140 | 231 | up20180655 | double (gunner_get_angle) (const gunner_t *p); |
141 | 340 | up20180642 | /**
|
142 | * @brief Get gunner max health.
|
||
143 | * @param p Pointer to gunner
|
||
144 | * @return Max health of the gunner
|
||
145 | */
|
||
146 | 267 | up20180655 | double (gunner_get_health) (const gunner_t *p); |
147 | 340 | up20180642 | /**
|
148 | * @brief Get gunner current health.
|
||
149 | * @param p Pointer to gunner
|
||
150 | * @return Current health of the gunner
|
||
151 | */
|
||
152 | 267 | up20180655 | double (gunner_get_curr_health) (const gunner_t *p); |
153 | 340 | up20180642 | /**
|
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 | 229 | up20180655 | int16_t (gunner_get_x_screen) (const gunner_t *p);
|
159 | 340 | up20180642 | /**
|
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 | 229 | up20180655 | int16_t (gunner_get_y_screen) (const gunner_t *p);
|
165 | 340 | up20180642 | /**
|
166 | * @brief Get gunner type.
|
||
167 | * @param p Pointer to gunner
|
||
168 | * @return Type of gunner
|
||
169 | */
|
||
170 | 321 | up20180642 | uint16_t (gunner_get_type) (const gunner_t *p);
|
171 | 340 | up20180642 | /**
|
172 | * @brief Get gunner team.
|
||
173 | * @param p Pointer to gunner
|
||
174 | * @return Team of gunner
|
||
175 | */
|
||
176 | 302 | up20180642 | int (gunner_get_team) (const gunner_t *p); |
177 | 340 | up20180642 | /**
|
178 | * @brief Draw gunner on screen buffer.
|
||
179 | * @param p Pointer to gunner
|
||
180 | */
|
||
181 | 201 | up20180642 | void (gunner_draw)(gunner_t *p);
|
182 | 340 | up20180642 | /**
|
183 | * @brief Draw gunner health bar on screen buffer.
|
||
184 | * @param p Pointer to gunner
|
||
185 | */
|
||
186 | 229 | up20180655 | void (gunner_draw_health)(const gunner_t *p); |
187 | 340 | up20180642 | /**
|
188 | * @brief Draw list of gunners on screen buffer.
|
||
189 | * @param shooter_list List of gunners
|
||
190 | */
|
||
191 | 339 | up20180642 | void (gunner_draw_list)(list_t *shooter_list);
|
192 | 340 | up20180642 | /**
|
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 | 302 | up20180642 | double (gunner_distance)(const gunner_t *p1, const gunner_t *p2); |
199 | 340 | up20180642 | /**
|
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 | 302 | up20180642 | |
207 | 339 | up20180642 | /**
|
208 | * @}
|
||
209 | */
|
||
210 | |||
211 | /**
|
||
212 | * @defgroup bullet_t bullet_t
|
||
213 | * @ingroup ent
|
||
214 | * @brief Bullet module.
|
||
215 | *
|
||
216 | * @{
|
||
217 | */
|
||
218 | |||
219 | 340 | up20180642 | /**
|
220 | * @brief Bullet.
|
||
221 | */
|
||
222 | 201 | up20180642 | typedef struct bullet bullet_t; |
223 | 340 | up20180642 | /**
|
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 | 237 | up20180642 | bullet_t* (bullet_ctor)(const gunner_t *shooter, const basic_sprite_t *b, double x, double y, double vx, double vy); |
234 | 340 | up20180642 | /**
|
235 | * @brief Destruct bullet.
|
||
236 | * @param p Pointer to bullet to be destructed
|
||
237 | */
|
||
238 | 203 | up20180642 | void (bullet_dtor)(bullet_t *p);
|
239 | 340 | up20180642 | /**
|
240 | * @brief Get bullet X-position.
|
||
241 | * @param p Pointer to bullet
|
||
242 | * @return X-position of the bullet
|
||
243 | */
|
||
244 | 203 | up20180642 | double (bullet_get_x) (const bullet_t *p); |
245 | 340 | up20180642 | /**
|
246 | * @brief Get bullet Y-position.
|
||
247 | * @param p Pointer to bullet
|
||
248 | * @return Y-position of the bullet
|
||
249 | */
|
||
250 | 203 | up20180642 | double (bullet_get_y) (const bullet_t *p); |
251 | 340 | up20180642 | /**
|
252 | * @brief Get bullet X-speed.
|
||
253 | * @param p Pointer to bullet
|
||
254 | * @return X-speed of the bullet
|
||
255 | */
|
||
256 | 320 | up20180655 | double (bullet_get_vx) (const bullet_t *p); |
257 | 340 | up20180642 | /**
|
258 | * @brief Get bullet Y-speed.
|
||
259 | * @param p Pointer to bullet
|
||
260 | * @return Y-speed of the bullet
|
||
261 | */
|
||
262 | 320 | up20180655 | double (bullet_get_vy) (const bullet_t *p); |
263 | 340 | up20180642 | /**
|
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 | 203 | up20180642 | int16_t (bullet_get_x_screen)(const bullet_t *p);
|
269 | 340 | up20180642 | /**
|
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 | 203 | up20180642 | int16_t (bullet_get_y_screen)(const bullet_t *p);
|
275 | 340 | up20180642 | /**
|
276 | * @brief Get bullet damage.
|
||
277 | * @param p Pointer to bullet
|
||
278 | * @return Damage
|
||
279 | */
|
||
280 | 267 | up20180655 | double (bullet_get_damage) (const bullet_t *p); |
281 | 340 | up20180642 | /**
|
282 | * @brief Set bullet damage.
|
||
283 | * @param p Pointer to bullet
|
||
284 | * @param damage Damage
|
||
285 | */
|
||
286 | 267 | up20180655 | void (bullet_set_damage) (bullet_t *p, double damage); |
287 | 340 | up20180642 | /**
|
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 | 302 | up20180642 | const gunner_t* (bullet_get_shooter)(const bullet_t *p); |
293 | 340 | up20180642 | /**
|
294 | * @brief Update bullet position (i.e., advance it according to its speed).
|
||
295 | * @param p Pointer to bullet
|
||
296 | */
|
||
297 | 226 | up20180642 | void (bullet_update_movement)(bullet_t *p);
|
298 | 340 | up20180642 | /**
|
299 | * @brief Update movement of bullets in a list.
|
||
300 | * @param bullet_list Pointer to bullet list
|
||
301 | */
|
||
302 | 231 | up20180655 | void (bullet_update_movement_list)(list_t *bullet_list);
|
303 | 340 | up20180642 | /**
|
304 | * @brief Draw bullet on screen buffer.
|
||
305 | * @param p Pointer to bullet
|
||
306 | */
|
||
307 | 203 | up20180642 | void (bullet_draw)(bullet_t *p);
|
308 | 340 | up20180642 | /**
|
309 | * @brief Draw bullets in list on screen buffer.
|
||
310 | * @param bullet_list Pointer to bullet list
|
||
311 | */
|
||
312 | 231 | up20180655 | void (bullet_draw_list)(list_t *bullet_list);
|
313 | 193 | up20180642 | |
314 | 339 | up20180642 | /**
|
315 | * @}
|
||
316 | */
|
||
317 | |||
318 | /**
|
||
319 | * @defgroup map_t map_t
|
||
320 | * @ingroup ent
|
||
321 | * @brief Bullet module.
|
||
322 | *
|
||
323 | * @{
|
||
324 | */
|
||
325 | |||
326 | 340 | up20180642 | /**
|
327 | * @brief Map.
|
||
328 | */
|
||
329 | 216 | up20180642 | typedef struct map map_t; |
330 | 340 | up20180642 | /**
|
331 | * @brief Construct map.
|
||
332 | 345 | up20180642 | * @param background XPM describing map as it should be rendered
|
333 | 340 | up20180642 | * @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 | 321 | up20180642 | map_t* (map_ctor)(const char *const *background, const char *const *collide); |
337 | 340 | up20180642 | /**
|
338 | * @brief Destruct map.
|
||
339 | * @param p Pointer to map to be destructed
|
||
340 | */
|
||
341 | 216 | up20180642 | void (map_dtor)(map_t *p);
|
342 | 340 | up20180642 | /**
|
343 | * @brief Get map width.
|
||
344 | * @param p Pointer to map
|
||
345 | * @return Width of map
|
||
346 | */
|
||
347 | 323 | up20180642 | uint16_t (map_get_width) (const map_t *p);
|
348 | 340 | up20180642 | /**
|
349 | * @brief Get map height.
|
||
350 | * @param p Pointer to map
|
||
351 | * @return Height of map
|
||
352 | */
|
||
353 | 323 | up20180642 | uint16_t (map_get_height) (const map_t *p);
|
354 | 340 | up20180642 | /**
|
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 | 321 | up20180642 | int (map_make_dijkstra)(map_t *p, double x_, double y_); |
369 | 340 | up20180642 | /**
|
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 | 321 | up20180642 | int (map_where_to_follow)(const map_t *p, double x, double y, double *theta); |
378 | 340 | up20180642 | /**
|
379 | * @brief Draw map on screen buffer.
|
||
380 | * @param p Pointer to map
|
||
381 | */
|
||
382 | 216 | up20180642 | void (map_draw)(map_t *p);
|
383 | 340 | up20180642 | /**
|
384 | * @brief Evaluate if point collides with map.
|
||
385 | 345 | up20180642 | * @param p Pointer to map
|
386 | 340 | up20180642 | * @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 | 339 | up20180642 | int (map_collides_point)(const map_t *p, double x, double y); |
391 | 216 | up20180642 | |
392 | 339 | up20180642 | /**
|
393 | * @}
|
||
394 | */
|
||
395 | |||
396 | 340 | up20180642 | /**
|
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 | 339 | up20180642 | int (map_collides_gunner)(const map_t *p, const gunner_t *gunner); |
403 | 340 | up20180642 | /**
|
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 | 339 | up20180642 | int (map_collides_bullet)(const map_t *p, const bullet_t *bullet); |
410 | 340 | up20180642 | /**
|
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 | 339 | up20180642 | int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull); |
417 | |||
418 | 193 | up20180642 | #endif //ENT_H_INCLUDED |