1 /* first part of synchro.
3 * game logic for players.
5 * large switch statement for tiles the player interacts with.
14 static void player(struct PLAYER *);
15 static int test(struct PLAYER *);
16 static void die(struct PLAYER *);
20 /* must test for death and actually kill separately */
21 char ply1_kill = test(&ply1);
22 char ply2_kill = test(&ply2);
24 if (ply1.alive && ply1_kill)
26 if (ply2.alive && ply2_kill)
30 ply1.alive = 1; /* debugging */
35 ply1.anim = SPR_still;
38 ply2.anim = SPR_still;
42 if (ply1.alive) player(&ply1);
43 if (ply2.alive) player(&ply2);
47 if (ply2.alive) player(&ply2);
48 if (ply1.alive) player(&ply1);
53 if (Cave[ply1.oldy][ply1.oldx] == Zplayer)
55 Cave[ply1.oldy][ply1.oldx] = Xblank;
56 Next[ply1.oldy][ply1.oldx] = Xblank;
59 if (Cave[ply1.y][ply1.x] == Xblank)
61 Cave[ply1.y][ply1.x] = Zplayer;
62 Next[ply1.y][ply1.x] = Zplayer;
68 if (Cave[ply2.oldy][ply2.oldx] == Zplayer)
70 Cave[ply2.oldy][ply2.oldx] = Xblank;
71 Next[ply2.oldy][ply2.oldx] = Xblank;
74 if (Cave[ply2.y][ply2.x] == Xblank)
76 Cave[ply2.y][ply2.x] = Zplayer;
77 Next[ply2.y][ply2.x] = Zplayer;
82 static int test(struct PLAYER *ply)
84 register unsigned int x = ply->x;
85 register unsigned int y = ply->y;
180 case Yacid_splash_eB:
181 case Yacid_splash_wB:
193 static void die(struct PLAYER *ply)
195 register unsigned int x = ply->x;
196 register unsigned int y = ply->y;
210 Cave[y-1][x] = Xboom_bug;
212 play_element_sound(x, y, SAMPLE_boom, Zplayer);
224 Cave[y-1][x] = Xboom_bomb;
226 play_element_sound(x, y, SAMPLE_boom, Zplayer);
241 Cave[y][x+1] = Xboom_bug;
243 play_element_sound(x, y, SAMPLE_boom, Zplayer);
255 Cave[y][x+1] = Xboom_bomb;
257 play_element_sound(x, y, SAMPLE_boom, Zplayer);
272 Cave[y+1][x] = Xboom_bug;
274 play_element_sound(x, y, SAMPLE_boom, Zplayer);
286 Cave[y+1][x] = Xboom_bomb;
288 play_element_sound(x, y, SAMPLE_boom, Zplayer);
303 Cave[y][x-1] = Xboom_bug;
305 play_element_sound(x, y, SAMPLE_boom, Zplayer);
317 Cave[y][x-1] = Xboom_bomb;
319 play_element_sound(x, y, SAMPLE_boom, Zplayer);
329 play_element_sound(x, y, SAMPLE_exit, Xexit_1);
333 play_element_sound(x, y, SAMPLE_die, Zplayer);
337 Cave[y][x] = Xboom_1;
341 static void player(struct PLAYER *ply)
343 register unsigned int x = ply->x;
344 register unsigned int y = ply->y;
345 unsigned int anim = 0; /* initialized to make compilers happy */
348 if ((ply->joy_spin = !ply->joy_spin))
411 if (dx == 0 && dy == 0)
417 if (++ply->dynamite_cnt == 5 && ply->dynamite)
419 Cave[y][x] = Xdynamite_1;
420 play_element_sound(x, y, SAMPLE_dynamite, Xdynamite_1);
426 ply->dynamite_cnt = 0;
429 Random += 7; /* bit more random if we dont move */
435 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
436 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
438 if (ply->joy_fire == 0)
440 int element = Cave[y][x];
444 /* fire is released */
446 case Yacid_splash_eB:
447 case Yacid_splash_wB:
448 Cave[y][x] = Zplayer;
449 Next[y][x] = Zplayer;
450 play_element_sound(x, y, SAMPLE_blank, Xblank);
451 ply->anim = SPR_walk + anim;
482 ply->anim = SPR_walk + anim;
488 Cave[y][x] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
489 (dx > 0 ? Ygrass_eB : Ygrass_wB));
490 Next[y][x] = Zplayer;
491 play_element_sound(x, y, SAMPLE_dirt, Xgrass);
492 ply->anim = SPR_walk + anim;
498 Cave[y][x] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
499 (dx > 0 ? Ydirt_eB : Ydirt_wB));
500 Next[y][x] = Zplayer;
501 play_element_sound(x, y, SAMPLE_dirt, Xdirt);
502 ply->anim = SPR_walk + anim;
509 Cave[y][x] = Ydiamond_eat;
510 Next[y][x] = Zplayer;
511 play_element_sound(x, y, SAMPLE_collect, element);
512 lev.score += lev.diamond_score;
513 lev.required = lev.required < 3 ? 0 : lev.required - 3;
514 ply->anim = SPR_walk + anim;
521 Cave[y][x] = Yemerald_eat;
522 Next[y][x] = Zplayer;
523 play_element_sound(x, y, SAMPLE_collect, element);
524 lev.score += lev.emerald_score;
525 lev.required = lev.required < 1 ? 0 : lev.required - 1;
526 ply->anim = SPR_walk + anim;
532 Cave[y][x] = Ydynamite_eat;
533 Next[y][x] = Zplayer;
534 play_element_sound(x, y, SAMPLE_collect, element);
535 lev.score += lev.dynamite_score;
536 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
537 ply->anim = SPR_walk + anim;
576 Cave[y][x] = Yball_eat;
577 Next[y][x] = Zplayer;
578 play_element_sound(x, y, SAMPLE_collect, element);
579 lev.score += lev.key_score;
580 ply->anim = SPR_walk + anim;
586 Cave[y][x] = Yball_eat;
587 Next[y][x] = Zplayer;
588 play_element_sound(x, y, SAMPLE_collect, element);
589 lev.score += lev.lenses_score;
590 lev.lenses_cnt = lev.lenses_time;
591 ply->anim = SPR_walk + anim;
597 Cave[y][x] = Yball_eat;
598 Next[y][x] = Zplayer;
599 play_element_sound(x, y, SAMPLE_collect, element);
600 lev.score += lev.magnify_score;
601 lev.magnify_cnt = lev.magnify_time;
602 ply->anim = SPR_walk + anim;
611 switch(Cave[y][x+dx])
621 if (Cave[y-1][x+dx+1] == Xblank)
622 Cave[y-1][x+dx+1] = Yacid_splash_eB;
623 if (Cave[y-1][x+dx-1] == Xblank)
624 Cave[y-1][x+dx-1] = Yacid_splash_wB;
625 play_sound(x, y, SAMPLE_acid);
629 case Yacid_splash_eB:
630 case Yacid_splash_wB:
631 Cave[y][x+dx] = dx > 0 ? Ystone_e : Ystone_w;
632 Next[y][x+dx] = Xstone_pause;
636 Cave[y][x] = dx > 0 ? Ystone_eB : Ystone_wB;
637 Next[y][x] = Zplayer;
638 play_element_sound(x, y, SAMPLE_roll, Xstone);
642 ply->anim = SPR_push + anim;
649 switch(Cave[y][x+dx])
659 if (Cave[y-1][x+dx+1] == Xblank)
660 Cave[y-1][x+dx+1] = Yacid_splash_eB;
661 if (Cave[y-1][x+dx-1] == Xblank)
662 Cave[y-1][x+dx-1] = Yacid_splash_wB;
663 play_sound(x, y, SAMPLE_acid);
667 case Yacid_splash_eB:
668 case Yacid_splash_wB:
669 Cave[y][x+dx] = dx > 0 ? Ybomb_e : Ybomb_w;
670 Next[y][x+dx] = Xbomb_pause;
674 Cave[y][x] = dx > 0 ? Ybomb_eB : Ybomb_wB;
675 Next[y][x] = Zplayer;
676 play_element_sound(x, y, SAMPLE_roll, Xbomb);
680 ply->anim = SPR_push + anim;
687 switch(Cave[y][x+dx])
697 if (Cave[y-1][x+dx+1] == Xblank)
698 Cave[y-1][x+dx+1] = Yacid_splash_eB;
699 if (Cave[y-1][x+dx-1] == Xblank)
700 Cave[y-1][x+dx-1] = Yacid_splash_wB;
701 play_sound(x, y, SAMPLE_acid);
705 case Yacid_splash_eB:
706 case Yacid_splash_wB:
707 Cave[y][x+dx] = dx > 0 ? Ynut_e : Ynut_w;
708 Next[y][x+dx] = Xnut_pause;
712 Cave[y][x] = dx > 0 ? Ynut_eB : Ynut_wB;
713 Next[y][x] = Zplayer;
714 play_element_sound(x, y, SAMPLE_roll, Xnut);
718 ply->anim = SPR_push + anim;
725 switch(Cave[y][x+dx])
729 Cave[y][x] = dx > 0 ? Yspring_kill_eB : Yspring_kill_wB;
730 Cave[y][x+dx] = dx > 0 ? Yspring_kill_e : Yspring_kill_w;
731 Next[y][x] = Zplayer;
732 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
733 play_element_sound(x, y, SAMPLE_slurp, Xalien);
734 lev.score += lev.slurp_score;
746 if (Cave[y-1][x+dx+1] == Xblank)
747 Cave[y-1][x+dx+1] = Yacid_splash_eB;
748 if (Cave[y-1][x+dx-1] == Xblank)
749 Cave[y-1][x+dx-1] = Yacid_splash_wB;
750 play_sound(x, y, SAMPLE_acid);
754 case Yacid_splash_eB:
755 case Yacid_splash_wB:
756 Cave[y][x+dx] = dx > 0 ? Yspring_e : Yspring_w;
757 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
760 Cave[y][x] = dx > 0 ? Yspring_eB : Yspring_wB;
761 Next[y][x] = Zplayer;
762 play_element_sound(x, y, SAMPLE_roll, Xspring);
766 ply->anim = SPR_push + anim;
773 case Xsand_stonein_1:
774 case Xsand_stonein_2:
775 case Xsand_stonein_3:
776 case Xsand_stonein_4:
780 ply->anim = SPR_push + anim;
784 switch(Cave[y+dy][x+dx])
794 if (Cave[y+dy-1][x+dx+1] == Xblank)
795 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
796 if (Cave[y+dy-1][x+dx-1] == Xblank)
797 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
798 play_sound(x, y, SAMPLE_acid);
802 case Yacid_splash_eB:
803 case Yacid_splash_wB:
804 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
805 (dx > 0 ? Yballoon_e : Yballoon_w));
806 Next[y+dy][x+dx] = Xballoon;
809 Cave[y][x] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
810 (dx > 0 ? Yballoon_eB : Yballoon_wB));
811 Next[y][x] = Zplayer;
812 play_element_sound(x, y, SAMPLE_push, Xballoon);
817 ply->anim = SPR_push + anim;
829 switch(Cave[y+dy][x+dx])
839 if (Cave[y+dy-1][x+dx+1] == Xblank)
840 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
841 if (Cave[y+dy-1][x+dx-1] == Xblank)
842 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
843 play_sound(x, y, SAMPLE_acid);
847 case Yacid_splash_eB:
848 case Yacid_splash_wB:
849 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
850 (dx > 0 ? Yandroid_e : Yandroid_w));
851 Next[y+dy][x+dx] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
852 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
855 Cave[y][x] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
856 (dx > 0 ? Yandroid_eB : Yandroid_wB));
857 Next[y][x] = Zplayer;
858 play_element_sound(x, y, SAMPLE_push, Xandroid);
863 ply->anim = SPR_push + anim;
868 if (ply->keys & 0x01)
875 if (ply->keys & 0x02)
882 if (ply->keys & 0x04)
889 if (ply->keys & 0x08)
896 if (ply->keys & 0x10)
903 if (ply->keys & 0x20)
910 if (ply->keys & 0x40)
917 if (ply->keys & 0x80)
923 if (!tab_blank[Cave[y+dy][x+dx]])
926 Cave[y+dy][x+dx] = Zplayer;
927 Next[y+dy][x+dx] = Zplayer;
928 play_element_sound(x, y, SAMPLE_door, element);
929 ply->anim = SPR_walk + anim;
935 play_element_sound(x, y, SAMPLE_press, element);
936 lev.wheel_cnt = lev.wheel_time;
942 lev.wind_direction = 0;
946 lev.wind_direction = 1;
950 lev.wind_direction = 2;
954 lev.wind_direction = 3;
958 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
962 play_element_sound(x, y, SAMPLE_press, element);
963 lev.wind_cnt = lev.wind_time;
967 play_element_sound(x, y, SAMPLE_press, element);
972 play_element_sound(x, y, SAMPLE_press, element);
973 lev.ball_cnt = lev.ball_time;
974 lev.ball_state = !lev.ball_state;
980 play_element_sound(x, y, SAMPLE_blank, Xplant);
981 ply->anim = SPR_walk + anim;
989 play_element_sound(x, y, SAMPLE_exit, Xexit_1);
991 lev.score += lev.time * lev.exit_score / 100;
992 ply->anim = SPR_walk + anim;
1000 int element = Cave[y][x];
1004 /* fire is pressed */
1008 Cave[y][x] = Yball_eat;
1009 Next[y][x] = Xblank;
1010 play_element_sound(x, y, SAMPLE_dirt, element);
1011 ply->anim = SPR_spray + anim;
1015 case Xdiamond_pause:
1016 Cave[y][x] = Ydiamond_eat;
1017 Next[y][x] = Xblank;
1018 play_element_sound(x, y, SAMPLE_collect, element);
1019 lev.score += lev.diamond_score;
1020 lev.required = lev.required < 3 ? 0 : lev.required - 3;
1021 ply->anim = SPR_walk + anim;
1025 case Xemerald_pause:
1026 Cave[y][x] = Yemerald_eat;
1027 Next[y][x] = Xblank;
1028 play_element_sound(x, y, SAMPLE_collect, element);
1029 lev.score += lev.emerald_score;
1030 lev.required = lev.required < 1 ? 0 : lev.required - 1;
1031 ply->anim = SPR_walk + anim;
1035 Cave[y][x] = Ydynamite_eat;
1036 Next[y][x] = Xblank;
1037 play_element_sound(x, y, SAMPLE_collect, element);
1038 lev.score += lev.dynamite_score;
1039 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1040 ply->anim = SPR_walk + anim;
1076 Cave[y][x] = Yball_eat;
1077 Next[y][x] = Xblank;
1078 play_element_sound(x, y, SAMPLE_collect, element);
1079 lev.score += lev.key_score;
1080 ply->anim = SPR_walk + anim;
1084 Cave[y][x] = Yball_eat;
1085 Next[y][x] = Xblank;
1086 play_element_sound(x, y, SAMPLE_collect, element);
1087 lev.score += lev.lenses_score;
1088 lev.lenses_cnt = lev.lenses_time;
1089 ply->anim = SPR_walk + anim;
1093 Cave[y][x] = Yball_eat;
1094 Next[y][x] = Xblank;
1095 play_element_sound(x, y, SAMPLE_collect, element);
1096 lev.score += lev.magnify_score;
1097 lev.magnify_cnt = lev.magnify_time;
1098 ply->anim = SPR_walk + anim;