Revision 311
multiplayer initial
proj.c | ||
---|---|---|
60 | 60 |
sprite_t *sp_crosshair = NULL; |
61 | 61 |
|
62 | 62 |
static int (singleplayer)(void); |
63 |
//static int (multiplayer)(void);
|
|
63 |
static int (multiplayer)(void); |
|
64 | 64 |
static int (chat)(void); |
65 | 65 |
int(proj_main_loop)(int argc, char *argv[]) { |
66 | 66 |
|
... | ... | |
130 | 130 |
switch(menu_update_state(main_menu, click)){ |
131 | 131 |
case -1: break; |
132 | 132 |
case 0: singleplayer(); break; //campaign(); break; |
133 |
case 1: break; |
|
133 |
case 1: multiplayer() ; break;
|
|
134 | 134 |
case 2: chat(); break; |
135 | 135 |
case 3: good = false; break; |
136 | 136 |
} |
... | ... | |
184 | 184 |
return 0; |
185 | 185 |
} |
186 | 186 |
|
187 |
typedef struct __attribute__((packed)) { |
|
188 |
// player 1 |
|
189 |
double player1_x; |
|
190 |
double player1_y; |
|
191 |
double player1_health; |
|
192 |
double player1_current_health; |
|
187 |
host_info_t *host = NULL; |
|
188 |
remote_info_t *remote = NULL; |
|
193 | 189 |
|
194 |
// player 2 |
|
195 |
double player2_x; |
|
196 |
double player2_y; |
|
197 |
double player2_health; |
|
198 |
double player2_current_health; |
|
190 |
static void multiplayer_process(const uint8_t *p, const size_t sz) { |
|
191 |
void *dest = NULL; |
|
192 |
hltp_type tp = hltp_interpret(p, sz, &dest); |
|
193 |
switch(tp){ |
|
194 |
case hltp_type_host: |
|
195 |
host_info_dtor(host); |
|
196 |
host = (host_info_t*)dest; |
|
197 |
break; |
|
198 |
case hltp_type_remote: |
|
199 |
remote_info_dtor(remote); |
|
200 |
remote = (remote_info_t*)dest; |
|
201 |
break; |
|
202 |
default: break; |
|
203 |
} |
|
204 |
} |
|
205 |
static int (multiplayer_host)(void); |
|
206 |
static int (multiplayer_remote)(void); |
|
207 |
static int (multiplayer)(void) { |
|
208 |
int r; |
|
199 | 209 |
|
200 |
// bullets |
|
201 |
size_t no_bullets; |
|
202 |
double *bullets_x; |
|
203 |
double *bullets_y; |
|
204 |
double *bullets_vx; |
|
205 |
double *bullets_vy; |
|
206 |
bool *bullet_shooter; // 0 for player 1, otherwise 1 for player 2 |
|
207 |
} host_info; |
|
210 |
menu_t *main_menu = menu_ctor(consolas); |
|
211 |
menu_add_item(main_menu, "Create"); |
|
212 |
menu_add_item(main_menu, "Connect"); |
|
213 |
menu_add_item(main_menu, "Back"); |
|
208 | 214 |
|
209 |
typedef struct __attribute__((packed)) { |
|
210 |
keys_t client_keys_pressed; |
|
211 |
int32_t client_mouse_x; |
|
212 |
int32_t client_mouse_y; |
|
213 |
size_t bullets_shot; |
|
214 |
double *bullets_x; |
|
215 |
double *bullets_y; |
|
216 |
} client_info; |
|
217 |
/* |
|
218 |
static void host_to_client_process(const uint8_t *p, const size_t sz) { |
|
215 |
//uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
|
216 |
uint8_t last_lb = 0; |
|
217 |
struct packet pp; |
|
218 |
keys_t *keys = get_key_presses(); |
|
219 | 219 |
|
220 |
} |
|
220 |
/// loop stuff |
|
221 |
int click = 0; |
|
222 |
uint32_t int_vector = 0; |
|
223 |
int good = true; |
|
224 |
while (good) { |
|
225 |
/* Get a request message. */ |
|
226 |
if((r = get_interrupts_vector(&int_vector))) return r; |
|
227 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
|
228 |
if (int_vector & n) { |
|
229 |
interrupt_handler(i); |
|
230 |
switch (i) { |
|
231 |
case TIMER0_IRQ: |
|
221 | 232 |
|
222 |
static void client_to_host_process(const uint8_t *p, const size_t sz) { |
|
233 |
graph_clear_screen(); |
|
234 |
switch(menu_update_state(main_menu, click)){ |
|
235 |
case -1: break; |
|
236 |
case 0: multiplayer_host(); break; |
|
237 |
case 1: multiplayer_remote(); break; |
|
238 |
case 2: good = false; break; |
|
239 |
} |
|
240 |
menu_draw(main_menu); |
|
241 |
|
|
242 |
click = 0; |
|
243 |
|
|
244 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
|
245 |
sprite_draw(sp_crosshair); |
|
246 |
graph_draw(); |
|
247 |
|
|
248 |
break; |
|
249 |
case KBC_IRQ: |
|
250 |
if ((scancode[0]) == ESC_BREAK_CODE) good = false; |
|
251 |
case MOUSE_IRQ: |
|
252 |
if (counter_mouse_ih >= 3) { |
|
253 |
mouse_parse_packet(packet_mouse_ih, &pp); |
|
254 |
update_mouse(&pp); |
|
255 |
if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed; |
|
256 |
last_lb = keys->lb_pressed; |
|
257 |
counter_mouse_ih = 0; |
|
258 |
} |
|
259 |
break; |
|
260 |
case COM1_IRQ: nctp_ih(); break; |
|
261 |
} |
|
262 |
} |
|
263 |
} |
|
264 |
} |
|
265 |
return 0; |
|
223 | 266 |
} |
224 | 267 |
|
225 |
static int (multiplayer)(void) { |
|
226 |
|
|
268 |
static int (multiplayer_host)(void) { |
|
227 | 269 |
//int r; |
228 | 270 |
|
271 |
nctp_dump(); |
|
272 |
nctp_set_processor(multiplayer_process);/* |
|
273 |
|
|
229 | 274 |
ent_set_scale(DEFAULT_SCALE); |
230 |
//text_timer_t *in_game_timer = timer_ctor(consolas);
|
|
275 |
text_timer_t *in_game_timer = timer_ctor(consolas); |
|
231 | 276 |
|
232 | 277 |
list_t *shooter_list = list_ctor(); |
233 | 278 |
|
... | ... | |
258 | 303 |
/// loop stuff |
259 | 304 |
uint32_t int_vector = 0; |
260 | 305 |
int good = true; |
306 |
int state = 0; // -1 for remote win, 0 for draw, 1 for host win |
|
307 |
while (good) { |
|
308 |
if ((r = get_interrupts_vector(&int_vector))) return r; |
|
309 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
|
310 |
interrupt_handler(i); |
|
311 |
switch (i) { |
|
312 |
case TIMER0_IRQ: |
|
261 | 313 |
|
262 |
// incomplete
|
|
314 |
break;
|
|
263 | 315 |
|
316 |
case KBC_IRQ: |
|
317 |
|
|
318 |
break; |
|
319 |
|
|
320 |
case MOUSE_IRQ: |
|
321 |
|
|
322 |
|
|
323 |
break; |
|
324 |
|
|
325 |
case COM1_IRQ: nctp_ih(); break; |
|
326 |
} |
|
327 |
} |
|
328 |
}*/ |
|
329 |
|
|
264 | 330 |
return 0; |
265 |
}*/ |
|
331 |
} |
|
332 |
static int (multiplayer_remote)(void) {/* |
|
333 |
int r; |
|
266 | 334 |
|
335 |
nctp_dump(); |
|
336 |
nctp_set_processor(multiplayer_process); |
|
337 |
|
|
338 |
ent_set_scale(DEFAULT_SCALE); |
|
339 |
text_timer_t *in_game_timer = timer_ctor(consolas); |
|
340 |
|
|
341 |
list_t *shooter_list = list_ctor(); |
|
342 |
|
|
343 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
|
344 |
gunner_set_spawn(shooter1, 75, 75); |
|
345 |
|
|
346 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter2 == NULL) printf("Failed to get shooter2\n"); |
|
347 |
gunner_set_spawn(shooter2, 975, 75); |
|
348 |
|
|
349 |
list_insert(shooter_list, list_end(shooter_list), shooter1); |
|
350 |
list_insert(shooter_list, list_end(shooter_list), shooter2); |
|
351 |
|
|
352 |
do { |
|
353 |
get_random_spawn(map1, shooter1, shooter_list); |
|
354 |
get_random_spawn(map1, shooter2, shooter_list); |
|
355 |
} while (distance_gunners(shooter1, shooter2) < 700); |
|
356 |
|
|
357 |
list_t *bullet_list = list_ctor(); |
|
358 |
|
|
359 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
360 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
361 |
|
|
362 |
//uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
|
363 |
uint8_t last_lb = 0; |
|
364 |
struct packet pp; |
|
365 |
keys_t *keys = get_key_presses(); |
|
366 |
|
|
367 |
/// loop stuff |
|
368 |
uint32_t int_vector = 0; |
|
369 |
int good = true; |
|
370 |
int state = 0; // -1 for remote win, 0 for draw, 1 for host win |
|
371 |
while (good) { |
|
372 |
if ((r = get_interrupts_vector(&int_vector))) return r; |
|
373 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
|
374 |
interrupt_handler(i); |
|
375 |
switch (i) { |
|
376 |
case TIMER0_IRQ: |
|
377 |
|
|
378 |
break; |
|
379 |
|
|
380 |
case KBC_IRQ: |
|
381 |
|
|
382 |
break; |
|
383 |
|
|
384 |
case MOUSE_IRQ: |
|
385 |
|
|
386 |
|
|
387 |
break; |
|
388 |
|
|
389 |
case COM1_IRQ: nctp_ih(); break; |
|
390 |
} |
|
391 |
} |
|
392 |
}*/ |
|
393 |
|
|
394 |
return 0; |
|
395 |
} |
|
396 |
|
|
267 | 397 |
static int (campaign)(void); |
268 | 398 |
static int (zombies)(void); |
269 | 399 |
static int (singleplayer)(void) { |
... | ... | |
649 | 779 |
rectangle_set_outline_width(r_text, 2); |
650 | 780 |
rectangle_set_outline_color(r_text, GRAPH_WHITE); |
651 | 781 |
rectangle_set_fill_trans(r_text, GRAPH_TRANSPARENT); |
782 |
} |
|
783 |
/** t_text */ { |
|
784 |
for(size_t i = 0; i < CHAT_MAX_NUM; ++i){ |
|
785 |
t_text[i] = text_ctor(consolas, " "); |
|
786 |
text_set_pos(t_text[i], rectangle_get_x(r_text)+50, |
|
787 |
rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i); |
|
788 |
text_set_halign(t_text[i], text_halign_left); |
|
789 |
text_set_valign(t_text[i], text_valign_bottom); |
|
790 |
text_set_color (t_text[i], TEXT_COLOR); |
|
791 |
} |
|
652 | 792 |
} |
653 |
/** t_text */ { |
|
654 |
for(size_t i = 0; i < CHAT_MAX_NUM; ++i){ |
|
655 |
t_text[i] = text_ctor(consolas, " "); |
|
656 |
text_set_pos(t_text[i], rectangle_get_x(r_text)+50, |
|
657 |
rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i); |
|
658 |
text_set_halign(t_text[i], text_halign_left); |
|
659 |
text_set_valign(t_text[i], text_valign_bottom); |
|
660 |
text_set_color (t_text[i], TEXT_COLOR); |
|
661 |
} |
|
662 |
} |
|
663 | 793 |
|
664 | 794 |
/// loop stuff |
665 | 795 |
uint32_t int_vector = 0; |
Also available in: Unified diff