Revision 237
now loading bullet sprite only once
proj/include/ent.h | ||
---|---|---|
34 | 34 |
|
35 | 35 |
struct bullet; |
36 | 36 |
typedef struct bullet bullet_t; |
37 |
bullet_t* (bullet_ctor)(const gunner_t *shooter, basic_sprite_t *b, double x, double y, double vx, double vy); |
|
37 |
bullet_t* (bullet_ctor)(const gunner_t *shooter, const basic_sprite_t *b, double x, double y, double vx, double vy);
|
|
38 | 38 |
void (bullet_dtor)(bullet_t *p); |
39 | 39 |
double (bullet_get_x) (const bullet_t *p); |
40 | 40 |
double (bullet_get_y) (const bullet_t *p); |
proj/include/proj_func.h | ||
---|---|---|
34 | 34 |
|
35 | 35 |
keys_t* (get_key_presses)(void); |
36 | 36 |
|
37 |
void (shoot_bullet)(const gunner_t *shooter, list_t *bullet_list); |
|
37 |
void (shoot_bullet)(const gunner_t *shooter, list_t *bullet_list, const basic_sprite_t *bsp_bullet);
|
|
38 | 38 |
|
39 | 39 |
void (update_game_state)(const map_t *map, list_t *shooter_list, list_t *bullet_list); |
40 | 40 |
|
proj/src/ent.c | ||
---|---|---|
107 | 107 |
sprite_t *b; |
108 | 108 |
int damage; |
109 | 109 |
}; |
110 |
bullet_t* (bullet_ctor)(const gunner_t *shooter, basic_sprite_t *b, double x, double y, double vx, double vy){ |
|
110 |
bullet_t* (bullet_ctor)(const gunner_t *shooter, const basic_sprite_t *b, double x, double y, double vx, double vy){
|
|
111 | 111 |
bullet_t *ret = malloc(sizeof(bullet_t)); |
112 | 112 |
if(ret == NULL) return NULL; |
113 | 113 |
ret->shooter = shooter; |
proj/src/proj.c | ||
---|---|---|
24 | 24 |
#include "shooter.h" |
25 | 25 |
#include "pistol.h" |
26 | 26 |
#include "nothing.h" |
27 |
//#include "bullet.h"
|
|
27 |
#include "bullet.h" |
|
28 | 28 |
#include "map1.h" |
29 | 29 |
|
30 | 30 |
#include "list.h" |
... | ... | |
82 | 82 |
basic_sprite_t *bsp_shooter = NULL; |
83 | 83 |
basic_sprite_t *bsp_pistol = NULL; |
84 | 84 |
basic_sprite_t *bsp_nothing = NULL; |
85 |
map_t *map1 = NULL; |
|
85 |
basic_sprite_t *bsp_bullet = NULL; |
|
86 |
map_t *map1 = NULL; |
|
86 | 87 |
sprite_t *sp_crosshair = NULL; |
87 | 88 |
{ |
88 | 89 |
graph_clear_screen(); |
... | ... | |
95 | 96 |
bsp_shooter = get_shooter (); if(bsp_shooter == NULL) printf("Failed to get shooter\n"); |
96 | 97 |
bsp_pistol = get_pistol (); if(bsp_pistol == NULL) printf("Failed to get pistol\n"); |
97 | 98 |
bsp_nothing = get_nothing (); if(bsp_nothing == NULL) printf("Failed to get nothing\n"); |
99 |
bsp_bullet = get_bullet (); if(bsp_bullet == NULL) printf("Failed to get bullet\n"); |
|
98 | 100 |
map1 = get_map1 (); if(map1 == NULL) printf("Failed to get map1\n"); |
99 | 101 |
|
100 | 102 |
sp_crosshair = sprite_ctor(bsp_crosshair); if(sp_crosshair == NULL) printf("Failed to get crosshair sprite\n"); |
... | ... | |
275 | 277 |
counter_mouse_ih = 0; |
276 | 278 |
|
277 | 279 |
if (last_lb ^ get_key_presses()->lb_pressed && get_key_presses()->lb_pressed) { |
278 |
shoot_bullet(shooter1, bullet_list); |
|
280 |
shoot_bullet(shooter1, bullet_list, bsp_bullet);
|
|
279 | 281 |
} |
280 | 282 |
|
281 | 283 |
last_lb = get_key_presses()->lb_pressed; |
proj/src/proj_func.c | ||
---|---|---|
10 | 10 |
#include "utils.h" |
11 | 11 |
#include "ent.h" |
12 | 12 |
#include "fast_math.h" |
13 |
#include "bullet.h" |
|
14 | 13 |
|
15 | 14 |
#include "kbc_macros.h" |
16 | 15 |
|
... | ... | |
66 | 65 |
} |
67 | 66 |
} |
68 | 67 |
|
69 |
void (shoot_bullet)(const gunner_t *shooter, list_t *bullet_list) { |
|
68 |
void (shoot_bullet)(const gunner_t *shooter, list_t *bullet_list, const basic_sprite_t *bsp_bullet) {
|
|
70 | 69 |
double angle = gunner_get_angle(shooter); |
71 | 70 |
double vx = -BULLET_SPEED * fm_sin(angle); |
72 | 71 |
double vy = -BULLET_SPEED * fm_cos(angle); |
73 |
bullet_t *bullet = bullet_ctor(shooter, get_bullet(), gunner_get_x(shooter), gunner_get_y(shooter), vx, vy);
|
|
72 |
bullet_t *bullet = bullet_ctor(shooter, bsp_bullet, gunner_get_x(shooter), gunner_get_y(shooter), vx, vy);
|
|
74 | 73 |
list_insert(bullet_list, list_end(bullet_list), bullet); |
75 | 74 |
} |
76 | 75 |
|
Also available in: Unified diff