Project

General

Profile

Revision 201

renamed gunner

View differences:

proj/include/ent.h
10 10
double (ent_get_XLength)(void);
11 11
double (ent_get_YLength)(void);
12 12

  
13
struct ent;
14
typedef struct ent ent_t;
13
struct gunner;
14
typedef struct gunner gunner_t;
15
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon);
16
void      (gunner_dtor)(gunner_t *p);
17
void (gunner_set_pos)  (gunner_t *p, int16_t x, int16_t y);
18
void (gunner_set_angle)(gunner_t *p, double angle        );
19
double  (gunner_get_x)       (const gunner_t *p);
20
double  (gunner_get_y)       (const gunner_t *p);
21
int16_t (gunner_get_x_screen)(const gunner_t *p);
22
int16_t (gunner_get_y_screen)(const gunner_t *p);
23
void (gunner_draw)(gunner_t *p);
15 24

  
16
ent_t* (ent_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon);
17
void   (ent_dtor)(ent_t *p);
25
struct bullet;
26
typedef struct bullet bullet_t;
27
bullet_t* (bullet_ctor)(basic_sprite_t *b);
18 28

  
19
void (ent_set_pos)  (ent_t *p, int16_t x, int16_t y);
20
void (ent_set_angle)(ent_t *p, double angle        );
21

  
22
double  (ent_get_x)       (const ent_t *p);
23
double  (ent_get_y)       (const ent_t *p);
24
int16_t (ent_get_x_screen)(const ent_t *p);
25
int16_t (ent_get_y_screen)(const ent_t *p);
26

  
27
void (ent_draw)(ent_t *p);
28

  
29 29
#endif //ENT_H_INCLUDED
proj/include/proj_func.h
17 17
/**
18 18
 * @brief Updates movement variables.
19 19
 */
