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 boolean player_digfield(struct PLAYER *, int, int);
16 static int test(struct PLAYER *);
17 static void die(struct PLAYER *);
21 /* must test for death and actually kill separately */
22 char ply1_kill = test(&ply1);
23 char ply2_kill = test(&ply2);
25 if (ply1.alive && ply1_kill)
27 if (ply2.alive && ply2_kill)
31 ply1.alive = 1; /* debugging */
36 ply1.anim = SPR_still;
39 ply2.anim = SPR_still;
43 if (ply1.alive) player(&ply1);
44 if (ply2.alive) player(&ply2);
48 if (ply2.alive) player(&ply2);
49 if (ply1.alive) player(&ply1);
54 if (Cave[ply1.oldy][ply1.oldx] == Zplayer)
56 Cave[ply1.oldy][ply1.oldx] = Xblank;
57 Next[ply1.oldy][ply1.oldx] = Xblank;
60 if (Cave[ply1.y][ply1.x] == Xblank)
62 Cave[ply1.y][ply1.x] = Zplayer;
63 Next[ply1.y][ply1.x] = Zplayer;
69 if (Cave[ply2.oldy][ply2.oldx] == Zplayer)
71 Cave[ply2.oldy][ply2.oldx] = Xblank;
72 Next[ply2.oldy][ply2.oldx] = Xblank;
75 if (Cave[ply2.y][ply2.x] == Xblank)
77 Cave[ply2.y][ply2.x] = Zplayer;
78 Next[ply2.y][ply2.x] = Zplayer;
83 static int test(struct PLAYER *ply)
85 register unsigned int x = ply->x;
86 register unsigned int y = ply->y;
91 if (lev.time_initial > 0 && lev.time == 0)
181 case Yacid_splash_eB:
182 case Yacid_splash_wB:
194 static void die(struct PLAYER *ply)
196 register unsigned int x = ply->x;
197 register unsigned int y = ply->y;
211 Cave[y-1][x] = Xboom_bug;
213 play_element_sound(x, y, SAMPLE_boom, Zplayer);
225 Cave[y-1][x] = Xboom_bomb;
227 play_element_sound(x, y, SAMPLE_boom, Zplayer);
242 Cave[y][x+1] = Xboom_bug;
244 play_element_sound(x, y, SAMPLE_boom, Zplayer);
256 Cave[y][x+1] = Xboom_bomb;
258 play_element_sound(x, y, SAMPLE_boom, Zplayer);
273 Cave[y+1][x] = Xboom_bug;
275 play_element_sound(x, y, SAMPLE_boom, Zplayer);
287 Cave[y+1][x] = Xboom_bomb;
289 play_element_sound(x, y, SAMPLE_boom, Zplayer);
304 Cave[y][x-1] = Xboom_bug;
306 play_element_sound(x, y, SAMPLE_boom, Zplayer);
318 Cave[y][x-1] = Xboom_bomb;
320 play_element_sound(x, y, SAMPLE_boom, Zplayer);
330 play_element_sound(x, y, SAMPLE_exit, Xexit_1);
334 play_element_sound(x, y, SAMPLE_die, Zplayer);
338 Cave[y][x] = Xboom_1;
342 static void player(struct PLAYER *ply)
344 unsigned int oldx = ply->x;
345 unsigned int oldy = ply->y;
346 register unsigned int x = oldx;
347 register unsigned int y = oldy;
348 unsigned int anim = 0;
352 printf("::: up == %d, down == %d, left == %d, right == %d, fire == %d [spin == %d, stick == %d]\n",
353 ply->joy_n, ply->joy_s, ply->joy_w, ply->joy_e, ply->joy_fire,
354 ply->joy_spin, ply->joy_stick);
358 if (ply->joy_w) /* west */
364 else if (ply->joy_e) /* east */
371 if (ply->joy_n) /* north */
377 else if (ply->joy_s) /* south */
386 if ((ply->joy_spin = !ply->joy_spin))
388 if (ply->joy_n) /* north */
394 else if (ply->joy_e) /* east */
400 else if (ply->joy_s) /* south */
406 else if (ply->joy_w) /* west */
415 if (ply->joy_w) /* west */
421 else if (ply->joy_s) /* south */
427 else if (ply->joy_e) /* east */
433 else if (ply->joy_n) /* north */
442 if (dx == 0 && dy == 0)
448 if (++ply->dynamite_cnt == 5 && ply->dynamite)
450 Cave[y][x] = Xdynamite_1;
451 play_element_sound(x, y, SAMPLE_dynamite, Xdynamite_1);
457 ply->dynamite_cnt = 0;
460 Random += 7; /* be a bit more random if the player doesn't move */
466 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
467 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
468 ply->joy_spin = !ply->joy_spin;
470 if (ply->joy_snap == 0) /* player wants to move */
472 boolean moved = FALSE;
474 if (ply->last_move_dir & MV_HORIZONTAL)
476 if (!(moved = player_digfield(ply, 0, dy)))
477 moved = player_digfield(ply, dx, 0);
481 if (!(moved = player_digfield(ply, dx, 0)))
482 moved = player_digfield(ply, 0, dy);
488 ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
489 else if (oldy != ply->y)
490 ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
493 else /* player wants to snap */
495 player_digfield(ply, dx, dy);
499 static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
501 int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
502 unsigned int oldx = ply->x;
503 unsigned int oldy = ply->y;
504 register unsigned int x = oldx + dx;
505 register unsigned int y = oldy + dy;
506 boolean result = TRUE;
508 if (!dx && !dy) /* no direction specified */
511 if (dx && dy && ply->joy_snap) /* more than one direction specified */
514 if (ply->joy_snap == 0) /* player wants to move */
516 int element = Cave[y][x];
520 /* fire is released */
522 case Yacid_splash_eB:
523 case Yacid_splash_wB:
524 Cave[y][x] = Zplayer;
525 Next[y][x] = Zplayer;
526 play_element_sound(x, y, SAMPLE_blank, Xblank);
527 ply->anim = SPR_walk + anim;
558 ply->anim = SPR_walk + anim;
564 Cave[y][x] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
565 (dx > 0 ? Ygrass_eB : Ygrass_wB));
566 Next[y][x] = Zplayer;
567 play_element_sound(x, y, SAMPLE_dirt, Xgrass);
568 ply->anim = SPR_walk + anim;
574 Cave[y][x] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
575 (dx > 0 ? Ydirt_eB : Ydirt_wB));
576 Next[y][x] = Zplayer;
577 play_element_sound(x, y, SAMPLE_dirt, Xdirt);
578 ply->anim = SPR_walk + anim;
585 Cave[y][x] = Ydiamond_eat;
586 Next[y][x] = Zplayer;
587 play_element_sound(x, y, SAMPLE_collect, element);
588 lev.score += lev.diamond_score;
589 lev.required = lev.required < 3 ? 0 : lev.required - 3;
590 ply->anim = SPR_walk + anim;
597 Cave[y][x] = Yemerald_eat;
598 Next[y][x] = Zplayer;
599 play_element_sound(x, y, SAMPLE_collect, element);
600 lev.score += lev.emerald_score;
601 lev.required = lev.required < 1 ? 0 : lev.required - 1;
602 ply->anim = SPR_walk + anim;
608 Cave[y][x] = Ydynamite_eat;
609 Next[y][x] = Zplayer;
610 play_element_sound(x, y, SAMPLE_collect, element);
611 lev.score += lev.dynamite_score;
612 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
613 ply->anim = SPR_walk + anim;
620 Cave[y][x] = Ykey_1_eat;
625 Cave[y][x] = Ykey_2_eat;
630 Cave[y][x] = Ykey_3_eat;
635 Cave[y][x] = Ykey_4_eat;
640 Cave[y][x] = Ykey_5_eat;
645 Cave[y][x] = Ykey_6_eat;
650 Cave[y][x] = Ykey_7_eat;
655 Cave[y][x] = Ykey_8_eat;
660 Next[y][x] = Zplayer;
661 play_element_sound(x, y, SAMPLE_collect, element);
662 lev.score += lev.key_score;
663 ply->anim = SPR_walk + anim;
669 Cave[y][x] = Ylenses_eat;
670 Next[y][x] = Zplayer;
671 play_element_sound(x, y, SAMPLE_collect, element);
672 lev.score += lev.lenses_score;
673 lev.lenses_cnt = lev.lenses_time;
674 ply->anim = SPR_walk + anim;
680 Cave[y][x] = Ymagnify_eat;
681 Next[y][x] = Zplayer;
682 play_element_sound(x, y, SAMPLE_collect, element);
683 lev.score += lev.magnify_score;
684 lev.magnify_cnt = lev.magnify_time;
685 ply->anim = SPR_walk + 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 ? Ystone_e : Ystone_w;
715 Next[y][x+dx] = Xstone_pause;
719 Cave[y][x] = dx > 0 ? Ystone_eB : Ystone_wB;
720 Next[y][x] = Zplayer;
721 play_element_sound(x, y, SAMPLE_roll, Xstone);
725 ply->anim = SPR_push + anim;
732 switch(Cave[y][x+dx])
742 if (Cave[y-1][x+dx+1] == Xblank)
743 Cave[y-1][x+dx+1] = Yacid_splash_eB;
744 if (Cave[y-1][x+dx-1] == Xblank)
745 Cave[y-1][x+dx-1] = Yacid_splash_wB;
746 play_sound(x, y, SAMPLE_acid);
750 case Yacid_splash_eB:
751 case Yacid_splash_wB:
752 Cave[y][x+dx] = dx > 0 ? Ybomb_e : Ybomb_w;
753 Next[y][x+dx] = Xbomb_pause;
757 Cave[y][x] = dx > 0 ? Ybomb_eB : Ybomb_wB;
758 Next[y][x] = Zplayer;
759 play_element_sound(x, y, SAMPLE_roll, Xbomb);
763 ply->anim = SPR_push + anim;
770 switch(Cave[y][x+dx])
780 if (Cave[y-1][x+dx+1] == Xblank)
781 Cave[y-1][x+dx+1] = Yacid_splash_eB;
782 if (Cave[y-1][x+dx-1] == Xblank)
783 Cave[y-1][x+dx-1] = Yacid_splash_wB;
784 play_sound(x, y, SAMPLE_acid);
788 case Yacid_splash_eB:
789 case Yacid_splash_wB:
790 Cave[y][x+dx] = dx > 0 ? Ynut_e : Ynut_w;
791 Next[y][x+dx] = Xnut_pause;
795 Cave[y][x] = dx > 0 ? Ynut_eB : Ynut_wB;
796 Next[y][x] = Zplayer;
797 play_element_sound(x, y, SAMPLE_roll, Xnut);
801 ply->anim = SPR_push + anim;
808 switch(Cave[y][x+dx])
812 Cave[y][x] = dx > 0 ? Yspring_kill_eB : Yspring_kill_wB;
813 Cave[y][x+dx] = dx > 0 ? Yspring_kill_e : Yspring_kill_w;
814 Next[y][x] = Zplayer;
815 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
816 play_element_sound(x, y, SAMPLE_slurp, Xalien);
817 lev.score += lev.slurp_score;
829 if (Cave[y-1][x+dx+1] == Xblank)
830 Cave[y-1][x+dx+1] = Yacid_splash_eB;
831 if (Cave[y-1][x+dx-1] == Xblank)
832 Cave[y-1][x+dx-1] = Yacid_splash_wB;
833 play_sound(x, y, SAMPLE_acid);
837 case Yacid_splash_eB:
838 case Yacid_splash_wB:
839 Cave[y][x+dx] = dx > 0 ? Yspring_e : Yspring_w;
840 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
843 Cave[y][x] = dx > 0 ? Yspring_eB : Yspring_wB;
844 Next[y][x] = Zplayer;
845 play_element_sound(x, y, SAMPLE_roll, Xspring);
849 ply->anim = SPR_push + anim;
856 case Xsand_stonein_1:
857 case Xsand_stonein_2:
858 case Xsand_stonein_3:
859 case Xsand_stonein_4:
863 ply->anim = SPR_push + anim;
867 switch(Cave[y+dy][x+dx])
877 if (Cave[y+dy-1][x+dx+1] == Xblank)
878 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
879 if (Cave[y+dy-1][x+dx-1] == Xblank)
880 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
881 play_sound(x, y, SAMPLE_acid);
885 case Yacid_splash_eB:
886 case Yacid_splash_wB:
887 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
888 (dx > 0 ? Yballoon_e : Yballoon_w));
889 Next[y+dy][x+dx] = Xballoon;
892 Cave[y][x] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
893 (dx > 0 ? Yballoon_eB : Yballoon_wB));
894 Next[y][x] = Zplayer;
895 play_element_sound(x, y, SAMPLE_push, Xballoon);
900 ply->anim = SPR_push + anim;
912 switch(Cave[y+dy][x+dx])
922 if (Cave[y+dy-1][x+dx+1] == Xblank)
923 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
924 if (Cave[y+dy-1][x+dx-1] == Xblank)
925 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
926 play_sound(x, y, SAMPLE_acid);
930 case Yacid_splash_eB:
931 case Yacid_splash_wB:
932 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
933 (dx > 0 ? Yandroid_e : Yandroid_w));
934 Next[y+dy][x+dx] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
935 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
938 Cave[y][x] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
939 (dx > 0 ? Yandroid_eB : Yandroid_wB));
940 Next[y][x] = Zplayer;
941 play_element_sound(x, y, SAMPLE_push, Xandroid);
946 ply->anim = SPR_push + anim;
951 if (ply->keys & 0x01)
958 if (ply->keys & 0x02)
965 if (ply->keys & 0x04)
972 if (ply->keys & 0x08)
979 if (ply->keys & 0x10)
986 if (ply->keys & 0x20)
993 if (ply->keys & 0x40)
1000 if (ply->keys & 0x80)
1006 if (!tab_blank[Cave[y+dy][x+dx]])
1009 Cave[y+dy][x+dx] = Zplayer;
1010 Next[y+dy][x+dx] = Zplayer;
1011 play_element_sound(x, y, SAMPLE_door, element);
1012 ply->anim = SPR_walk + anim;
1018 play_element_sound(x, y, SAMPLE_press, element);
1019 lev.wheel_cnt = lev.wheel_time;
1025 lev.wind_direction = 0;
1029 lev.wind_direction = 1;
1033 lev.wind_direction = 2;
1037 lev.wind_direction = 3;
1041 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
1045 play_element_sound(x, y, SAMPLE_press, element);
1046 lev.wind_cnt = lev.wind_time;
1050 play_element_sound(x, y, SAMPLE_press, element);
1055 play_element_sound(x, y, SAMPLE_press, element);
1056 lev.ball_cnt = lev.ball_time;
1057 lev.ball_state = !lev.ball_state;
1061 Cave[y][x] = Yplant;
1062 Next[y][x] = Xplant;
1063 play_element_sound(x, y, SAMPLE_blank, Xplant);
1064 ply->anim = SPR_walk + anim;
1072 play_element_sound(x, y, SAMPLE_exit, Xexit_1);
1074 if (--lev.home == 0 && lev.time_initial > 0) /* game won */
1075 lev.score += lev.time * lev.exit_score / 100;
1077 ply->anim = SPR_walk + anim;
1084 if (ply->x == oldx && ply->y == oldy) /* no movement */
1087 else /* player wants to snap */
1089 int element = Cave[y][x];
1093 /* fire is pressed */
1096 Cave[y][x] = Ygrass_eat;
1097 Next[y][x] = Xblank;
1098 play_element_sound(x, y, SAMPLE_dirt, element);
1099 ply->anim = SPR_spray + anim;
1103 Cave[y][x] = Ydirt_eat;
1104 Next[y][x] = Xblank;
1105 play_element_sound(x, y, SAMPLE_dirt, element);
1106 ply->anim = SPR_spray + anim;
1110 case Xdiamond_pause:
1111 Cave[y][x] = Ydiamond_eat;
1112 Next[y][x] = Xblank;
1113 play_element_sound(x, y, SAMPLE_collect, element);
1114 lev.score += lev.diamond_score;
1115 lev.required = lev.required < 3 ? 0 : lev.required - 3;
1116 ply->anim = SPR_walk + anim;
1120 case Xemerald_pause:
1121 Cave[y][x] = Yemerald_eat;
1122 Next[y][x] = Xblank;
1123 play_element_sound(x, y, SAMPLE_collect, element);
1124 lev.score += lev.emerald_score;
1125 lev.required = lev.required < 1 ? 0 : lev.required - 1;
1126 ply->anim = SPR_walk + anim;
1130 Cave[y][x] = Ydynamite_eat;
1131 Next[y][x] = Xblank;
1132 play_element_sound(x, y, SAMPLE_collect, element);
1133 lev.score += lev.dynamite_score;
1134 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1135 ply->anim = SPR_walk + anim;
1140 Cave[y][x] = Ykey_1_eat;
1145 Cave[y][x] = Ykey_2_eat;
1150 Cave[y][x] = Ykey_3_eat;
1155 Cave[y][x] = Ykey_4_eat;
1160 Cave[y][x] = Ykey_5_eat;
1165 Cave[y][x] = Ykey_6_eat;
1170 Cave[y][x] = Ykey_7_eat;
1175 Cave[y][x] = Ykey_8_eat;
1179 Next[y][x] = Xblank;
1180 play_element_sound(x, y, SAMPLE_collect, element);
1181 lev.score += lev.key_score;
1182 ply->anim = SPR_walk + anim;
1186 Cave[y][x] = Ylenses_eat;
1187 Next[y][x] = Xblank;
1188 play_element_sound(x, y, SAMPLE_collect, element);
1189 lev.score += lev.lenses_score;
1190 lev.lenses_cnt = lev.lenses_time;
1191 ply->anim = SPR_walk + anim;
1195 Cave[y][x] = Ymagnify_eat;
1196 Next[y][x] = Xblank;
1197 play_element_sound(x, y, SAMPLE_collect, element);
1198 lev.score += lev.magnify_score;
1199 lev.magnify_cnt = lev.magnify_time;
1200 ply->anim = SPR_walk + anim;