Project

General

Profile

Revision 231

shooting things, bit laggy, cause mostly known, to be fixed

View differences:

proj_func.c
9 9
#include "proj_macros.h"
10 10
#include "utils.h"
11 11
#include "ent.h"
12
#include "fast_math.h"
13
#include "bullet.h"
12 14

  
13 15
#include "kbc_macros.h"
14 16

  
......
51 53
}
52 54

  
53 55
void update_movement(const map_t *map, gunner_t *p) {
54
    static const int speed = 5;
55 56
    double x = gunner_get_x(p);
56 57
    double y = gunner_get_y(p);
57
    gunner_set_pos(p, x + speed * hor_mov, y);
58
    gunner_set_pos(p, x + SHOOTER_SPEED * hor_mov, y);
58 59
    if (map_collides_gunner(map, p)) {
59 60
        gunner_set_pos(p, x, y);
60 61
    }
61 62
    x = gunner_get_x(p);
62
    gunner_set_pos(p, x, y + speed * ver_mov);
63
    gunner_set_pos(p, x, y + SHOOTER_SPEED * ver_mov);
63 64
    if (map_collides_gunner(map, p)) {
64 65
        gunner_set_pos(p, x, y);
65 66
    }
66 67
}
67 68

  
69
void (shoot_bullet)(const gunner_t *shooter, list_t *bullet_list) {
70
    double angle = gunner_get_angle(shooter);
71
    double vx = -BULLET_SPEED * fm_sin(angle);
72
    double vy = -BULLET_SPEED * fm_cos(angle);
73
    bullet_t *bullet = bullet_ctor(get_bullet(), gunner_get_x(shooter), gunner_get_y(shooter), vx, vy);
74
    list_insert(bullet_list, list_end(bullet_list), bullet);
75
}
76

  
77
void (update_game_state)(const map_t *map, gunner_t *shooter, list_t *bullet_list) {
78

  
79
    bullet_update_movement_list(bullet_list);
80

  
81
    list_node_t *it = list_begin(bullet_list);
82
    while (it != list_end(bullet_list)) {
83
        bullet_t *bullet = *(bullet_t**)list_node_val(it);
84
        if (map_collides_bullet(map, bullet)) {
85
            list_node_t *aux = list_node_next(it);
86
            bullet = (bullet_t*)list_erase(bullet_list, it);
87
            free(bullet);
88
            it = aux;
89
            continue;
90
        }
91

  
92
        if (gunner_collides_bullet(shooter, bullet)) {
93
            list_node_t *aux = list_node_next(it);
94
            bullet = (bullet_t*)list_erase(bullet_list, it);
95
            gunner_set_curr_health(shooter, gunner_get_curr_health(shooter) - bullet_get_damage(bullet));
96
            free(bullet);
97
            it = aux;
98
            continue;
99
        }
100

  
101
        it = list_node_next(it);
102
    }
103
}
104

  
68 105
void update_scale(void) {
69 106
    static uint8_t last_plus = 0, last_minus = 0;
70 107
    if (key_presses.ctrl_pressed) {
......
88 125

  
89 126
static int32_t mouse_x = 0, mouse_y = 0;
90 127

  
91
void update_mouse_position(struct packet *p) {
128
void (update_mouse)(struct packet *p) {
92 129
    mouse_x = max(0, mouse_x + p->delta_x);
93 130
    mouse_x = min(mouse_x, graph_get_XRes() - 1);
94 131

  
95 132
    mouse_y = max(0, mouse_y - p->delta_y);
96 133
    mouse_y = min(mouse_y, graph_get_YRes() - 1);
134

  
135
    key_presses.lb_pressed = p->lb;
97 136
}
98 137

  
138
keys_t* (get_key_presses)(void) {
139
    return &key_presses;
140
}
141

  
99 142
int32_t get_mouse_X(void) { return mouse_x; }
100 143

  
101 144
int32_t get_mouse_Y(void) { return mouse_y; }

Also available in: Unified diff