Revision 340
more changes in ent.h, ent.c
proj/include/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 |
proj/include/interrupts_func.h | ||
---|---|---|
2 | 2 |
#define INTERRUPTS_FUNC_H_INCLUDED |
3 | 3 |
|
4 | 4 |
/** |
5 |
* @defgroup interrupts_func interrupts_func |
|
6 |
* @brief Interrupts functions. |
|
7 |
* |
|
8 |
* @{ |
|
9 |
*/ |
|
10 |
|
|
11 |
/** |
|
5 | 12 |
* @brief Subscribes all drivers used (timer->keyboard->mouse) |
6 | 13 |
* @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK |
7 | 14 |
* @see {_ERRORS_H_::errors} |
... | ... | |
23 | 30 |
|
24 | 31 |
int get_interrupts_vector(uint64_t *p); |
25 | 32 |
|
33 |
/** |
|
34 |
* @} |
|
35 |
*/ |
|
36 |
|
|
26 | 37 |
#endif /* end of include guard: INTERRUPTS_FUNC_H_INCLUDED */ |
proj/include/makecode_map.h | ||
---|---|---|
1 | 1 |
#ifndef MAKE_CODE_MAP_H_ |
2 | 2 |
#define MAKE_CODE_MAP_H_ |
3 | 3 |
|
4 |
/** |
|
5 |
* @defgroup makecode_map makecode_map |
|
6 |
* @brief Makecode map. |
|
7 |
* |
|
8 |
* @{ |
|
9 |
*/ |
|
10 |
|
|
11 |
#include <stdint.h> |
|
12 |
|
|
4 | 13 |
#define BASE_CODE 0x02 |
5 | 14 |
#define ERROR_CODE 0 |
6 | 15 |
|
7 |
#include <stdint.h> |
|
8 |
|
|
9 | 16 |
/** |
10 | 17 |
* @brief Maps make code into char |
11 | 18 |
* @param code Make code to map. |
... | ... | |
13 | 20 |
*/ |
14 | 21 |
char (map_makecode)(uint8_t code); |
15 | 22 |
|
23 |
/** |
|
24 |
* @} |
|
25 |
*/ |
|
26 |
|
|
16 | 27 |
#endif /* end of include guard: MAKE_CODE_MAP_H_ */ |
proj/include/proj_func.h | ||
---|---|---|
1 | 1 |
#ifndef PROJ_FUNC_H_INCLUDED |
2 | 2 |
#define PROJ_FUNC_H_INCLUDED |
3 | 3 |
|
4 |
/** |
|
5 |
* @defgroup proj_func proj_func |
|
6 |
* @brief Project helper functions. |
|
7 |
* |
|
8 |
* @{ |
|
9 |
*/ |
|
10 |
|
|
4 | 11 |
#include "ent.h" |
5 | 12 |
#include "text.h" |
6 | 13 |
#include "proj_structures.h" |
... | ... | |
29 | 36 |
|
30 | 37 |
void (update_game_state)(const map_t *map, list_t *shooter_list, list_t *bullet_list); |
31 | 38 |
|
32 |
void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l); |
|
33 | 39 |
|
40 |
|
|
34 | 41 |
void update_scale(void); |
35 | 42 |
|
36 | 43 |
int16_t* get_mouse_X(void); |
... | ... | |
43 | 50 |
|
44 | 51 |
double get_mouse_angle(gunner_t *p); |
45 | 52 |
|
53 |
/** |
|
54 |
* @} |
|
55 |
*/ |
|
56 |
|
|
57 |
/** |
|
58 |
* @defgroup text_timer_t text_timer_t |
|
59 |
* @ingroup proj_func |
|
60 |
* @brief Text timer. |
|
61 |
* |
|
62 |
* @{ |
|
63 |
*/ |
|
64 |
|
|
65 |
/** |
|
66 |
* @brief Text timer. |
|
67 |
*/ |
|
46 | 68 |
typedef struct { |
69 |
/// @brief Time since construction. |
|
47 | 70 |
int time; |
71 |
/// @brief Text. |
|
48 | 72 |
text_t *text; |
49 | 73 |
} text_timer_t; |
50 | 74 |
|
51 | 75 |
text_timer_t* (timer_ctor)(const font_t *fnt); |
52 | 76 |
|
77 |
void (timer_dtor)(text_timer_t *p); |
|
78 |
|
|
53 | 79 |
void (timer_update)(text_timer_t *p); |
54 | 80 |
|
55 | 81 |
void (timer_reset)(text_timer_t *p); |
56 | 82 |
|
57 |
void (timer_dtor)(text_timer_t *p); |
|
83 |
/** |
|
84 |
* @} |
|
85 |
*/ |
|
58 | 86 |
|
59 | 87 |
#endif /* end of include guard: PROJ_FUNC_H_INCLUDED */ |
proj/include/proj_macros.h | ||
---|---|---|
1 | 1 |
#ifndef PROJ_MACROS_H_INCLUDED |
2 | 2 |
#define PROJ_MACROS_H_INCLUDED |
3 | 3 |
|
4 |
/** |
|
5 |
* @defgroup proj_macros proj_macros |
|
6 |
* @brief Project macros. |
|
7 |
* |
|
8 |
* @{ |
|
9 |
*/ |
|
10 |
|
|
4 | 11 |
// Movement Directions |
5 |
#define UP -1 /** @brief Moving to the top side of screen */ |
|
6 |
#define DOWN 1 /** @brief Moving to the bottom side of screen */ |
|
7 |
#define LEFT -1 /** @brief Moving to the left side of screen */ |
|
8 |
#define RIGHT 1 /** @brief Moving to the right side of screen */ |
|
9 |
#define REST 0 /** @brief Not moving */ |
|
12 |
/** @brief Moving to the top side of screen */ |
|
13 |
#define UP -1 |
|
14 |
/** @brief Moving to the bottom side of screen */ |
|
15 |
#define DOWN 1 |
|
16 |
/** @brief Moving to the left side of screen */ |
|
17 |
#define LEFT -1 |
|
18 |
/** @brief Moving to the right side of screen */ |
|
19 |
#define RIGHT 1 |
|
20 |
/** @brief Not moving */ |
|
21 |
#define REST 0 |
|
10 | 22 |
|
11 | 23 |
// Movement Constants |
12 |
#define SHOOTER_SPEED 5 /** @brief Shooter speed */ |
|
13 |
#define BULLET_SPEED 8 /** @brief Bullet speet */ |
|
24 |
/** @brief Shooter speed */ |
|
25 |
#define SHOOTER_SPEED 5 |
|
26 |
/** @brief Bullet speet */ |
|
27 |
#define BULLET_SPEED 8 |
|
14 | 28 |
|
15 | 29 |
// Refresh Rate |
16 |
#define REFRESH_RATE 60 /** @brief Screen refresh rate */ |
|
30 |
/** @brief Screen refresh rate */ |
|
31 |
#define REFRESH_RATE 60 |
|
17 | 32 |
|
18 | 33 |
//Graphics mode |
19 |
#define GRAPH_MODE DIRECT_1024_768_888 /** @brief Graphic mode used */ |
|
20 |
#define MIN_SCALE 0.2 /** @brief Minimum zoom */ |
|
21 |
#define DEFAULT_SCALE 0.5 /** @brief Default zoom */ |
|
22 |
#define MAX_SCALE 10.0 /** @brief Maximum zoom */ |
|
34 |
/** @brief Graphic mode used */ |
|
35 |
#define GRAPH_MODE DIRECT_1024_768_888 |
|
36 |
/** @brief Minimum zoom */ |
|
37 |
#define MIN_SCALE 0.2 |
|
38 |
/** @brief Default zoom */ |
|
39 |
#define DEFAULT_SCALE 0.5 |
|
40 |
/** @brief Maximum zoom */ |
|
41 |
#define MAX_SCALE 10.0 |
|
23 | 42 |
|
24 | 43 |
// Colors |
44 |
/** @brief Text color */ |
|
25 | 45 |
#define TEXT_COLOR 0xFFFFFF |
46 |
/** @brief Highlight color */ |
|
26 | 47 |
#define HIGHLIGHT_COLOR 0x404040 |
48 |
/** @brief Delimiter color */ |
|
27 | 49 |
#define DELIMITER_COLOR 0x404040 |
28 | 50 |
|
51 |
/** @brief Melee attacks range */ |
|
29 | 52 |
#define MELEE_RANGE 80 |
53 |
/** @brief Melee attack damage (for zombies). */ |
|
30 | 54 |
#define MELEE_DAMAGE 1 |
31 |
|
|
55 |
/** @brief Zombie speed */ |
|
32 | 56 |
#define ZOMBIE_SPEED 1.0 |
33 | 57 |
|
58 |
/** |
|
59 |
* @} |
|
60 |
*/ |
|
61 |
|
|
34 | 62 |
#endif /* end of include guard: PROJ_MACROS_H_INCLUDED */ |
proj/include/proj_structures.h | ||
---|---|---|
1 | 1 |
#ifndef PROJ_STRUCTURES_H_INCLUDED |
2 | 2 |
#define PROJ_STRUCTURES_H_INCLUDED |
3 | 3 |
|
4 |
/** |
|
5 |
* @defgroup proj_structures proj_structures |
|
6 |
* @brief Project structures. |
|
7 |
* |
|
8 |
* @{ |
|
9 |
*/ |
|
10 |
|
|
4 | 11 |
#include <stdint.h> |
5 | 12 |
#include "ent.h" |
6 | 13 |
|
7 | 14 |
/** |
8 |
* @brief Key presses.
|
|
15 |
* @}
|
|
9 | 16 |
*/ |
17 |
|
|
18 |
/** |
|
19 |
* @defgroup keys_t keys_t |
|
20 |
* @ingroup proj_structures |
|
21 |
* @brief Keys pressed module. |
|
22 |
* |
|
23 |
* @{ |
|
24 |
*/ |
|
25 |
|
|
26 |
/** |
|
27 |
* @brief Keys pressed. |
|
28 |
*/ |
|
10 | 29 |
typedef struct { |
11 | 30 |
/// @brief W is pressed when 1 |
12 | 31 |
uint8_t w_pressed : 1; |
... | ... | |
27 | 46 |
} keys_t; |
28 | 47 |
|
29 | 48 |
/** |
49 |
* @} |
|
50 |
*/ |
|
51 |
|
|
52 |
/** |
|
53 |
* @defgroup host_info_t host_info_t |
|
54 |
* @ingroup proj_structures |
|
55 |
* @brief Host info module. |
|
56 |
* |
|
57 |
* @{ |
|
58 |
*/ |
|
59 |
|
|
60 |
/** |
|
30 | 61 |
* @brief Information to transmit from host to remote. |
31 | 62 |
*/ |
32 | 63 |
typedef struct { |
... | ... | |
82 | 113 |
void host_info_dtor(host_info_t *p); |
83 | 114 |
|
84 | 115 |
/** |
116 |
* @} |
|
117 |
*/ |
|
118 |
|
|
119 |
/** |
|
120 |
* @defgroup remote_info_t remote_info_t |
|
121 |
* @ingroup proj_structures |
|
122 |
* @brief Remote info module. |
|
123 |
* |
|
124 |
* @{ |
|
125 |
*/ |
|
126 |
|
|
127 |
/** |
|
85 | 128 |
* @brief Information to transmit from remote to host. |
86 | 129 |
*/ |
87 | 130 |
typedef struct { |
... | ... | |
102 | 145 |
void remote_info_dtor(remote_info_t *p); |
103 | 146 |
|
104 | 147 |
/** |
148 |
* @} |
|
149 |
*/ |
|
150 |
|
|
151 |
/** |
|
152 |
* @defgroup bullet_info_t bullet_info_t |
|
153 |
* @ingroup proj_structures |
|
154 |
* @brief Bullet event module. |
|
155 |
* |
|
156 |
* @{ |
|
157 |
*/ |
|
158 |
|
|
159 |
|
|
160 |
/** |
|
105 | 161 |
* @brief Bullet event to transmit from remote to host. |
106 | 162 |
*/ |
107 | 163 |
typedef struct { |
... | ... | |
119 | 175 |
*/ |
120 | 176 |
void bullet_info_dtor(bullet_info_t *p); |
121 | 177 |
|
178 |
/** |
|
179 |
* @} |
|
180 |
*/ |
|
181 |
|
|
122 | 182 |
#endif /* end of include guard: PROJ_STRUCTURES_H_INCLUDED */ |
proj/src/ent.c | ||
---|---|---|
124 | 124 |
rectangle_draw(p->red_bar); |
125 | 125 |
text_draw(p->txt); |
126 | 126 |
} |
127 |
void (gunner_draw_list)(list_t *shooter_list) { |
|
128 |
if (list_size(shooter_list) == 0) return; |
|
127 | 129 |
|
130 |
list_node_t *it = list_begin(shooter_list); |
|
131 |
while (it != list_end(shooter_list)) { |
|
132 |
gunner_draw(*(gunner_t**)list_node_val(it)); |
|
133 |
it = list_node_next(it); |
|
134 |
} |
|
135 |
} |
|
128 | 136 |
double (gunner_distance)(const gunner_t *p1, const gunner_t *p2){ |
129 | 137 |
double dx = gunner_get_x(p1) - gunner_get_x(p2); |
130 | 138 |
double dy = gunner_get_y(p1) - gunner_get_y(p2); |
131 | 139 |
return sqrt(dx*dx+dy*dy); |
132 | 140 |
} |
141 |
int (gunner_collides_gunner)(const gunner_t *p1, const gunner_t *p2) { |
|
142 |
if (p1 == p2) return false; |
|
143 |
double p1_radius = max_d(sprite_get_w(p1->dude), sprite_get_h(p1->dude))/2.0; |
|
144 |
double p2_radius = max_d(sprite_get_w(p2->dude), sprite_get_h(p2->dude))/2.0; |
|
145 |
double distance = gunner_distance(p1, p2); |
|
146 |
return distance <= p1_radius+p2_radius; |
|
147 |
} |
|
133 | 148 |
|
134 | 149 |
struct bullet{ |
135 | 150 |
const gunner_t *shooter; |
... | ... | |
156 | 171 |
sprite_set_angle(ret->b, angle-M_PI_2); |
157 | 172 |
return ret; |
158 | 173 |
} |
159 |
|
|
160 | 174 |
void (bullet_dtor)(bullet_t *p){ |
161 | 175 |
if(p == NULL) return; |
162 | 176 |
sprite_dtor(p->b); |
... | ... | |
178 | 192 |
p->x += p->vx; |
179 | 193 |
p->y += p->vy; |
180 | 194 |
} |
181 |
|
|
182 | 195 |
void (bullet_update_movement_list)(list_t *bullet_list){ |
183 | 196 |
if (list_size(bullet_list) == 0) return; |
184 | 197 |
|
... | ... | |
188 | 201 |
it = list_node_next(it); |
189 | 202 |
} |
190 | 203 |
} |
191 |
|
|
192 | 204 |
void (bullet_draw)(bullet_t *p){ |
193 | 205 |
const int16_t x_screen = bullet_get_x_screen(p); |
194 | 206 |
const int16_t y_screen = bullet_get_y_screen(p); |
... | ... | |
196 | 208 |
sprite_set_scale(p->b, scale); |
197 | 209 |
sprite_draw (p->b); |
198 | 210 |
} |
199 |
|
|
200 |
void (gunner_draw_list)(list_t *shooter_list) { |
|
201 |
if (list_size(shooter_list) == 0) return; |
|
202 |
|
|
203 |
list_node_t *it = list_begin(shooter_list); |
|
204 |
while (it != list_end(shooter_list)) { |
|
205 |
gunner_draw(*(gunner_t**)list_node_val(it)); |
|
206 |
it = list_node_next(it); |
|
207 |
} |
|
208 |
} |
|
209 |
|
|
210 | 211 |
void (bullet_draw_list)(list_t *bullet_list) { |
211 | 212 |
if (list_size(bullet_list) == 0) return; |
212 | 213 |
|
... | ... | |
233 | 234 |
} |
234 | 235 |
return 0; |
235 | 236 |
} |
237 |
static int16_t (map_get_x_screen)(const map_t *p){ (void)p; return (int16_t)((-x_origin)*scale); } |
|
238 |
static int16_t (map_get_y_screen)(const map_t *p){ (void)p; return (int16_t)((-y_origin)*scale); } |
|
236 | 239 |
map_t* (map_ctor)(const char *const *background, const char *const *collide){ |
237 | 240 |
map_t *ret = malloc(sizeof(map_t)); |
238 | 241 |
if(ret == NULL) return NULL; |
... | ... | |
285 | 288 |
free(p->visited); |
286 | 289 |
free(p); |
287 | 290 |
} |
288 |
static int16_t (map_get_x_screen)(const map_t *p){ (void)p; return (int16_t)((-x_origin)*scale); } |
|
289 |
static int16_t (map_get_y_screen)(const map_t *p){ (void)p; return (int16_t)((-y_origin)*scale); } |
|
290 | 291 |
uint16_t (map_get_width) (const map_t *p){ return sprite_get_w(p->background); } |
291 | 292 |
uint16_t (map_get_height) (const map_t *p){ return sprite_get_h(p->background); } |
292 |
int (map_collides_point)(const map_t *p, double x, double y){ |
|
293 |
const uint16_t w = sprite_get_w(p->background), h = sprite_get_h(p->background); |
|
294 |
int16_t x_ = (int16_t)x, y_ = (int16_t)y; |
|
295 |
if(x_ < 0 || w <= x_ || y_ < 0 || h <= y_) return 0; |
|
296 |
int32_t pos = x_ + y_*w; |
|
297 |
if(0 <= pos && pos < w*h) return p->collide[pos]; |
|
298 |
else return false; |
|
299 |
} |
|
300 |
int (map_collides_gunner)(const map_t *p, const gunner_t *shooter) { |
|
301 |
double radius = max_d(sprite_get_w(shooter->dude), sprite_get_h(shooter->dude))/2.0; |
|
302 |
return map_collides_gunner_pos(p, gunner_get_x(shooter), gunner_get_y(shooter), radius); |
|
303 |
} |
|
304 | 293 |
int (map_make_dijkstra)(map_t *p, double x_, double y_){ |
305 | 294 |
int16_t x = (int16_t)x_, y = (int16_t)y_; |
306 | 295 |
|
... | ... | |
345 | 334 |
*theta = atan2(-(newy-y_), newx-x_); |
346 | 335 |
return SUCCESS; |
347 | 336 |
} |
337 |
void (map_draw)(map_t *p){ |
|
338 |
const int16_t x_screen = map_get_x_screen(p); |
|
339 |
const int16_t y_screen = map_get_y_screen(p); |
|
340 |
sprite_set_pos (p->background, x_screen, y_screen); |
|
341 |
sprite_set_scale(p->background, scale); |
|
342 |
sprite_draw (p->background); |
|
343 |
} |
|
344 |
int (map_collides_point)(const map_t *p, double x, double y){ |
|
345 |
const uint16_t w = sprite_get_w(p->background), h = sprite_get_h(p->background); |
|
346 |
int16_t x_ = (int16_t)x, y_ = (int16_t)y; |
|
347 |
if(x_ < 0 || w <= x_ || y_ < 0 || h <= y_) return 0; |
|
348 |
int32_t pos = x_ + y_*w; |
|
349 |
if(0 <= pos && pos < w*h) return p->collide[pos]; |
|
350 |
else return false; |
|
351 |
} |
|
348 | 352 |
|
353 |
int (map_collides_gunner)(const map_t *p, const gunner_t *shooter) { |
|
354 |
double radius = max_d(sprite_get_w(shooter->dude), sprite_get_h(shooter->dude))/2.0; |
|
355 |
return map_collides_gunner_pos(p, gunner_get_x(shooter), gunner_get_y(shooter), radius); |
|
356 |
} |
|
349 | 357 |
int (map_collides_bullet)(const map_t *p, const bullet_t *bull){ |
350 | 358 |
double radius = max_d(sprite_get_w(bull->b), sprite_get_h(bull->b))/2.0; |
351 | 359 |
double bullet_x = bullet_get_x(bull); |
... | ... | |
357 | 365 |
} |
358 | 366 |
return 0; |
359 | 367 |
} |
360 |
|
|
361 | 368 |
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull){ |
362 | 369 |
if(bull->shooter == shooter) return false; |
363 | 370 |
|
... | ... | |
374 | 381 |
double distance = sqrt(dx*dx + dy*dy); |
375 | 382 |
return distance <= shooter_radius+bullet_radius; |
376 | 383 |
} |
384 |
void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l) { |
|
385 |
uint16_t w = map_get_width(map), h = map_get_height(map); |
|
386 |
double x, y; |
|
377 | 387 |
|
378 |
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2) { |
|
379 |
if (shooter1 == shooter2) return false; |
|
380 |
double shooter1_radius = max_d(sprite_get_w(shooter1->dude), sprite_get_h(shooter1->dude))/2.0; |
|
381 |
double shooter2_radius = max_d(sprite_get_w(shooter2->dude), sprite_get_h(shooter2->dude))/2.0; |
|
382 |
double distance = gunner_distance(shooter1, shooter2); |
|
383 |
return distance <= shooter1_radius+shooter2_radius; |
|
388 |
while(true){ |
|
389 |
x = rand() % w; |
|
390 |
y = rand() % h; |
|
391 |
gunner_set_pos(p, x, y); |
|
392 |
if(map_collides_gunner(map, p)) continue; |
|
393 |
int collides = false; |
|
394 |
list_node_t *it = list_begin(l); |
|
395 |
while(it != list_end(l)){ |
|
396 |
if(gunner_collides_gunner(p, *list_node_val(it))){ |
|
397 |
collides = true; |
|
398 |
break; |
|
399 |
} |
|
400 |
it = list_node_next(it); |
|
401 |
} |
|
402 |
if(!collides) return; |
|
403 |
} |
|
384 | 404 |
} |
385 |
|
|
386 |
void (map_draw)(map_t *p){ |
|
387 |
const int16_t x_screen = map_get_x_screen(p); |
|
388 |
const int16_t y_screen = map_get_y_screen(p); |
|
389 |
sprite_set_pos (p->background, x_screen, y_screen); |
|
390 |
sprite_set_scale(p->background, scale); |
|
391 |
sprite_draw (p->background); |
|
392 |
} |
proj/src/proj_func.c | ||
---|---|---|
251 | 251 |
} |
252 | 252 |
} |
253 | 253 |
|
254 |
void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l) { |
|
255 |
uint16_t w = map_get_width(map), h = map_get_height(map); |
|
256 |
double x, y; |
|
257 |
|
|
258 |
while(true){ |
|
259 |
x = rand() % w; |
|
260 |
y = rand() % h; |
|
261 |
gunner_set_pos(p, x, y); |
|
262 |
if(map_collides_gunner(map, p)) continue; |
|
263 |
int collides = false; |
|
264 |
list_node_t *it = list_begin(l); |
|
265 |
while(it != list_end(l)){ |
|
266 |
if(gunner_collides_gunner(p, *list_node_val(it))){ |
|
267 |
collides = true; |
|
268 |
break; |
|
269 |
} |
|
270 |
it = list_node_next(it); |
|
271 |
} |
|
272 |
if(!collides) return; |
|
273 |
} |
|
274 |
} |
|
275 |
|
|
276 | 254 |
void update_scale(void) { |
277 | 255 |
static uint8_t last_plus = 0, last_minus = 0; |
278 | 256 |
if (key_presses.ctrl_pressed) { |
Also available in: Unified diff