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;
90 if (lev.time_initial > 0 && lev.time == 0)
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;
544 Cave[y][x] = Ykey_1_eat;
549 Cave[y][x] = Ykey_2_eat;
554 Cave[y][x] = Ykey_3_eat;
559 Cave[y][x] = Ykey_4_eat;
564 Cave[y][x] = Ykey_5_eat;
569 Cave[y][x] = Ykey_6_eat;
574 Cave[y][x] = Ykey_7_eat;
579 Cave[y][x] = Ykey_8_eat;
584 Next[y][x] = Zplayer;
585 play_element_sound(x, y, SAMPLE_collect, element);
586 lev.score += lev.key_score;
587 ply->anim = SPR_walk + anim;
593 Cave[y][x] = Ylenses_eat;
594 Next[y][x] = Zplayer;
595 play_element_sound(x, y, SAMPLE_collect, element);
596 lev.score += lev.lenses_score;
597 lev.lenses_cnt = lev.lenses_time;
598 ply->anim = SPR_walk + anim;
604 Cave[y][x] = Ymagnify_eat;
605 Next[y][x] = Zplayer;
606 play_element_sound(x, y, SAMPLE_collect, element);
607 lev.score += lev.magnify_score;
608 lev.magnify_cnt = lev.magnify_time;
609 ply->anim = SPR_walk + anim;
618 switch(Cave[y][x+dx])
628 if (Cave[y-1][x+dx+1] == Xblank)
629 Cave[y-1][x+dx+1] = Yacid_splash_eB;
630 if (Cave[y-1][x+dx-1] == Xblank)
631 Cave[y-1][x+dx-1] = Yacid_splash_wB;
632 play_sound(x, y, SAMPLE_acid);
636 case Yacid_splash_eB:
637 case Yacid_splash_wB:
638 Cave[y][x+dx] = dx > 0 ? Ystone_e : Ystone_w;
639 Next[y][x+dx] = Xstone_pause;
643 Cave[y][x] = dx > 0 ? Ystone_eB : Ystone_wB;
644 Next[y][x] = Zplayer;
645 play_element_sound(x, y, SAMPLE_roll, Xstone);
649 ply->anim = SPR_push + anim;
656 switch(Cave[y][x+dx])
666 if (Cave[y-1][x+dx+1] == Xblank)
667 Cave[y-1][x+dx+1] = Yacid_splash_eB;
668 if (Cave[y-1][x+dx-1] == Xblank)
669 Cave[y-1][x+dx-1] = Yacid_splash_wB;
670 play_sound(x, y, SAMPLE_acid);
674 case Yacid_splash_eB:
675 case Yacid_splash_wB:
676 Cave[y][x+dx] = dx > 0 ? Ybomb_e : Ybomb_w;
677 Next[y][x+dx] = Xbomb_pause;
681 Cave[y][x] = dx > 0 ? Ybomb_eB : Ybomb_wB;
682 Next[y][x] = Zplayer;
683 play_element_sound(x, y, SAMPLE_roll, Xbomb);
687 ply->anim = SPR_push + anim;
694 switch(Cave[y][x+dx])
704 if (Cave[y-1][x+dx+1] == Xblank)
705 Cave[y-1][x+dx+1] = Yacid_splash_eB;
706 if (Cave[y-1][x+dx-1] == Xblank)
707 Cave[y-1][x+dx-1] = Yacid_splash_wB;
708 play_sound(x, y, SAMPLE_acid);
712 case Yacid_splash_eB:
713 case Yacid_splash_wB:
714 Cave[y][x+dx] = dx > 0 ? Ynut_e : Ynut_w;
715 Next[y][x+dx] = Xnut_pause;
719 Cave[y][x] = dx > 0 ? Ynut_eB : Ynut_wB;
720 Next[y][x] = Zplayer;
721 play_element_sound(x, y, SAMPLE_roll, Xnut);
725 ply->anim = SPR_push + anim;
732 switch(Cave[y][x+dx])
736 Cave[y][x] = dx > 0 ? Yspring_kill_eB : Yspring_kill_wB;
737 Cave[y][x+dx] = dx > 0 ? Yspring_kill_e : Yspring_kill_w;
738 Next[y][x] = Zplayer;
739 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
740 play_element_sound(x, y, SAMPLE_slurp, Xalien);
741 lev.score += lev.slurp_score;
753 if (Cave[y-1][x+dx+1] == Xblank)
754 Cave[y-1][x+dx+1] = Yacid_splash_eB;
755 if (Cave[y-1][x+dx-1] == Xblank)
756 Cave[y-1][x+dx-1] = Yacid_splash_wB;
757 play_sound(x, y, SAMPLE_acid);
761 case Yacid_splash_eB:
762 case Yacid_splash_wB:
763 Cave[y][x+dx] = dx > 0 ? Yspring_e : Yspring_w;
764 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
767 Cave[y][x] = dx > 0 ? Yspring_eB : Yspring_wB;
768 Next[y][x] = Zplayer;
769 play_element_sound(x, y, SAMPLE_roll, Xspring);
773 ply->anim = SPR_push + anim;
780 case Xsand_stonein_1:
781 case Xsand_stonein_2:
782 case Xsand_stonein_3:
783 case Xsand_stonein_4:
787 ply->anim = SPR_push + anim;
791 switch(Cave[y+dy][x+dx])
801 if (Cave[y+dy-1][x+dx+1] == Xblank)
802 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
803 if (Cave[y+dy-1][x+dx-1] == Xblank)
804 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
805 play_sound(x, y, SAMPLE_acid);
809 case Yacid_splash_eB:
810 case Yacid_splash_wB:
811 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
812 (dx > 0 ? Yballoon_e : Yballoon_w));
813 Next[y+dy][x+dx] = Xballoon;
816 Cave[y][x] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
817 (dx > 0 ? Yballoon_eB : Yballoon_wB));
818 Next[y][x] = Zplayer;
819 play_element_sound(x, y, SAMPLE_push, Xballoon);
824 ply->anim = SPR_push + anim;
836 switch(Cave[y+dy][x+dx])
846 if (Cave[y+dy-1][x+dx+1] == Xblank)
847 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
848 if (Cave[y+dy-1][x+dx-1] == Xblank)
849 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
850 play_sound(x, y, SAMPLE_acid);
854 case Yacid_splash_eB:
855 case Yacid_splash_wB:
856 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
857 (dx > 0 ? Yandroid_e : Yandroid_w));
858 Next[y+dy][x+dx] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
859 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
862 Cave[y][x] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
863 (dx > 0 ? Yandroid_eB : Yandroid_wB));
864 Next[y][x] = Zplayer;
865 play_element_sound(x, y, SAMPLE_push, Xandroid);
870 ply->anim = SPR_push + anim;
875 if (ply->keys & 0x01)
882 if (ply->keys & 0x02)
889 if (ply->keys & 0x04)
896 if (ply->keys & 0x08)
903 if (ply->keys & 0x10)
910 if (ply->keys & 0x20)
917 if (ply->keys & 0x40)
924 if (ply->keys & 0x80)
930 if (!tab_blank[Cave[y+dy][x+dx]])
933 Cave[y+dy][x+dx] = Zplayer;
934 Next[y+dy][x+dx] = Zplayer;
935 play_element_sound(x, y, SAMPLE_door, element);
936 ply->anim = SPR_walk + anim;
942 play_element_sound(x, y, SAMPLE_press, element);
943 lev.wheel_cnt = lev.wheel_time;
949 lev.wind_direction = 0;
953 lev.wind_direction = 1;
957 lev.wind_direction = 2;
961 lev.wind_direction = 3;
965 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
969 play_element_sound(x, y, SAMPLE_press, element);
970 lev.wind_cnt = lev.wind_time;
974 play_element_sound(x, y, SAMPLE_press, element);
979 play_element_sound(x, y, SAMPLE_press, element);
980 lev.ball_cnt = lev.ball_time;
981 lev.ball_state = !lev.ball_state;
987 play_element_sound(x, y, SAMPLE_blank, Xplant);
988 ply->anim = SPR_walk + anim;
996 play_element_sound(x, y, SAMPLE_exit, Xexit_1);
998 if (--lev.home == 0 && lev.time_initial > 0) /* game won */
999 lev.score += lev.time * lev.exit_score / 100;
1001 ply->anim = SPR_walk + anim;
1010 int element = Cave[y][x];
1014 /* fire is pressed */
1017 Cave[y][x] = Ygrass_eat;
1018 Next[y][x] = Xblank;
1019 play_element_sound(x, y, SAMPLE_dirt, element);
1020 ply->anim = SPR_spray + anim;
1024 Cave[y][x] = Ydirt_eat;
1025 Next[y][x] = Xblank;
1026 play_element_sound(x, y, SAMPLE_dirt, element);
1027 ply->anim = SPR_spray + anim;
1031 case Xdiamond_pause:
1032 Cave[y][x] = Ydiamond_eat;
1033 Next[y][x] = Xblank;
1034 play_element_sound(x, y, SAMPLE_collect, element);
1035 lev.score += lev.diamond_score;
1036 lev.required = lev.required < 3 ? 0 : lev.required - 3;
1037 ply->anim = SPR_walk + anim;
1041 case Xemerald_pause:
1042 Cave[y][x] = Yemerald_eat;
1043 Next[y][x] = Xblank;
1044 play_element_sound(x, y, SAMPLE_collect, element);
1045 lev.score += lev.emerald_score;
1046 lev.required = lev.required < 1 ? 0 : lev.required - 1;
1047 ply->anim = SPR_walk + anim;
1051 Cave[y][x] = Ydynamite_eat;
1052 Next[y][x] = Xblank;
1053 play_element_sound(x, y, SAMPLE_collect, element);
1054 lev.score += lev.dynamite_score;
1055 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1056 ply->anim = SPR_walk + anim;
1061 Cave[y][x] = Ykey_1_eat;
1066 Cave[y][x] = Ykey_2_eat;
1071 Cave[y][x] = Ykey_3_eat;
1076 Cave[y][x] = Ykey_4_eat;
1081 Cave[y][x] = Ykey_5_eat;
1086 Cave[y][x] = Ykey_6_eat;
1091 Cave[y][x] = Ykey_7_eat;
1096 Cave[y][x] = Ykey_8_eat;
1100 Next[y][x] = Xblank;
1101 play_element_sound(x, y, SAMPLE_collect, element);
1102 lev.score += lev.key_score;
1103 ply->anim = SPR_walk + anim;
1107 Cave[y][x] = Ylenses_eat;
1108 Next[y][x] = Xblank;
1109 play_element_sound(x, y, SAMPLE_collect, element);
1110 lev.score += lev.lenses_score;
1111 lev.lenses_cnt = lev.lenses_time;
1112 ply->anim = SPR_walk + anim;
1116 Cave[y][x] = Ymagnify_eat;
1117 Next[y][x] = Xblank;
1118 play_element_sound(x, y, SAMPLE_collect, element);
1119 lev.score += lev.magnify_score;
1120 lev.magnify_cnt = lev.magnify_time;
1121 ply->anim = SPR_walk + anim;