Revision 339
more changes
proj/include/ent.h | ||
---|---|---|
1 | 1 |
#ifndef ENT_H_INCLUDED |
2 | 2 |
#define ENT_H_INCLUDED |
3 | 3 |
|
4 |
/** |
|
5 |
* @defgroup ent ent |
|
6 |
* @brief Entities module |
|
7 |
* |
|
8 |
* @{ |
|
9 |
*/ |
|
10 |
|
|
4 | 11 |
#include "basic_sprite.h" |
5 | 12 |
#include "list.h" |
6 | 13 |
|
... | ... | |
11 | 18 |
double (ent_get_XLength)(void); |
12 | 19 |
double (ent_get_YLength)(void); |
13 | 20 |
|
21 |
/** |
|
22 |
* @} |
|
23 |
*/ |
|
24 |
|
|
25 |
/** |
|
26 |
* @defgroup gunner_t gunner_t |
|
27 |
* @ingroup ent |
|
28 |
* @brief Gunner module. |
|
29 |
* |
|
30 |
* @{ |
|
31 |
*/ |
|
32 |
|
|
14 | 33 |
#define GUNNER_MELEE BIT(0) |
15 | 34 |
#define GUNNER_RANGED BIT(1) |
16 | 35 |
#define GUNNER_PLAYER BIT(2) |
... | ... | |
37 | 56 |
int (gunner_get_team) (const gunner_t *p); |
38 | 57 |
void (gunner_draw)(gunner_t *p); |
39 | 58 |
void (gunner_draw_health)(const gunner_t *p); |
40 |
|
|
59 |
void (gunner_draw_list)(list_t *shooter_list); |
|
41 | 60 |
double (gunner_distance)(const gunner_t *p1, const gunner_t *p2); |
61 |
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2); |
|
42 | 62 |
|
63 |
/** |
|
64 |
* @} |
|
65 |
*/ |
|
66 |
|
|
67 |
/** |
|
68 |
* @defgroup bullet_t bullet_t |
|
69 |
* @ingroup ent |
|
70 |
* @brief Bullet module. |
|
71 |
* |
|
72 |
* @{ |
|
73 |
*/ |
|
74 |
|
|
43 | 75 |
typedef struct bullet bullet_t; |
44 | 76 |
bullet_t* (bullet_ctor)(const gunner_t *shooter, const basic_sprite_t *b, double x, double y, double vx, double vy); |
45 | 77 |
void (bullet_dtor)(bullet_t *p); |
... | ... | |
55 | 87 |
void (bullet_update_movement)(bullet_t *p); |
56 | 88 |
void (bullet_update_movement_list)(list_t *bullet_list); |
57 | 89 |
void (bullet_draw)(bullet_t *p); |
58 |
|
|
59 |
void (gunner_draw_list)(list_t *shooter_list); |
|
60 | 90 |
void (bullet_draw_list)(list_t *bullet_list); |
61 |
void (gunner_draw_health)(const gunner_t *p); |
|
62 | 91 |
|
92 |
/** |
|
93 |
* @} |
|
94 |
*/ |
|
95 |
|
|
96 |
/** |
|
97 |
* @defgroup map_t map_t |
|
98 |
* @ingroup ent |
|
99 |
* @brief Bullet module. |
|
100 |
* |
|
101 |
* @{ |
|
102 |
*/ |
|
103 |
|
|
63 | 104 |
typedef struct map map_t; |
64 | 105 |
map_t* (map_ctor)(const char *const *background, const char *const *collide); |
65 | 106 |
void (map_dtor)(map_t *p); |
66 |
int (map_collides_point)(const map_t *p, double x, double y); |
|
67 |
int (map_collides_gunner)(const map_t *p, const gunner_t *gunner); |
|
68 |
int (map_collides_bullet)(const map_t *p, const bullet_t *bullet); |
|
69 | 107 |
uint16_t (map_get_width) (const map_t *p); |
70 | 108 |
uint16_t (map_get_height) (const map_t *p); |
71 | 109 |
int (map_make_dijkstra)(map_t *p, double x_, double y_); |
72 | 110 |
int (map_where_to_follow)(const map_t *p, double x, double y, double *theta); |
73 |
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull); |
|
74 |
double (distance_gunners)(const gunner_t *shooter1, const gunner_t *shooter2); |
|
75 |
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2); |
|
76 | 111 |
void (map_draw)(map_t *p); |
112 |
int (map_collides_point)(const map_t *p, double x, double y); |
|
77 | 113 |
|
114 |
/** |
|
115 |
* @} |
|
116 |
*/ |
|
117 |
|
|
118 |
int (map_collides_gunner)(const map_t *p, const gunner_t *gunner); |
|
119 |
int (map_collides_bullet)(const map_t *p, const bullet_t *bullet); |
|
120 |
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull); |
|
121 |
|
|
78 | 122 |
#endif //ENT_H_INCLUDED |
proj/include/proj_func.h | ||
---|---|---|
43 | 43 |
|
44 | 44 |
double get_mouse_angle(gunner_t *p); |
45 | 45 |
|
46 |
typedef struct timer {
|
|
46 |
typedef struct { |
|
47 | 47 |
int time; |
48 | 48 |
text_t *text; |
49 | 49 |
} text_timer_t; |
proj/include/proj_structures.h | ||
---|---|---|
4 | 4 |
#include <stdint.h> |
5 | 5 |
#include "ent.h" |
6 | 6 |
|
7 |
typedef struct keys { |
|
7 |
/** |
|
8 |
* @brief Key presses. |
|
9 |
*/ |
|
10 |
typedef struct { |
|
8 | 11 |
/// @brief W is pressed when 1 |
9 | 12 |
uint8_t w_pressed : 1; |
10 | 13 |
/// @brief A is pressed when 1 |
... | ... | |
23 | 26 |
uint8_t lb_pressed : 1; |
24 | 27 |
} keys_t; |
25 | 28 |
|
29 |
/** |
|
30 |
* @brief Information to transmit from host to remote. |
|
31 |
*/ |
|
26 | 32 |
typedef struct { |
27 | 33 |
// host |
28 | 34 |
/// @brief Host player X-position |
... | ... | |
49 | 55 |
int16_t remote_current_health; |
50 | 56 |
|
51 | 57 |
// bullets |
58 |
/// @brief Number of bullets |
|
52 | 59 |
uint8_t no_bullets; |
60 |
/// @brief X-position of the bullets |
|
53 | 61 |
int16_t *bullets_x; |
62 |
/// @brief Y-position of the bullets |
|
54 | 63 |
int16_t *bullets_y; |
64 |
/// @brief X-speed of the bullets |
|
55 | 65 |
int16_t *bullets_vx; |
66 |
/// @brief Y-speed of the bullets |
|
56 | 67 |
int16_t *bullets_vy; |
68 |
/// @brief Who shot each bullet |
|
57 | 69 |
bool *bullets_shooter; // false for host, true for remote |
58 | 70 |
} host_info_t; |
71 |
/** |
|
72 |
* @brief Construct host information. |
|
73 |
* @param host Pointer to host gunner |
|
74 |
* @param remote Pointer to remote gunner |
|
75 |
* @return Pointer to constructed host information, or NULL if failed |
|
76 |
*/ |
|
77 |
host_info_t* host_info_ctor(gunner_t *host, gunner_t *remote); |
|
78 |
/** |
|
79 |
* @brief Destruct host information. |
|
80 |
* @param p Pointer to host information to be destructed |
|
81 |
*/ |
|
82 |
void host_info_dtor(host_info_t *p); |
|
59 | 83 |
|
84 |
/** |
|
85 |
* @brief Information to transmit from remote to host. |
|
86 |
*/ |
|
60 | 87 |
typedef struct { |
61 | 88 |
/// @brief Remote keys that are pressed |
62 | 89 |
keys_t remote_keys_pressed; |
63 | 90 |
/// @brief Remote player angle |
64 | 91 |
double remote_angle; |
65 | 92 |
} remote_info_t; |
93 |
/** |
|
94 |
* @brief Construct remote information. |
|
95 |
* @return Pointer to constructed remote information, or NULL if failed |
|
96 |
*/ |
|
97 |
remote_info_t* remote_info_ctor(void); |
|
98 |
/** |
|
99 |
* @brief Destruct remote information. |
|
100 |
* @param p Pointer to remote information to be destructed |
|
101 |
*/ |
|
102 |
void remote_info_dtor(remote_info_t *p); |
|
66 | 103 |
|
104 |
/** |
|
105 |
* @brief Bullet event to transmit from remote to host. |
|
106 |
*/ |
|
67 | 107 |
typedef struct { |
68 | 108 |
/// @brief New bullet signal from remote |
69 | 109 |
bool new_bullet; |
70 | 110 |
} bullet_info_t; |
71 |
|
|
72 |
host_info_t* host_info_ctor(gunner_t *host, gunner_t *remote); |
|
73 |
|
|
74 |
void host_info_dtor(host_info_t *p); |
|
75 |
|
|
76 |
remote_info_t* remote_info_ctor(void); |
|
77 |
|
|
78 |
void remote_info_dtor(remote_info_t *p); |
|
79 |
|
|
111 |
/** |
|
112 |
* @brief Construct bullet event. |
|
113 |
* @return Pointer to constructed bullet event, or NULL if failed |
|
114 |
*/ |
|
80 | 115 |
bullet_info_t* bullet_info_ctor(void); |
81 |
|
|
116 |
/** |
|
117 |
* @brief Destruct bullet event. |
|
118 |
* @param p Pointer to bullet event to be destructed |
|
119 |
*/ |
|
82 | 120 |
void bullet_info_dtor(bullet_info_t *p); |
83 | 121 |
|
84 | 122 |
#endif /* end of include guard: PROJ_STRUCTURES_H_INCLUDED */ |
proj/libs/graph/include/basic_sprite.h | ||
---|---|---|
10 | 10 |
* |
11 | 11 |
* @{ |
12 | 12 |
*/ |
13 |
|
|
14 |
/** |
|
15 |
* @brief Basic sprite. |
|
16 |
*/ |
|
13 | 17 |
typedef struct basic_sprite basic_sprite_t; |
14 | 18 |
|
15 | 19 |
/** |
proj/libs/kbc/include/mouse.h | ||
---|---|---|
19 | 19 |
int (subscribe_mouse_interrupt)(uint8_t interrupt_bit, int *interrupt_id); |
20 | 20 |
|
21 | 21 |
//These have to do with mouse_ih |
22 |
/** |
|
23 |
* @brief Get previous mouse interrupt handler call exit code. |
|
24 |
* @return Exit code of previous mouse IH call |
|
25 |
*/ |
|
22 | 26 |
int (mouse_get_got_error_mouse_ih)(void); |
27 |
/** |
|
28 |
* @brief Get mouse packet. |
|
29 |
* @return Pointer to mouse packet |
|
30 |
*/ |
|
23 | 31 |
const uint8_t* (mouse_get_packet_mouse_ih)(void); |
32 |
/** |
|
33 |
* @brief Number of mouse bytes received (0 to 3). |
|
34 |
* @return Number of bytes |
|
35 |
*/ |
|
24 | 36 |
int (mouse_get_counter_mouse_ih)(void); |
37 |
/** |
|
38 |
* @brief Set number of received mouse bytes. |
|
39 |
* |
|
40 |
* Usually this function is used to reset counter_mouse_ih. |
|
41 |
* @param n New value of the counter |
|
42 |
*/ |
|
25 | 43 |
void (mouse_set_counter_mouse_ih)(int n); |
26 | 44 |
|
27 | 45 |
/** |
proj/libs/timer/include/timer.h | ||
---|---|---|
11 | 11 |
/** @brief Timer 0 IRQ line */ |
12 | 12 |
#define TIMER0_IRQ 0 |
13 | 13 |
|
14 |
/** |
|
15 |
* @brief Subscribes Timer Interrupts and disables Minix Default IH. |
|
16 |
* @param interrupt_bit Bit of Interrupt Vector that will be set when Timer Interrupt is pending |
|
17 |
* @param interrupt_id Timer Interrupt ID to specify the Timer Interrupt in other calls |
|
18 |
* @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK |
|
19 |
* @see {_ERRORS_H_::errors} |
|
20 |
*/ |
|
14 | 21 |
int (subscribe_timer_interrupt)(uint8_t interrupt_bit, int *interrupt_id); |
15 | 22 |
|
23 |
/** |
|
24 |
* @brief Timer interrupt handler. Increases interrupt counter. |
|
25 |
*/ |
|
16 | 26 |
void (timer_int_handler)(void); |
17 | 27 |
|
28 |
/** |
|
29 |
* @brief Get number of timer interrupts. |
|
30 |
* @return Number of timer interrupts. |
|
31 |
*/ |
|
18 | 32 |
uint32_t (timer_get_no_interrupts)(void); |
19 | 33 |
|
20 | 34 |
/** |
proj/src/ent.c | ||
---|---|---|
375 | 375 |
return distance <= shooter_radius+bullet_radius; |
376 | 376 |
} |
377 | 377 |
|
378 |
double (distance_gunners)(const gunner_t *shooter1, const gunner_t *shooter2) { |
|
379 |
double shooter1_x = gunner_get_x(shooter1); |
|
380 |
double shooter1_y = gunner_get_y(shooter1); |
|
381 |
|
|
382 |
double shooter2_x = gunner_get_x(shooter2); |
|
383 |
double shooter2_y = gunner_get_y(shooter2); |
|
384 |
|
|
385 |
double dx = shooter1_x - shooter2_x; |
|
386 |
double dy = shooter1_y - shooter2_y; |
|
387 |
return sqrt(dx*dx + dy*dy); |
|
388 |
} |
|
389 |
|
|
390 | 378 |
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2) { |
391 | 379 |
if (shooter1 == shooter2) return false; |
392 | 380 |
double shooter1_radius = max_d(sprite_get_w(shooter1->dude), sprite_get_h(shooter1->dude))/2.0; |
393 | 381 |
double shooter2_radius = max_d(sprite_get_w(shooter2->dude), sprite_get_h(shooter2->dude))/2.0; |
394 |
double distance = distance_gunners(shooter1, shooter2);
|
|
382 |
double distance = gunner_distance(shooter1, shooter2);
|
|
395 | 383 |
return distance <= shooter1_radius+shooter2_radius; |
396 | 384 |
} |
397 | 385 |
|
proj/src/proj.c | ||
---|---|---|
296 | 296 |
do { |
297 | 297 |
get_random_spawn(map1, shooter1, shooter_list); |
298 | 298 |
get_random_spawn(map1, shooter2, shooter_list); |
299 |
} while (distance_gunners(shooter1, shooter2) < 500);
|
|
299 |
} while (gunner_distance(shooter1, shooter2) < 500);
|
|
300 | 300 |
|
301 | 301 |
host_info = host_info_ctor(shooter1, shooter2); |
302 | 302 |
remote_info = remote_info_ctor(); |
Also available in: Unified diff