1 /* first part of synchro.
3 * game logic for players.
5 * large switch statement for tiles the player interacts with.
13 #if defined(TARGET_X11)
15 static void player(struct PLAYER *);
16 static int test(struct PLAYER *);
17 static void die(struct PLAYER *);
21 char ply1_kill = test(&ply1); /* must test for death and actually kill separately */
22 char ply2_kill = test(&ply2);
23 if(ply1.alive && ply1_kill) die(&ply1);
24 if(ply2.alive && ply2_kill) die(&ply2);
27 ply1.alive = 1; /* debugging */
32 ply1.anim = SPR_still;
35 ply2.anim = SPR_still;
38 if(ply1.alive) player(&ply1);
39 if(ply2.alive) player(&ply2);
41 if(ply2.alive) player(&ply2);
42 if(ply1.alive) player(&ply1);
45 if(Cave[ply1.oldy][ply1.oldx] == Zplayer) {
46 Cave[ply1.oldy][ply1.oldx] = Xblank;
47 Next[ply1.oldy][ply1.oldx] = Xblank;
49 if(Cave[ply1.y][ply1.x] == Xblank) {
50 Cave[ply1.y][ply1.x] = Zplayer;
51 Next[ply1.y][ply1.x] = Zplayer;
55 if(Cave[ply2.oldy][ply2.oldx] == Zplayer) {
56 Cave[ply2.oldy][ply2.oldx] = Xblank;
57 Next[ply2.oldy][ply2.oldx] = Xblank;
59 if(Cave[ply2.y][ply2.x] == Xblank) {
60 Cave[ply2.y][ply2.x] = Zplayer;
61 Next[ply2.y][ply2.x] = Zplayer;
66 static int test(struct PLAYER *ply)
68 register unsigned int x = ply->x;
69 register unsigned int y = ply->y;
71 if(lev.time == 0) return(1);
73 switch(Cave[y-1][x]) {
92 switch(Cave[y][x+1]) {
111 switch(Cave[y+1][x]) {
130 switch(Cave[y][x-1]) {
151 case Yacid_splash_eB:
152 case Yacid_splash_wB:
163 static void die(struct PLAYER *ply)
165 register unsigned int x = ply->x;
166 register unsigned int y = ply->y;
170 switch(Cave[y-1][x]) {
179 Cave[y-1][x] = Xboom_bug; break;
188 Cave[y-1][x] = Xboom_bomb; break;
190 switch(Cave[y][x+1]) {
199 Cave[y][x+1] = Xboom_bug; break;
208 Cave[y][x+1] = Xboom_bomb; break;
210 switch(Cave[y+1][x]) {
219 Cave[y+1][x] = Xboom_bug; break;
228 Cave[y+1][x] = Xboom_bomb; break;
230 switch(Cave[y][x-1]) {
239 Cave[y][x-1] = Xboom_bug; break;
248 Cave[y][x-1] = Xboom_bomb; break;
254 play[SAMPLE_exit] = 1; break;
256 play[SAMPLE_die] = 1; break;
258 Cave[y][x] = Xboom_1;
262 static void player(struct PLAYER *ply)
264 register unsigned int x = ply->x;
265 register unsigned int y = ply->y;
266 unsigned int anim = 0; /* initialized to make compilers happy */
269 if((ply->joy_spin = !ply->joy_spin)) {
271 y--; dy = -1; anim = 0; /* north */
272 } else if(ply->joy_e) {
273 x++; dx = 1; anim = 1; /* east */
274 } else if(ply->joy_s) {
275 y++; dy = 1; anim = 2; /* south */
276 } else if(ply->joy_w) {
277 x--; dx = -1; anim = 3; /* west */
281 x--; dx = -1; anim = 3; /* west */
282 } else if(ply->joy_s) {
283 y++; dy = 1; anim = 2; /* south */
284 } else if(ply->joy_e) {
285 x++; dx = 1; anim = 1; /* east */
286 } else if(ply->joy_n) {
287 y--; dy = -1; anim = 0; /* north */
290 if(dx == 0 && dy == 0) {
293 if(++ply->dynamite_cnt == 5 && ply->dynamite) {
294 Cave[y][x] = Xdynamite_1;
295 play[SAMPLE_dynamite] = 1;
299 ply->dynamite_cnt = 0;
301 Random += 7; /* bit more random if we dont move */
305 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
306 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
308 if(ply->joy_fire == 0) {
309 switch(Cave[y][x]) { /* fire is released */
311 case Yacid_splash_eB:
312 case Yacid_splash_wB:
313 Cave[y][x] = Zplayer;
314 Next[y][x] = Zplayer;
315 play[SAMPLE_blank] = 1;
316 ply->anim = SPR_walk + anim;
346 ply->anim = SPR_walk + anim;
351 Cave[y][x] = dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) : (dx > 0 ? Ygrass_eB : Ygrass_wB);
352 Next[y][x] = Zplayer;
353 play[SAMPLE_dirt] = 1;
354 ply->anim = SPR_walk + anim;
359 Cave[y][x] = dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) : (dx > 0 ? Ydirt_eB : Ydirt_wB);
360 Next[y][x] = Zplayer;
361 play[SAMPLE_dirt] = 1;
362 ply->anim = SPR_walk + anim;
368 Cave[y][x] = Ydiamond_eat;
369 Next[y][x] = Zplayer;
370 play[SAMPLE_collect] = 1;
371 lev.score += lev.diamond_score;
372 lev.required = lev.required < 3 ? 0 : lev.required - 3;
373 ply->anim = SPR_walk + anim;
379 Cave[y][x] = Yemerald_eat;
380 Next[y][x] = Zplayer;
381 play[SAMPLE_collect] = 1;
382 lev.score += lev.emerald_score;
383 lev.required = lev.required < 1 ? 0 : lev.required - 1;
384 ply->anim = SPR_walk + anim;
389 Cave[y][x] = Ydynamite_eat;
390 Next[y][x] = Zplayer;
391 play[SAMPLE_collect] = 1;
392 lev.score += lev.dynamite_score;
393 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
394 ply->anim = SPR_walk + anim;
399 ply->keys |= 0x01; goto key_walk;
401 ply->keys |= 0x02; goto key_walk;
403 ply->keys |= 0x04; goto key_walk;
405 ply->keys |= 0x08; goto key_walk;
407 ply->keys |= 0x10; goto key_walk;
409 ply->keys |= 0x20; goto key_walk;
411 ply->keys |= 0x40; goto key_walk;
413 ply->keys |= 0x80; goto key_walk;
415 Cave[y][x] = Yball_eat;
416 Next[y][x] = Zplayer;
417 play[SAMPLE_collect] = 1;
418 lev.score += lev.key_score;
419 ply->anim = SPR_walk + anim;
424 Cave[y][x] = Yball_eat;
425 Next[y][x] = Zplayer;
426 play[SAMPLE_collect] = 1;
427 lev.score += lev.lenses_score;
428 lev.lenses_cnt = lev.lenses_time;
429 ply->anim = SPR_walk + anim;
434 Cave[y][x] = Yball_eat;
435 Next[y][x] = Zplayer;
436 play[SAMPLE_collect] = 1;
437 lev.score += lev.magnify_score;
438 lev.magnify_cnt = lev.magnify_time;
439 ply->anim = SPR_walk + anim;
445 switch(Cave[y][x+dx]) {
454 if(Cave[y-1][x+dx+1] == Xblank) Cave[y-1][x+dx+1] = Yacid_splash_eB;
455 if(Cave[y-1][x+dx-1] == Xblank) Cave[y-1][x+dx-1] = Yacid_splash_wB;
456 play[SAMPLE_acid] = 1;
459 case Yacid_splash_eB:
460 case Yacid_splash_wB:
461 Cave[y][x+dx] = dx > 0 ? Ystone_e : Ystone_w;
462 Next[y][x+dx] = Xstone_pause;
464 Cave[y][x] = dx > 0 ? Ystone_eB : Ystone_wB;
465 Next[y][x] = Zplayer;
466 play[SAMPLE_roll] = 1;
469 ply->anim = SPR_push + anim;
473 switch(Cave[y][x+dx]) {
482 if(Cave[y-1][x+dx+1] == Xblank) Cave[y-1][x+dx+1] = Yacid_splash_eB;
483 if(Cave[y-1][x+dx-1] == Xblank) Cave[y-1][x+dx-1] = Yacid_splash_wB;
484 play[SAMPLE_acid] = 1;
487 case Yacid_splash_eB:
488 case Yacid_splash_wB:
489 Cave[y][x+dx] = dx > 0 ? Ybomb_e : Ybomb_w;
490 Next[y][x+dx] = Xbomb_pause;
492 Cave[y][x] = dx > 0 ? Ybomb_eB : Ybomb_wB;
493 Next[y][x] = Zplayer;
494 play[SAMPLE_roll] = 1;
497 ply->anim = SPR_push + anim;
501 switch(Cave[y][x+dx]) {
510 if(Cave[y-1][x+dx+1] == Xblank) Cave[y-1][x+dx+1] = Yacid_splash_eB;
511 if(Cave[y-1][x+dx-1] == Xblank) Cave[y-1][x+dx-1] = Yacid_splash_wB;
512 play[SAMPLE_acid] = 1;
515 case Yacid_splash_eB:
516 case Yacid_splash_wB:
517 Cave[y][x+dx] = dx > 0 ? Ynut_e : Ynut_w;
518 Next[y][x+dx] = Xnut_pause;
520 Cave[y][x] = dx > 0 ? Ynut_eB : Ynut_wB;
521 Next[y][x] = Zplayer;
522 play[SAMPLE_roll] = 1;
525 ply->anim = SPR_push + anim;
529 switch(Cave[y][x+dx]) {
532 Cave[y][x] = dx > 0 ? Yspring_kill_eB : Yspring_kill_wB;
533 Cave[y][x+dx] = dx > 0 ? Yspring_kill_e : Yspring_kill_w;
534 Next[y][x] = Zplayer;
535 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
536 play[SAMPLE_slurp] = 1;
537 lev.score += lev.slurp_score;
548 if(Cave[y-1][x+dx+1] == Xblank) Cave[y-1][x+dx+1] = Yacid_splash_eB;
549 if(Cave[y-1][x+dx-1] == Xblank) Cave[y-1][x+dx-1] = Yacid_splash_wB;
550 play[SAMPLE_acid] = 1;
553 case Yacid_splash_eB:
554 case Yacid_splash_wB:
555 Cave[y][x+dx] = dx > 0 ? Yspring_e : Yspring_w;
556 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
558 Cave[y][x] = dx > 0 ? Yspring_eB : Yspring_wB;
559 Next[y][x] = Zplayer;
560 play[SAMPLE_roll] = 1;
563 ply->anim = SPR_push + anim;
569 case Xsand_stonein_1:
570 case Xsand_stonein_2:
571 case Xsand_stonein_3:
572 case Xsand_stonein_4:
574 ply->anim = SPR_push + anim;
577 switch(Cave[y+dy][x+dx]) {
586 if(Cave[y+dy-1][x+dx+1] == Xblank) Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
587 if(Cave[y+dy-1][x+dx-1] == Xblank) Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
588 play[SAMPLE_acid] = 1;
591 case Yacid_splash_eB:
592 case Yacid_splash_wB:
593 Cave[y+dy][x+dx] = dy ? (dy < 0 ? Yballoon_n : Yballoon_s) : (dx > 0 ? Yballoon_e : Yballoon_w);
594 Next[y+dy][x+dx] = Xballoon;
596 Cave[y][x] = dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) : (dx > 0 ? Yballoon_eB : Yballoon_wB);
597 Next[y][x] = Zplayer;
598 play[SAMPLE_push] = 1;
602 ply->anim = SPR_push + anim;
613 switch(Cave[y+dy][x+dx]) {
622 if(Cave[y+dy-1][x+dx+1] == Xblank) Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
623 if(Cave[y+dy-1][x+dx-1] == Xblank) Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
624 play[SAMPLE_acid] = 1;
627 case Yacid_splash_eB:
628 case Yacid_splash_wB:
629 Cave[y+dy][x+dx] = dy ? (dy < 0 ? Yandroid_n : Yandroid_s) : (dx > 0 ? Yandroid_e : Yandroid_w);
630 Next[y+dy][x+dx] = dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) : (dx > 0 ? Xandroid_2_e : Xandroid_2_w);
632 Cave[y][x] = dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) : (dx > 0 ? Yandroid_eB : Yandroid_wB);
633 Next[y][x] = Zplayer;
634 play[SAMPLE_push] = 1;
638 ply->anim = SPR_push + anim;
642 if(ply->keys & 0x01) goto door_walk; else break;
645 if(ply->keys & 0x02) goto door_walk; else break;
648 if(ply->keys & 0x04) goto door_walk; else break;
651 if(ply->keys & 0x08) goto door_walk; else break;
654 if(ply->keys & 0x10) goto door_walk; else break;
657 if(ply->keys & 0x20) goto door_walk; else break;
660 if(ply->keys & 0x40) goto door_walk; else break;
663 if(ply->keys & 0x80) goto door_walk; else break;
665 if(!tab_blank[Cave[y+dy][x+dx]]) break;
666 Cave[y+dy][x+dx] = Zplayer;
667 Next[y+dy][x+dx] = Zplayer;
668 play[SAMPLE_door] = 1;
669 ply->anim = SPR_walk + anim;
674 play[SAMPLE_press] = 1;
675 lev.wheel_cnt = lev.wheel_time;
680 lev.wind_direction = 0; goto wind_walk;
682 lev.wind_direction = 1; goto wind_walk;
684 lev.wind_direction = 2; goto wind_walk;
686 lev.wind_direction = 3; goto wind_walk;
688 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3); goto wind_walk;
690 play[SAMPLE_press] = 1;
691 lev.wind_cnt = lev.wind_time;
694 play[SAMPLE_press] = 1;
698 play[SAMPLE_press] = 1;
699 lev.ball_cnt = lev.ball_time;
700 lev.ball_state = !lev.ball_state;
705 play[SAMPLE_blank] = 1;
706 ply->anim = SPR_walk + anim;
713 play[SAMPLE_exit] = 1;
714 if(--lev.home == 0) lev.score += lev.time * lev.exit_score / 100;
715 ply->anim = SPR_walk + anim;
721 switch(Cave[y][x]) { /* fire is pressed */
724 Cave[y][x] = Yball_eat;
726 play[SAMPLE_dirt] = 1;
727 ply->anim = SPR_spray + anim;
731 Cave[y][x] = Ydiamond_eat;
733 play[SAMPLE_collect] = 1;
734 lev.score += lev.diamond_score;
735 lev.required = lev.required < 3 ? 0 : lev.required - 3;
736 ply->anim = SPR_walk + anim;
740 Cave[y][x] = Yemerald_eat;
742 play[SAMPLE_collect] = 1;
743 lev.score += lev.emerald_score;
744 lev.required = lev.required < 1 ? 0 : lev.required - 1;
745 ply->anim = SPR_walk + anim;
748 Cave[y][x] = Ydynamite_eat;
750 play[SAMPLE_collect] = 1;
751 lev.score += lev.dynamite_score;
752 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
753 ply->anim = SPR_walk + anim;
756 ply->keys |= 0x01; goto key_shoot;
758 ply->keys |= 0x02; goto key_shoot;
760 ply->keys |= 0x04; goto key_shoot;
762 ply->keys |= 0x08; goto key_shoot;
764 ply->keys |= 0x10; goto key_shoot;
766 ply->keys |= 0x20; goto key_shoot;
768 ply->keys |= 0x40; goto key_shoot;
770 ply->keys |= 0x80; goto key_shoot;
772 Cave[y][x] = Yball_eat;
774 play[SAMPLE_collect] = 1;
775 lev.score += lev.key_score;
776 ply->anim = SPR_walk + anim;
779 Cave[y][x] = Yball_eat;
781 play[SAMPLE_collect] = 1;
782 lev.score += lev.lenses_score;
783 lev.lenses_cnt = lev.lenses_time;
784 ply->anim = SPR_walk + anim;
787 Cave[y][x] = Yball_eat;
789 play[SAMPLE_collect] = 1;
790 lev.score += lev.magnify_score;
791 lev.magnify_cnt = lev.magnify_time;
792 ply->anim = SPR_walk + anim;