1 /* first part of synchro.
3 * game logic for players.
5 * large switch statement for tiles the player interacts with.
11 #define USE_CHANGED_ACID_STUFF 1
13 extern boolean checkIfAllPlayersFitToScreen();
15 static void check_player(struct PLAYER *);
16 static void kill_player(struct PLAYER *);
17 static boolean player_digfield(struct PLAYER *, int, int);
18 static boolean player_killed(struct PLAYER *);
25 game_em.any_player_moving = FALSE;
26 game_em.any_player_snapping = FALSE;
28 /* must test for death and actually kill separately */
29 for (i = 0; i < MAX_PLAYERS; i++)
31 boolean ply_kill = player_killed(&ply[i]);
33 if (ply[i].alive && ply_kill)
37 for (i = 0; i < MAX_PLAYERS; i++)
39 ply[i].oldx = ply[i].x;
40 ply[i].oldy = ply[i].y;
41 ply[i].anim = SPR_still;
44 start_check_nr = (RandomEM & 128 ? 0 : 1) * 2 + (RandomEM & 256 ? 0 : 1);
46 for (i = 0; i < MAX_PLAYERS; i++)
48 int check_nr = (start_check_nr + i) % MAX_PLAYERS;
50 if (ply[check_nr].alive)
51 check_player(&ply[check_nr]);
54 for (i = 0; i < MAX_PLAYERS; i++)
59 if (Cave[ply[i].oldy][ply[i].oldx] == Zplayer)
61 Cave[ply[i].oldy][ply[i].oldx] = Xblank;
62 Next[ply[i].oldy][ply[i].oldx] = Xblank;
65 if (Cave[ply[i].y][ply[i].x] == Xblank)
67 Cave[ply[i].y][ply[i].x] = Zplayer;
68 Next[ply[i].y][ply[i].x] = Zplayer;
73 static boolean player_killed(struct PLAYER *ply)
81 if (lev.killed_out_of_time && setup.time_limit)
171 case Yacid_splash_eB:
172 case Yacid_splash_wB:
194 static void kill_player(struct PLAYER *ply)
211 Cave[y-1][x] = Xboom_bug;
222 Cave[y-1][x] = Xboom_bomb;
236 Cave[y][x+1] = Xboom_bug;
247 Cave[y][x+1] = Xboom_bomb;
261 Cave[y+1][x] = Xboom_bug;
272 Cave[y+1][x] = Xboom_bomb;
286 Cave[y][x-1] = Xboom_bug;
297 Cave[y][x-1] = Xboom_bomb;
308 play_element_sound(x, y, SAMPLE_exit_leave, Xexit_1);
312 play_element_sound(x, y, SAMPLE_die, Zplayer);
318 #if USE_CHANGED_ACID_STUFF
331 Cave[y][x] = Xboom_1;
337 static void check_player(struct PLAYER *ply)
345 game_em.last_player_direction[ply->num] = MV_NONE;
347 if (ply->joy_w) /* west */
352 else if (ply->joy_e) /* east */
358 if (ply->joy_n) /* north */
363 else if (ply->joy_s) /* south */
375 boolean players_visible_before_move;
376 boolean players_visible_after_move;
379 players_visible_before_move = checkIfAllPlayersFitToScreen();
384 players_visible_after_move = checkIfAllPlayersFitToScreen();
387 player is allowed to move only in the following cases:
388 - it is not needed to display all players (not focussed to all players)
389 - all players are (still or again) visible after the move
390 - some players were already outside visible screen area before the move
392 can_move = (game.centered_player_nr != -1 ||
393 players_visible_after_move ||
394 !players_visible_before_move);
401 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
407 if (dx == 0 && dy == 0)
413 if (++ply->dynamite_cnt == 5 && ply->dynamite)
415 Cave[y][x] = Xdynamite_1;
416 play_element_sound(x, y, SAMPLE_dynamite, Xdynamite_1);
422 ply->dynamite_cnt = 0;
425 RandomEM += 7; /* be a bit more random if the player doesn't move */
431 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
432 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
433 ply->joy_spin = !ply->joy_spin;
435 if (ply->joy_snap == 0) /* player wants to move */
437 boolean moved = FALSE;
439 if (ply->last_move_dir & MV_HORIZONTAL)
441 if (!(moved = player_digfield(ply, 0, dy)))
442 moved = player_digfield(ply, dx, 0);
446 if (!(moved = player_digfield(ply, dx, 0)))
447 moved = player_digfield(ply, 0, dy);
453 ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
454 else if (oldy != ply->y)
455 ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
457 game_em.any_player_moving = TRUE;
458 game_em.last_moving_player = ply->num;
459 game_em.last_player_direction[ply->num] = ply->last_move_dir;
462 else /* player wants to snap */
464 game_em.any_player_snapping = player_digfield(ply, dx, dy);
468 static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
470 int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
475 boolean result = TRUE;
477 if (!dx && !dy) /* no direction specified */
480 if (dx && dy && ply->joy_snap) /* more than one direction specified */
483 if (ply->joy_snap == 0) /* player wants to move */
485 int element = Cave[y][x];
489 /* fire is released */
491 case Yacid_splash_eB:
492 case Yacid_splash_wB:
493 Cave[y][x] = Zplayer;
494 Next[y][x] = Zplayer;
505 play_element_sound(x, y, SAMPLE_blank, Xblank);
506 ply->anim = SPR_walk + anim;
511 #if USE_CHANGED_ACID_STUFF
520 if (Cave[y-1][x+1] == Xblank)
521 Cave[y-1][x+1] = Yacid_splash_eB;
522 if (Cave[y-1][x-1] == Xblank)
523 Cave[y-1][x-1] = Yacid_splash_wB;
524 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
546 #if !USE_CHANGED_ACID_STUFF
556 ply->anim = SPR_walk + anim;
562 Cave[y][x] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
563 (dx > 0 ? Ygrass_eB : Ygrass_wB));
564 Next[y][x] = Zplayer;
565 play_element_sound(x, y, SAMPLE_dirt, Xgrass);
566 ply->anim = SPR_walk + anim;
572 Cave[y][x] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
573 (dx > 0 ? Ydirt_eB : Ydirt_wB));
574 Next[y][x] = Zplayer;
575 play_element_sound(x, y, SAMPLE_dirt, Xdirt);
576 ply->anim = SPR_walk + anim;
583 Cave[y][x] = Ydiamond_eat;
584 Next[y][x] = Zplayer;
585 play_element_sound(x, y, SAMPLE_collect, element);
586 lev.score += lev.diamond_score;
587 lev.required = lev.required < 3 ? 0 : lev.required - 3;
588 game.snapshot.collected_item = TRUE;
589 ply->anim = SPR_walk + anim;
596 Cave[y][x] = Yemerald_eat;
597 Next[y][x] = Zplayer;
598 play_element_sound(x, y, SAMPLE_collect, element);
599 lev.score += lev.emerald_score;
600 lev.required = lev.required < 1 ? 0 : lev.required - 1;
601 game.snapshot.collected_item = TRUE;
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_element_sound(x, y, SAMPLE_acid, Xacid_1);
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_element_sound(x, y, SAMPLE_acid, Xacid_1);
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_element_sound(x, y, SAMPLE_acid, Xacid_1);
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_element_sound(x, y, SAMPLE_acid, Xacid_1);
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_element_sound(x, y, SAMPLE_acid, Xacid_1);
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_element_sound(x, y, SAMPLE_acid, Xacid_1);
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;
1074 ply->anim = SPR_walk + anim;
1081 if (ply->x == oldx && ply->y == oldy) /* no movement */
1084 else /* player wants to snap */
1086 int element = Cave[y][x];
1090 /* fire is pressed */
1093 Cave[y][x] = Ygrass_eat;
1094 Next[y][x] = Xblank;
1095 play_element_sound(x, y, SAMPLE_dirt, element);
1096 ply->anim = SPR_spray + anim;
1100 Cave[y][x] = Ydirt_eat;
1101 Next[y][x] = Xblank;
1102 play_element_sound(x, y, SAMPLE_dirt, element);
1103 ply->anim = SPR_spray + anim;
1107 case Xdiamond_pause:
1108 Cave[y][x] = Ydiamond_eat;
1109 Next[y][x] = Xblank;
1110 play_element_sound(x, y, SAMPLE_collect, element);
1111 lev.score += lev.diamond_score;
1112 lev.required = lev.required < 3 ? 0 : lev.required - 3;
1113 game.snapshot.collected_item = TRUE;
1114 ply->anim = SPR_walk + anim;
1118 case Xemerald_pause:
1119 Cave[y][x] = Yemerald_eat;
1120 Next[y][x] = Xblank;
1121 play_element_sound(x, y, SAMPLE_collect, element);
1122 lev.score += lev.emerald_score;
1123 lev.required = lev.required < 1 ? 0 : lev.required - 1;
1124 game.snapshot.collected_item = TRUE;
1125 ply->anim = SPR_walk + anim;
1129 Cave[y][x] = Ydynamite_eat;
1130 Next[y][x] = Xblank;
1131 play_element_sound(x, y, SAMPLE_collect, element);
1132 lev.score += lev.dynamite_score;
1133 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1134 ply->anim = SPR_walk + anim;
1139 Cave[y][x] = Ykey_1_eat;
1144 Cave[y][x] = Ykey_2_eat;
1149 Cave[y][x] = Ykey_3_eat;
1154 Cave[y][x] = Ykey_4_eat;
1159 Cave[y][x] = Ykey_5_eat;
1164 Cave[y][x] = Ykey_6_eat;
1169 Cave[y][x] = Ykey_7_eat;
1174 Cave[y][x] = Ykey_8_eat;
1178 Next[y][x] = Xblank;
1179 play_element_sound(x, y, SAMPLE_collect, element);
1180 lev.score += lev.key_score;
1181 ply->anim = SPR_walk + anim;
1185 Cave[y][x] = Ylenses_eat;
1186 Next[y][x] = Xblank;
1187 play_element_sound(x, y, SAMPLE_collect, element);
1188 lev.score += lev.lenses_score;
1189 lev.lenses_cnt = lev.lenses_time;
1190 ply->anim = SPR_walk + anim;
1194 Cave[y][x] = Ymagnify_eat;
1195 Next[y][x] = Xblank;
1196 play_element_sound(x, y, SAMPLE_collect, element);
1197 lev.score += lev.magnify_score;
1198 lev.magnify_cnt = lev.magnify_time;
1199 ply->anim = SPR_walk + anim;