20
void update_movement(ent_t *p);
20
void update_movement(gunner_t *p);
21 21

  
22 22
typedef struct keys {
23 23
    uint8_t w_pressed       : 1;
......
44 44
 * @param
45 45
 * @return Angle
46 46
 */
47
double get_mouse_angle(ent_t *p);
47
double get_mouse_angle(gunner_t *p);
48 48

  
49 49
/**
50 50
 * @brief Get horizontal movement direction.
proj/src/ent.c
15 15
double (ent_get_XLength)(void){ return graph_get_XRes()/scale; }
16 16
double (ent_get_YLength)(void){ return graph_get_YRes()/scale; }
17 17

  
18
struct ent{
18
struct gunner{
19 19
    double x, y; //real position in meters
20 20
    sprite_t *dude;
21 21
    sprite_t *weapon;
22 22
};
23 23

  
24
ent_t* (ent_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon){
25
    ent_t *ret = malloc(sizeof(ent_t));
24
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon){
25
    gunner_t *ret = malloc(sizeof(gunner_t));
26 26
    if(ret == NULL) return NULL;
27 27
    ret->x = 0.0;
28 28
    ret->y = 0.0;
29 29
    ret->dude   = sprite_ctor(dude  );
30 30
    ret->weapon = sprite_ctor(weapon);
31 31
    if(ret->dude == NULL || ret->weapon == NULL){
32
        ent_dtor(ret);
32
        gunner_dtor(ret);
33 33
        return NULL;
34 34
    } else return ret;
35 35
}
36
void (ent_dtor)(ent_t *p){
36
void (gunner_dtor)(gunner_t *p){
37 37
    if(p == NULL) return;
38 38
    sprite_dtor(p->dude);
39 39
    sprite_dtor(p->weapon);
40 40
    free(p);
41 41
}
42 42

  
43
void (ent_set_pos)  (ent_t *p, int16_t x, int16_t y){ p->x = x; p->y = y; }
44
void (ent_set_angle)(ent_t *p, double angle        ){
43
void (gunner_set_pos)  (gunner_t *p, int16_t x, int16_t y){ p->x = x; p->y = y; }
44
void (gunner_set_angle)(gunner_t *p, double angle        ){
45 45
    sprite_set_angle(p->dude  , angle);
46 46
    sprite_set_angle(p->weapon, angle);
47 47
}
48 48

  
49
double  (ent_get_x)       (const ent_t *p){ return p->x; }
50
double  (ent_get_y)       (const ent_t *p){ return p->y; }
51
int16_t (ent_get_x_screen)(const ent_t *p){ return (p->x-x_origin)*scale; }
52
int16_t (ent_get_y_screen)(const ent_t *p){ return (p->y-y_origin)*scale; }
49
double  (gunner_get_x)       (const gunner_t *p){ return p->x; }
50
double  (gunner_get_y)       (const gunner_t *p){ return p->y; }
51
int16_t (gunner_get_x_screen)(const gunner_t *p){ return (p->x-x_origin)*scale; }
52
int16_t (gunner_get_y_screen)(const gunner_t *p){ return (p->y-y_origin)*scale; }
53 53

  
54
void (ent_draw)(ent_t *p){
55
    const int16_t x_screen = ent_get_x_screen(p);
56
    const int16_t y_screen = ent_get_y_screen(p);
54
void (gunner_draw)(gunner_t *p){
55
    const int16_t x_screen = gunner_get_x_screen(p);
56
    const int16_t y_screen = gunner_get_y_screen(p);
57 57
    sprite_set_pos  (p->dude  , x_screen, y_screen);
58 58
    sprite_set_pos  (p->weapon, x_screen, y_screen);
59 59
    sprite_set_scale(p->dude  , scale);
proj/src/proj.c
109 109
    #ifdef TELMO
110 110
        ent_set_scale(2.0);
111 111

  
112
        ent_t *shooter1 = ent_ctor(bsp_shooter, bsp_pistol); if(shooter1 == NULL) printf("Failed to get shooter1\n");
113
        ent_set_pos(shooter1, 0, 0);
114
        ent_set_origin(ent_get_x(shooter1)-ent_get_XLength()/2.0,
115
                       ent_get_y(shooter1)-ent_get_YLength()/2.0);
112
        gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol); if(shooter1 == NULL) printf("Failed to get shooter1\n");
113
        gunner_set_pos(shooter1, 0, 0);
114
        ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
115
                       gunner_get_y(shooter1)-ent_get_YLength()/2.0);
116 116

  
117
        ent_t *shooter2 = ent_ctor(bsp_shooter, bsp_nothing);
118
        ent_set_pos(shooter2, -50, -50);
117
        gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing);
118
        gunner_set_pos(shooter2, -50, -50);
119 119

  
120 120
        graph_clear_screen();
121
        ent_draw(shooter1);
121
        gunner_draw(shooter1);
122 122
        sprite_draw(sp_crosshair);
123 123
        graph_draw();
124 124

  
......
152 152
                                if (no_interrupts % refresh_count_value == 0) {
153 153
                                    update_movement(shooter1);
154 154
                                    update_scale();
155
                                    ent_set_origin(ent_get_x(shooter1)-ent_get_XLength()/2.0,
156
                                                   ent_get_y(shooter1)-ent_get_YLength()/2.0);
155
                                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
156
                                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
157 157

  
158 158
                                    sprite_set_pos(sp_crosshair, get_mouse_X(), get_mouse_Y());
159 159
                                    double angle = get_mouse_angle(shooter1);
160
                                    ent_set_angle(shooter1, angle - M_PI_2);
160
                                    gunner_set_angle(shooter1, angle - M_PI_2);
161 161
                                    graph_clear_screen();
162
                                    ent_draw(shooter2);
163
                                    ent_draw(shooter1);
162
                                    gunner_draw(shooter2);
163
                                    gunner_draw(shooter1);
164 164
                                    sprite_draw(sp_crosshair);
165 165
                                    graph_draw();
166 166
                                }
......
187 187
    }
188 188

  
189 189
    #ifdef TELMO
190
        ent_dtor(shooter1); shooter1 = NULL;
190
        gunner_dtor(shooter1); shooter1 = NULL;
191 191
    #endif
192 192

  
193 193
    basic_sprite_dtor(bsp_crosshair); bsp_crosshair = NULL;
proj/src/proj_func.c
50 50
    hor_mov = key_presses.d_pressed - key_presses.a_pressed;
51 51
}
52 52

  
53
void update_movement(ent_t *p) {
53
void update_movement(gunner_t *p) {
54 54
    static const int speed = 5;
55
    ent_set_pos(p, ent_get_x(p) + speed * hor_mov, ent_get_y(p) + speed * ver_mov);
55
    gunner_set_pos(p, gunner_get_x(p) + speed * hor_mov, gunner_get_y(p) + speed * ver_mov);
56 56
}
57 57

  
58 58
void update_scale(void) {
......
90 90

  
91 91
int32_t get_mouse_Y(void) { return mouse_y; }
92 92

  
93
double get_mouse_angle(ent_t *p) {
94
    return atan2(ent_get_y_screen(p) - mouse_y, mouse_x - ent_get_x_screen(p));
93
double get_mouse_angle(gunner_t *p) {
94
    return atan2(gunner_get_y_screen(p) - mouse_y, mouse_x - gunner_get_x_screen(p));
95 95
}
96 96

  
97 97
int get_hor_movement(void) { return hor_mov; }

Also available in: Unified diff