Project

General

Profile

Revision 227

implemented bullet movement and angle

View differences:

proj/include/ent.h
24 24

  
25 25
struct bullet;
26 26
typedef struct bullet bullet_t;
27
bullet_t* (bullet_ctor)(basic_sprite_t *b);
27
bullet_t* (bullet_ctor)(basic_sprite_t *b, double x, double y, double vx, double vy);
28 28
void      (bullet_dtor)(bullet_t *p);
29
void (bullet_set_pos)  (bullet_t *p, double x, double y);
30
void (bullet_set_angle)(bullet_t *p, double angle        );
31 29
double  (bullet_get_x)       (const bullet_t *p);
32 30
double  (bullet_get_y)       (const bullet_t *p);
33 31
int16_t (bullet_get_x_screen)(const bullet_t *p);
proj/src/ent.c
65 65
    double vx, vy;
66 66
    sprite_t *b;
67 67
};
68
bullet_t* (bullet_ctor)(basic_sprite_t *b){
68
bullet_t* (bullet_ctor)(basic_sprite_t *b, double x, double y, double vx, double vy){
69 69
    bullet_t *ret = malloc(sizeof(bullet_t));
70 70
    if(ret == NULL) return NULL;
71
    ret-> x = 0.0;
72
    ret-> y = 0.0;
73
    ret->vx = 0.0;
74
    ret->vy = 0.0;
71
    ret-> x =  x;
72
    ret-> y =  y;
73
    ret->vx = vx;
74
    ret->vy = vy;
75 75
    ret->b = sprite_ctor(b);
76 76
    if(ret->b == NULL){
77 77
        bullet_dtor(ret);
78 78
        return NULL;
79
    }else return ret;
79
    }
80
    double angle = atan2(-ret->vy, ret->vx);
81
    sprite_set_angle(ret->b, angle-M_PI_2);
82
    return ret;
80 83
}
81 84
void (bullet_dtor)(bullet_t *p){
82 85
    if(p == NULL) return;
83 86
    sprite_dtor(p->b);
84 87
    free(p);
85 88
}
86
void (bullet_set_pos)  (bullet_t *p, double x, double y){ p->x = x; p->y = y; }
87
void (bullet_set_angle)(bullet_t *p, double angle      ){ sprite_set_angle(p->b, angle); }
88 89
double  (bullet_get_x)       (const bullet_t *p){ return p->x; }
89 90
double  (bullet_get_y)       (const bullet_t *p){ return p->y; }
90 91
int16_t (bullet_get_x_screen)(const bullet_t *p){ return (p->x-x_origin)*scale; }
proj/src/proj.c
145 145
        gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing);
146 146
        gunner_set_pos(shooter2, -50, -50);
147 147

  
148
        bullet_t *bullet = bullet_ctor(get_bullet());
149
        bullet_set_pos(bullet, 400, 400);
148
        bullet_t *bullet = bullet_ctor(get_bullet(), 400.0, 400.0, 2.0, -1.0);
150 149

  
151 150
        ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
152 151
                       gunner_get_y(shooter1)-ent_get_YLength()/2.0);
......
180 179
                            if (i == 0) {
181 180
                                if (no_interrupts % refresh_count_value == 0) {
182 181
                                    update_movement(map1, shooter1);
182
                                    bullet_update_movement(bullet);
183 183

  
184 184
                                    if(map_collides_gunner(map1, shooter1)){
185 185
                                        printf("COLLIDING\n");

Also available in: Unified diff