Revision 246
convert to lists
proj/include/ent.h | ||
---|---|---|
55 | 55 |
int (map_collides_point)(const map_t *p, double x, double y); |
56 | 56 |
int (map_collides_gunner)(const map_t *p, const gunner_t *gunner); |
57 | 57 |
int (map_collides_bullet)(const map_t *p, const bullet_t *bullet); |
58 |
int16_t (map_get_width) (const map_t *p); |
|
59 |
int16_t (map_get_height) (const map_t *p); |
|
58 | 60 |
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull); |
59 | 61 |
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2); |
60 | 62 |
void (map_draw)(map_t *p); |
proj/include/proj_func.h | ||
---|---|---|
28 | 28 |
/** |
29 | 29 |
* @brief Updates movement variables. |
30 | 30 |
*/ |
31 |
void update_movement(const map_t *map, gunner_t *p, gunner_t *p2);
|
|
31 |
void update_movement(const map_t *map, gunner_t *p, keys_t *keys, list_t *shooter_list);
|
|
32 | 32 |
|
33 | 33 |
void update_mouse(struct packet *p); |
34 | 34 |
|
... | ... | |
38 | 38 |
|
39 | 39 |
void (update_game_state)(const map_t *map, list_t *shooter_list, list_t *bullet_list); |
40 | 40 |
|
41 |
void (get_random_spawn)(const map_t *map, gunner_t *p); |
|
42 |
|
|
41 | 43 |
void update_scale(void); |
42 | 44 |
|
43 | 45 |
int32_t get_mouse_X(void); |
proj/src/ent.c | ||
---|---|---|
215 | 215 |
} |
216 | 216 |
int16_t (map_get_x_screen)(const map_t *p){ return (-x_origin)*scale; } |
217 | 217 |
int16_t (map_get_y_screen)(const map_t *p){ return (-y_origin)*scale; } |
218 |
int16_t (map_get_width) (const map_t *p){ return sprite_get_w(p->background); } |
|
219 |
int16_t (map_get_height) (const map_t *p){ return sprite_get_h(p->background); } |
|
218 | 220 |
int (map_collides_point)(const map_t *p, double x, double y){ |
219 | 221 |
const uint16_t w = sprite_get_w(p->background), h = sprite_get_h(p->background); |
220 | 222 |
int16_t x_ = x, y_ = y; |
proj/src/proj.c | ||
---|---|---|
223 | 223 |
|
224 | 224 |
if (no_interrupts % 180 == 0) gunner_set_pos(shooter2, 775, 75); |
225 | 225 |
|
226 |
update_game_state(map1, shooter_list, bullet_list); |
|
226 |
while (good) { |
|
227 |
/* Get a request message. */ |
|
228 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
|
229 |
printf("driver_receive failed with %d", r); |
|
230 |
continue; |
|
231 |
} |
|
232 |
if (is_ipc_notify(ipc_status)) { /* received notification */ |
|
233 |
switch (_ENDPOINT_P(msg.m_source)) { |
|
234 |
case HARDWARE: /* hardware interrupt notification */ |
|
235 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
|
236 |
if (msg.m_notify.interrupts & n) { |
|
237 |
interrupt_handler(i); |
|
238 |
if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
|
239 |
#ifdef TELMO |
|
240 |
if (i == 0) { |
|
241 |
if (no_interrupts % refresh_count_value == 0) { |
|
242 |
update_movement(map1, shooter1, get_key_presses(), shooter_list); |
|
243 |
//bullet_update_movement(bullet); |
|
227 | 244 |
|
228 |
if(map_collides_gunner(map1, shooter1)){ |
|
229 |
printf("COLLIDING\n"); |
|
230 |
} |
|
231 |
|
|
232 | 245 |
update_scale(); |
233 |
|
|
234 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
235 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
236 |
|
|
237 | 246 |
sprite_set_pos(sp_crosshair, get_mouse_X(), get_mouse_Y()); |
238 | 247 |
double angle = get_mouse_angle(shooter1); |
239 | 248 |
gunner_set_angle(shooter1, angle - M_PI_2); |
... | ... | |
246 | 255 |
gunner_draw(shooter1); |
247 | 256 |
bullet_draw_list(bullet_list); |
248 | 257 |
|
249 |
t = clock()-t; //printf("%d\n", (t*1000)/CLOCKS_PER_SEC); |
|
250 |
|
|
251 | 258 |
sprite_draw(sp_crosshair); |
252 | 259 |
graph_draw(); |
253 | 260 |
} |
... | ... | |
258 | 265 |
update_mouse(&pp); |
259 | 266 |
//printf("X: %d Y: %d\n", get_mouse_X(), get_mouse_Y()); |
260 | 267 |
counter_mouse_ih = 0; |
261 |
|
|
262 |
if (last_lb ^ get_key_presses()->lb_pressed && get_key_presses()->lb_pressed) { |
|
263 |
shoot_bullet(shooter1, bullet_list, bsp_bullet); |
|
264 |
} |
|
265 |
|
|
266 | 268 |
last_lb = get_key_presses()->lb_pressed; |
267 | 269 |
} |
268 | 270 |
} |
proj/src/proj_func.c | ||
---|---|---|
48 | 48 |
} |
49 | 49 |
} |
50 | 50 |
|
51 |
|
|
52 |
void update_movement(const map_t *map, gunner_t *p, gunner_t *p2) { |
|
53 |
int ver_mov = key_presses.s_pressed - key_presses.w_pressed; |
|
54 |
int hor_mov = key_presses.d_pressed - key_presses.a_pressed; |
|
51 |
void update_movement(const map_t *map, gunner_t *p, keys_t *keys, list_t *shooter_list) { |
|
52 |
int ver_mov = keys->s_pressed - keys->w_pressed; |
|
53 |
int hor_mov = keys->d_pressed - keys->a_pressed; |
|
55 | 54 |
double x = gunner_get_x(p); |
56 | 55 |
double y = gunner_get_y(p); |
56 |
|
|
57 | 57 |
gunner_set_pos(p, x + SHOOTER_SPEED * hor_mov, y); |
58 |
if (map_collides_gunner(map, p) || gunner_collides_gunner(p, p2)) { |
|
59 |
gunner_set_pos(p, x, y); |
|
58 |
if (map_collides_gunner(map, p)) gunner_set_pos(p, x, y); |
|
59 |
else { |
|
60 |
list_node_t *it = list_begin(shooter_list); |
|
61 |
while (it != list_end(shooter_list)) { |
|
62 |
gunner_t *p2 = *(gunner_t**)list_node_val(it); |
|
63 |
if (p != p2 && gunner_collides_gunner(p, p2)) { |
|
64 |
gunner_set_pos(p, x, y); |
|
65 |
break; |
|
66 |
} |
|
67 |
it = list_node_next(it); |
|
68 |
} |
|
60 | 69 |
} |
61 |
x = gunner_get_x(p);
|
|
70 |
x = gunner_get_x(p); |
|
62 | 71 |
gunner_set_pos(p, x, y + SHOOTER_SPEED * ver_mov); |
63 |
if (map_collides_gunner(map, p) || gunner_collides_gunner(p, p2)) { |
|
64 |
gunner_set_pos(p, x, y); |
|
72 |
if (map_collides_gunner(map, p)) gunner_set_pos(p, x, y); |
|
73 |
else { |
|
74 |
list_node_t *it = list_begin(shooter_list); |
|
75 |
while (it != list_end(shooter_list)) { |
|
76 |
gunner_t *p2 = *(gunner_t**)list_node_val(it); |
|
77 |
if (p != p2 && gunner_collides_gunner(p, p2)) { |
|
78 |
gunner_set_pos(p, x, y); |
|
79 |
break; |
|
80 |
} |
|
81 |
it = list_node_next(it); |
|
82 |
} |
|
65 | 83 |
} |
66 | 84 |
} |
67 | 85 |
|
... | ... | |
99 | 117 |
/// Change health |
100 | 118 |
gunner_set_curr_health(shooter, gunner_get_curr_health(shooter) - bullet_get_damage(bullet)); |
101 | 119 |
if (gunner_get_curr_health(shooter) <= 0) { |
102 |
shooter = list_erase(shooter_list, shooter_it);
|
|
103 |
gunner_dtor(shooter);
|
|
120 |
gunner_set_curr_health(shooter, gunner_get_health(shooter));
|
|
121 |
get_random_spawn(map, shooter);
|
|
104 | 122 |
} |
105 | 123 |
/// Delete bullet |
106 | 124 |
bullet_dtor(list_erase(bullet_list, bullet_it)); deleted_bullet = true; |
... | ... | |
115 | 133 |
} |
116 | 134 |
} |
117 | 135 |
|
136 |
void (get_random_spawn)(const map_t *map, gunner_t *p) { |
|
137 |
uint16_t w = map_get_width(map), h = map_get_height(map); |
|
138 |
double x, y; |
|
139 |
|
|
140 |
do { |
|
141 |
x = rand() % w; |
|
142 |
y = rand() % h; |
|
143 |
gunner_set_pos(p, x, y); |
|
144 |
} while (map_collides_gunner(map, p)); |
|
145 |
} |
|
146 |
|
|
118 | 147 |
void update_scale(void) { |
119 | 148 |
static uint8_t last_plus = 0, last_minus = 0; |
120 | 149 |
if (key_presses.ctrl_pressed) { |
Also available in: Unified diff