Revision 231
shooting things, bit laggy, cause mostly known, to be fixed
proj/include/ent.h | ||
---|---|---|
2 | 2 |
#define ENT_H_INCLUDED |
3 | 3 |
|
4 | 4 |
#include "sprite.h" |
5 |
#include "list.h" |
|
5 | 6 |
|
6 | 7 |
void (ent_set_scale) (double n); |
7 | 8 |
void (ent_set_origin)(double x, double y); |
... | ... | |
20 | 21 |
void (gunner_set_curr_health) (gunner_t *p, int health); |
21 | 22 |
double (gunner_get_x) (const gunner_t *p); |
22 | 23 |
double (gunner_get_y) (const gunner_t *p); |
24 |
double (gunner_get_angle) (const gunner_t *p); |
|
23 | 25 |
int (gunner_get_health) (const gunner_t *p); |
24 | 26 |
int (gunner_get_curr_health) (const gunner_t *p); |
25 | 27 |
int16_t (gunner_get_x_screen) (const gunner_t *p); |
... | ... | |
38 | 40 |
int (bullet_get_damage) (const bullet_t *p); |
39 | 41 |
void (bullet_set_damage) (bullet_t *p, int damage); |
40 | 42 |
void (bullet_update_movement)(bullet_t *p); |
43 |
void (bullet_update_movement_list)(list_t *bullet_list); |
|
41 | 44 |
void (bullet_draw)(bullet_t *p); |
45 |
void (bullet_draw_list)(list_t *bullet_list); |
|
42 | 46 |
void (gunner_draw_health)(const gunner_t *p); |
43 | 47 |
|
44 | 48 |
struct map; |
proj/include/proj_func.h | ||
---|---|---|
27 | 27 |
uint8_t ctrl_pressed : 1; |
28 | 28 |
uint8_t plus_pressed : 1; |
29 | 29 |
uint8_t minus_pressed : 1; |
30 |
uint8_t lb_pressed : 1; |
|
30 | 31 |
} keys_t; |
31 | 32 |
|
32 |
void update_mouse_position(struct packet *p);
|
|
33 |
void update_mouse(struct packet *p); |
|
33 | 34 |
|
35 |
keys_t* (get_key_presses)(void); |
|
36 |
|
|
37 |
void (shoot_bullet)(const gunner_t *shooter, list_t *bullet_list); |
|
38 |
|
|
39 |
void (update_game_state)(const map_t *map, gunner_t *shooter, list_t *bullet_list); |
|
40 |
|
|
34 | 41 |
void update_scale(void); |
35 | 42 |
|
36 | 43 |
int32_t get_mouse_X(void); |
proj/include/proj_macros.h | ||
---|---|---|
26 | 26 |
#define RIGHT 1 /** @brief Moving to the right side of screen */ |
27 | 27 |
#define REST 0 /** @brief Not moving */ |
28 | 28 |
|
29 |
// Movement Constants |
|
30 |
#define SHOOTER_SPEED 5 /** @brief Shooter speed */ |
|
31 |
#define BULLET_SPEED 8 /** @brief Bullet speet */ |
|
32 |
|
|
29 | 33 |
// Extra Keys |
30 | 34 |
#define ESC_MAKE_CODE 0x01 /** @brief ESC Make Code */ |
31 | 35 |
#define ESC_BREAK_CODE 0x81 /** @brief ESC Break Code */ |
proj/include/sprite.h | ||
---|---|---|
42 | 42 |
|
43 | 43 |
int16_t (sprite_get_x)(const sprite_t *p); |
44 | 44 |
int16_t (sprite_get_y)(const sprite_t *p); |
45 |
double (sprite_get_angle)(const sprite_t *p); |
|
45 | 46 |
uint16_t (sprite_get_w)(const sprite_t *p); |
46 | 47 |
uint16_t (sprite_get_h)(const sprite_t *p); |
47 | 48 |
|
proj/src/ent.c | ||
---|---|---|
59 | 59 |
} |
60 | 60 |
double (gunner_get_x) (const gunner_t *p){ return p->x; } |
61 | 61 |
double (gunner_get_y) (const gunner_t *p){ return p->y; } |
62 |
double (gunner_get_angle) (const gunner_t *p){ return sprite_get_angle(p->dude); } |
|
62 | 63 |
int (gunner_get_health) (const gunner_t *p){ return p->health; } |
63 | 64 |
int (gunner_get_curr_health) (const gunner_t *p){ return p->current_health; } |
64 | 65 |
int16_t (gunner_get_x_screen) (const gunner_t *p){ return (p->x-x_origin)*scale; } |
... | ... | |
134 | 135 |
p->x += p->vx; |
135 | 136 |
p->y += p->vy; |
136 | 137 |
} |
138 |
|
|
139 |
void (bullet_update_movement_list)(list_t *bullet_list){ |
|
140 |
if (bullet_list == NULL) return; |
|
141 |
if (list_size(bullet_list) == 0) return; |
|
142 |
|
|
143 |
list_node_t *it = list_begin(bullet_list); |
|
144 |
while (it != list_end(bullet_list)) { |
|
145 |
bullet_update_movement(*(bullet_t**)list_node_val(it)); |
|
146 |
it = list_node_next(it); |
|
147 |
} |
|
148 |
} |
|
149 |
|
|
137 | 150 |
void (bullet_draw)(bullet_t *p){ |
138 | 151 |
const int16_t x_screen = bullet_get_x_screen(p); |
139 | 152 |
const int16_t y_screen = bullet_get_y_screen(p); |
... | ... | |
142 | 155 |
sprite_draw (p->b); |
143 | 156 |
} |
144 | 157 |
|
158 |
void (bullet_draw_list)(list_t *bullet_list) { |
|
159 |
if (bullet_list == NULL) return; |
|
160 |
if (list_size(bullet_list) == 0) return; |
|
161 |
|
|
162 |
list_node_t *it = list_begin(bullet_list); |
|
163 |
while (it != list_end(bullet_list)) { |
|
164 |
bullet_draw(*(bullet_t**)list_node_val(it)); |
|
165 |
it = list_node_next(it); |
|
166 |
} |
|
167 |
} |
|
168 |
|
|
145 | 169 |
struct map{ |
146 | 170 |
basic_sprite_t *bsp_background; |
147 | 171 |
sprite_t *background; |
proj/src/graph.c | ||
---|---|---|
363 | 363 |
void (sprite_set_scale) (sprite_t *p, double scale ){ p->scale = scale; } |
364 | 364 |
int16_t (sprite_get_x)(const sprite_t *p){ return p->x; } |
365 | 365 |
int16_t (sprite_get_y)(const sprite_t *p){ return p->y; } |
366 |
double (sprite_get_angle)(const sprite_t *p){ return p->theta; } |
|
366 | 367 |
uint16_t (sprite_get_w)(const sprite_t *p){ return basic_sprite_get_w(p->bsp); } |
367 | 368 |
uint16_t (sprite_get_h)(const sprite_t *p){ return basic_sprite_get_h(p->bsp); } |
368 | 369 |
void (sprite_src2pic)(const sprite_t *p, int16_t x, int16_t y, int16_t *u, int16_t *v){ |
proj/src/proj.c | ||
---|---|---|
23 | 23 |
#include "shooter.h" |
24 | 24 |
#include "pistol.h" |
25 | 25 |
#include "nothing.h" |
26 |
#include "bullet.h" |
|
26 |
//#include "bullet.h"
|
|
27 | 27 |
#include "map1.h" |
28 | 28 |
|
29 | 29 |
#include "list.h" |
... | ... | |
143 | 143 |
gunner_set_pos(shooter1, 75, 75); |
144 | 144 |
|
145 | 145 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing); |
146 |
gunner_set_pos(shooter2, -50, -50);
|
|
146 |
gunner_set_pos(shooter2, 775, 75);
|
|
147 | 147 |
|
148 |
bullet_t *bullet = bullet_ctor(get_bullet(), 400.0, 400.0, 2.0, -1.0); |
|
148 |
//bullet_t *bullet = bullet_ctor(get_bullet(), 400.0, 400.0, 2.0, -1.0);
|
|
149 | 149 |
|
150 |
list_t *bullet_list = list_ctor(); |
|
151 |
|
|
150 | 152 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
151 | 153 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
152 | 154 |
|
153 | 155 |
uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
156 |
|
|
157 |
uint8_t last_lb = 0; |
|
154 | 158 |
#endif |
155 | 159 |
|
156 | 160 |
/// loop stuff |
... | ... | |
180 | 184 |
if (no_interrupts % refresh_count_value == 0) { |
181 | 185 |
update_movement(map1, shooter1); |
182 | 186 |
//bullet_update_movement(bullet); |
187 |
update_game_state(map1, shooter2, bullet_list); |
|
183 | 188 |
|
184 | 189 |
if(map_collides_gunner(map1, shooter1)){ |
185 | 190 |
printf("COLLIDING\n"); |
186 | 191 |
} |
187 | 192 |
|
188 |
if (gunner_collides_bullet(shooter1, bullet)) { |
|
193 |
/*if (gunner_collides_bullet(shooter1, bullet)) {
|
|
189 | 194 |
printf("Bullet Collide with Shooter\n"); |
190 | 195 |
gunner_set_curr_health(shooter1, gunner_get_curr_health(shooter1) - bullet_get_damage(bullet)); |
191 |
} |
|
196 |
}*/
|
|
192 | 197 |
|
193 | 198 |
update_scale(); |
194 | 199 |
|
... | ... | |
205 | 210 |
map_draw (map1); |
206 | 211 |
gunner_draw(shooter2); |
207 | 212 |
gunner_draw(shooter1); |
208 |
bullet_draw(bullet);
|
|
213 |
bullet_draw_list(bullet_list);
|
|
209 | 214 |
|
210 | 215 |
t = clock()-t; //printf("%d\n", (t*1000)/CLOCKS_PER_SEC); |
211 | 216 |
|
... | ... | |
216 | 221 |
if (i == 12) { |
217 | 222 |
if (counter_mouse_ih >= 3) { |
218 | 223 |
struct packet pp = mouse_parse_packet(packet_mouse_ih); |
219 |
update_mouse_position(&pp);
|
|
224 |
update_mouse(&pp); |
|
220 | 225 |
//printf("X: %d Y: %d\n", get_mouse_X(), get_mouse_Y()); |
221 | 226 |
counter_mouse_ih = 0; |
227 |
|
|
228 |
if (last_lb ^ get_key_presses()->lb_pressed && get_key_presses()->lb_pressed) { |
|
229 |
shoot_bullet(shooter1, bullet_list); |
|
230 |
} |
|
231 |
|
|
232 |
last_lb = get_key_presses()->lb_pressed; |
|
222 | 233 |
} |
223 | 234 |
} |
224 | 235 |
#endif |
... | ... | |
237 | 248 |
#ifdef TELMO |
238 | 249 |
gunner_dtor(shooter1); shooter1 = NULL; |
239 | 250 |
gunner_dtor(shooter2); shooter2 = NULL; |
240 |
bullet_dtor(bullet); bullet = NULL; |
|
251 |
|
|
252 |
while(list_size(bullet_list) > 0){ |
|
253 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
254 |
free(p); |
|
255 |
} |
|
256 |
if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
|
241 | 257 |
#endif |
242 | 258 |
|
243 | 259 |
basic_sprite_dtor (bsp_crosshair); bsp_crosshair = NULL; |
proj/src/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