Revision 302
working on zombies
proj/include/ent.h | ||
---|---|---|
19 | 19 |
|
20 | 20 |
struct gunner; |
21 | 21 |
typedef struct gunner gunner_t; |
22 |
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon, gunner_type tp);
|
|
22 |
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon, gunner_type type, int team);
|
|
23 | 23 |
void (gunner_dtor)(gunner_t *p); |
24 | 24 |
void (gunner_set_pos) (gunner_t *p, double x, double y); |
25 | 25 |
void (gunner_set_spawn) (gunner_t *p, double x, double y); |
... | ... | |
36 | 36 |
int16_t (gunner_get_x_screen) (const gunner_t *p); |
37 | 37 |
int16_t (gunner_get_y_screen) (const gunner_t *p); |
38 | 38 |
gunner_type (gunner_get_type) (const gunner_t *p); |
39 |
int (gunner_get_team) (const gunner_t *p); |
|
39 | 40 |
void (gunner_draw)(gunner_t *p); |
40 | 41 |
void (gunner_draw_health)(const gunner_t *p); |
41 | 42 |
|
43 |
double (gunner_distance)(const gunner_t *p1, const gunner_t *p2); |
|
44 |
|
|
42 | 45 |
struct bullet; |
43 | 46 |
typedef struct bullet bullet_t; |
44 | 47 |
bullet_t* (bullet_ctor)(const gunner_t *shooter, const basic_sprite_t *b, double x, double y, double vx, double vy); |
... | ... | |
49 | 52 |
int16_t (bullet_get_y_screen)(const bullet_t *p); |
50 | 53 |
double (bullet_get_damage) (const bullet_t *p); |
51 | 54 |
void (bullet_set_damage) (bullet_t *p, double damage); |
55 |
const gunner_t* (bullet_get_shooter)(const bullet_t *p); |
|
52 | 56 |
void (bullet_update_movement)(bullet_t *p); |
53 | 57 |
void (bullet_update_movement_list)(list_t *bullet_list); |
54 | 58 |
void (bullet_draw)(bullet_t *p); |
proj/include/proj_macros.h | ||
---|---|---|
26 | 26 |
#define HIGHLIGHT_COLOR 0x404040 |
27 | 27 |
#define DELIMITER_COLOR 0x404040 |
28 | 28 |
|
29 |
#define MEELEE_RANGE 150 |
|
30 |
#define MEELEE_DAMAGE 1 |
|
31 |
|
|
29 | 32 |
#endif /* end of include guard: PROJ_MACROS_H_INCLUDED */ |
proj/src/ent.c | ||
---|---|---|
24 | 24 |
sprite_t *weapon; |
25 | 25 |
double health, current_health; |
26 | 26 |
gunner_type type; |
27 |
int team; |
|
27 | 28 |
}; |
28 |
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon, gunner_type tp){
|
|
29 |
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon, gunner_type type, int team){
|
|
29 | 30 |
gunner_t *ret = malloc(sizeof(gunner_t)); |
30 | 31 |
if(ret == NULL) return NULL; |
31 | 32 |
ret->spawn_x = 0.0; |
... | ... | |
34 | 35 |
ret->y = 0.0; |
35 | 36 |
ret->health = 100; |
36 | 37 |
ret->current_health = ret->health; |
37 |
ret->type = tp; |
|
38 |
ret->type = type; |
|
39 |
ret->team = team; |
|
38 | 40 |
ret->dude = sprite_ctor(dude ); |
39 | 41 |
ret->weapon = sprite_ctor(weapon); |
40 | 42 |
if(ret->dude == NULL || ret->weapon == NULL){ |
... | ... | |
72 | 74 |
int16_t (gunner_get_x_screen) (const gunner_t *p){ return (p->x-x_origin)*scale; } |
73 | 75 |
int16_t (gunner_get_y_screen) (const gunner_t *p){ return (p->y-y_origin)*scale; } |
74 | 76 |
gunner_type (gunner_get_type) (const gunner_t *p){ return p->type; } |
77 |
int (gunner_get_team) (const gunner_t *p){ return p->team; } |
|
75 | 78 |
void (gunner_draw)(gunner_t *p){ |
76 | 79 |
const int16_t x_screen = gunner_get_x_screen(p); |
77 | 80 |
const int16_t y_screen = gunner_get_y_screen(p); |
... | ... | |
102 | 105 |
rectangle_dtor(red_bar); |
103 | 106 |
} |
104 | 107 |
|
108 |
double (gunner_distance)(const gunner_t *p1, const gunner_t *p2){ |
|
109 |
double dx = gunner_get_x(p1) - gunner_get_x(p2); |
|
110 |
double dy = gunner_get_y(p1) - gunner_get_y(p2); |
|
111 |
return sqrt(dx*dx+dy*dy); |
|
112 |
} |
|
113 |
|
|
105 | 114 |
struct bullet{ |
106 | 115 |
const gunner_t *shooter; |
107 | 116 |
double x, y; //real position |
... | ... | |
141 | 150 |
if (damage < 0) damage = 0; |
142 | 151 |
p->damage = damage; |
143 | 152 |
} |
153 |
const gunner_t* (bullet_get_shooter)(const bullet_t *p){ return p->shooter; } |
|
144 | 154 |
void (bullet_update_movement)(bullet_t *p){ |
145 | 155 |
p->x += p->vx; |
146 | 156 |
p->y += p->vy; |
proj/src/proj.c | ||
---|---|---|
288 | 288 |
|
289 | 289 |
list_t *shooter_list = list_ctor(); |
290 | 290 |
|
291 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
|
291 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
|
|
292 | 292 |
gunner_set_spawn(shooter1, 75, 75); |
293 | 293 |
gunner_set_pos(shooter1, 75, 75); |
294 | 294 |
|
295 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing, gunner_player); |
|
295 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing, gunner_player, 2);
|
|
296 | 296 |
gunner_set_spawn(shooter2, 975, 75); |
297 | 297 |
gunner_set_pos(shooter2, 775, 75); |
298 | 298 |
|
... | ... | |
343 | 343 |
|
344 | 344 |
graph_clear_screen(); |
345 | 345 |
map_draw (map1); |
346 |
bullet_draw_list(bullet_list); |
|
346 | 347 |
gunner_draw_list(shooter_list); |
347 |
bullet_draw_list(bullet_list); |
|
348 | 348 |
|
349 | 349 |
text_draw(in_game_timer->text); |
350 | 350 |
|
... | ... | |
424 | 424 |
|
425 | 425 |
list_t *shooter_list = list_ctor(); |
426 | 426 |
|
427 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
|
427 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
|
|
428 | 428 |
gunner_set_spawn(shooter1, 75, 75); |
429 | 429 |
gunner_set_pos(shooter1, 75, 75); |
430 | 430 |
|
... | ... | |
444 | 444 |
int ipc_status; |
445 | 445 |
message msg; |
446 | 446 |
int good = true; |
447 |
int dead = false; |
|
447 | 448 |
|
448 | 449 |
int health = 50; |
449 | 450 |
|
450 |
while (good) { |
|
451 |
while (good && !dead) {
|
|
451 | 452 |
/* Get a request message. */ |
452 | 453 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
453 | 454 |
printf("driver_receive failed with %d", r); |
... | ... | |
467 | 468 |
|
468 | 469 |
update_game_state(map1, shooter_list, bullet_list);//printf("L468\n"); |
469 | 470 |
|
471 |
if(list_find(shooter_list, shooter1) == list_end(shooter_list)){ printf("YOU DIED\n"); |
|
472 |
good = false; |
|
473 |
dead = true; |
|
474 |
break; |
|
475 |
} //printf("L489\n"); |
|
476 |
|
|
470 | 477 |
//update_scale(); |
471 | 478 |
double angle = get_mouse_angle(shooter1);//printf("L471\n"); |
472 | 479 |
gunner_set_angle(shooter1, angle - M_PI_2); //printf("L472\n"); |
... | ... | |
475 | 482 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
476 | 483 |
|
477 | 484 |
while(list_size(shooter_list) < ZOMBIES_NUM){ |
478 |
gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, gunner_meelee); |
|
485 |
gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, gunner_meelee, 3);
|
|
479 | 486 |
gunner_set_health(zombie, health); |
480 | 487 |
gunner_set_curr_health(zombie, health); |
481 | 488 |
health *= ZOMBIE_HEALTH_FACTOR; |
... | ... | |
483 | 490 |
list_push_back(shooter_list, zombie); |
484 | 491 |
} //printf("L484\n"); |
485 | 492 |
|
486 |
if(list_find(shooter_list, shooter1) == list_end(shooter_list)){ |
|
487 |
good = false; |
|
488 |
break; |
|
489 |
} //printf("L489\n"); |
|
490 | 493 |
graph_clear_screen(); |
491 | 494 |
map_draw (map1); |
495 |
bullet_draw_list(bullet_list); |
|
492 | 496 |
gunner_draw_list(shooter_list); |
493 |
bullet_draw_list(bullet_list); //printf("L502\n"); |
|
494 | 497 |
|
495 | 498 |
text_draw(in_game_timer->text); |
496 | 499 |
|
... | ... | |
553 | 556 |
} |
554 | 557 |
if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
555 | 558 |
|
559 |
if(dead){ |
|
560 |
printf("YOU DIED\n"); |
|
561 |
} |
|
562 |
|
|
556 | 563 |
timer_dtor(in_game_timer); in_game_timer = NULL; |
557 | 564 |
|
558 | 565 |
return SUCCESS; |
proj/src/proj_func.c | ||
---|---|---|
92 | 92 |
} |
93 | 93 |
|
94 | 94 |
void (update_game_state)(const map_t *map, list_t *shooter_list, list_t *bullet_list) { |
95 |
|
|
95 |
/// BULLETS |
|
96 | 96 |
bullet_update_movement_list(bullet_list); |
97 |
|
|
98 | 97 |
list_node_t *bullet_it = list_begin(bullet_list); |
99 | 98 |
while (bullet_it != list_end(bullet_list)) { |
100 | 99 |
/// Collision with walls |
... | ... | |
112 | 111 |
int deleted_bullet = false; |
113 | 112 |
while(shooter_it != list_end(shooter_list)){ |
114 | 113 |
gunner_t *shooter = *(gunner_t**)list_node_val(shooter_it); |
115 |
if(gunner_collides_bullet(shooter, bullet)) { |
|
114 |
if(gunner_collides_bullet(shooter, bullet) && |
|
115 |
gunner_get_team(shooter) != gunner_get_team(bullet_get_shooter(bullet))) { |
|
116 | 116 |
list_node_t *aux = list_node_next(bullet_it); |
117 | 117 |
/// Change health |
118 | 118 |
gunner_set_curr_health(shooter, gunner_get_curr_health(shooter) - bullet_get_damage(bullet)); |
... | ... | |
130 | 130 |
/// Advance iterator if necessary |
131 | 131 |
bullet_it = list_node_next(bullet_it); |
132 | 132 |
} |
133 |
/// MEELEE |
|
134 |
list_node_t *it1 = list_begin(shooter_list); |
|
135 |
while(it1 != list_end(shooter_list)){ |
|
136 |
gunner_t *s1 = *list_node_val(it1); |
|
137 |
if(gunner_get_type(s1) != gunner_meelee){ it1 = list_node_next(it1); continue; } |
|
138 |
list_node_t *it2 = list_begin(shooter_list); |
|
139 |
while(it2 != list_end(shooter_list)){ |
|
140 |
gunner_t *s2 = *list_node_val(it2); |
|
141 |
if(s1 != s2 && gunner_distance(s1, s2) < MEELEE_RANGE) |
|
142 |
gunner_set_curr_health(s2, gunner_get_curr_health(s2) - MEELEE_DAMAGE); |
|
143 |
if(gunner_get_curr_health(s2) <= 0){ |
|
144 |
list_node_t *aux = list_node_next(it2); |
|
145 |
gunner_dtor(list_erase(shooter_list, it2)); |
|
146 |
it2 = aux; |
|
147 |
}else it2 = list_node_next(it2); |
|
148 |
} |
|
149 |
it1 = list_node_next(it1); |
|
150 |
} |
|
133 | 151 |
} |
134 | 152 |
|
135 | 153 |
void (get_random_spawn)(const map_t *map, gunner_t *p) { |
Also available in: Unified diff