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 ply->anim = SPR_walk + anim;
595 Cave[y][x] = Yemerald_eat;
596 Next[y][x] = Zplayer;
597 play_element_sound(x, y, SAMPLE_collect, element);
598 lev.score += lev.emerald_score;
599 lev.required = lev.required < 1 ? 0 : lev.required - 1;
600 ply->anim = SPR_walk + anim;
606 Cave[y][x] = Ydynamite_eat;
607 Next[y][x] = Zplayer;
608 play_element_sound(x, y, SAMPLE_collect, element);
609 lev.score += lev.dynamite_score;
610 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
611 ply->anim = SPR_walk + anim;
618 Cave[y][x] = Ykey_1_eat;
623 Cave[y][x] = Ykey_2_eat;
628 Cave[y][x] = Ykey_3_eat;
633 Cave[y][x] = Ykey_4_eat;
638 Cave[y][x] = Ykey_5_eat;
643 Cave[y][x] = Ykey_6_eat;
648 Cave[y][x] = Ykey_7_eat;
653 Cave[y][x] = Ykey_8_eat;
658 Next[y][x] = Zplayer;
659 play_element_sound(x, y, SAMPLE_collect, element);
660 lev.score += lev.key_score;
661 ply->anim = SPR_walk + anim;
667 Cave[y][x] = Ylenses_eat;
668 Next[y][x] = Zplayer;
669 play_element_sound(x, y, SAMPLE_collect, element);
670 lev.score += lev.lenses_score;
671 lev.lenses_cnt = lev.lenses_time;
672 ply->anim = SPR_walk + anim;
678 Cave[y][x] = Ymagnify_eat;
679 Next[y][x] = Zplayer;
680 play_element_sound(x, y, SAMPLE_collect, element);
681 lev.score += lev.magnify_score;
682 lev.magnify_cnt = lev.magnify_time;
683 ply->anim = SPR_walk + anim;
692 switch(Cave[y][x+dx])
702 if (Cave[y-1][x+dx+1] == Xblank)
703 Cave[y-1][x+dx+1] = Yacid_splash_eB;
704 if (Cave[y-1][x+dx-1] == Xblank)
705 Cave[y-1][x+dx-1] = Yacid_splash_wB;
706 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
710 case Yacid_splash_eB:
711 case Yacid_splash_wB:
712 Cave[y][x+dx] = dx > 0 ? Ystone_e : Ystone_w;
713 Next[y][x+dx] = Xstone_pause;
717 Cave[y][x] = dx > 0 ? Ystone_eB : Ystone_wB;
718 Next[y][x] = Zplayer;
719 play_element_sound(x, y, SAMPLE_roll, Xstone);
723 ply->anim = SPR_push + anim;
730 switch(Cave[y][x+dx])
740 if (Cave[y-1][x+dx+1] == Xblank)
741 Cave[y-1][x+dx+1] = Yacid_splash_eB;
742 if (Cave[y-1][x+dx-1] == Xblank)
743 Cave[y-1][x+dx-1] = Yacid_splash_wB;
744 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
748 case Yacid_splash_eB:
749 case Yacid_splash_wB:
750 Cave[y][x+dx] = dx > 0 ? Ybomb_e : Ybomb_w;
751 Next[y][x+dx] = Xbomb_pause;
755 Cave[y][x] = dx > 0 ? Ybomb_eB : Ybomb_wB;
756 Next[y][x] = Zplayer;
757 play_element_sound(x, y, SAMPLE_roll, Xbomb);
761 ply->anim = SPR_push + anim;
768 switch(Cave[y][x+dx])
778 if (Cave[y-1][x+dx+1] == Xblank)
779 Cave[y-1][x+dx+1] = Yacid_splash_eB;
780 if (Cave[y-1][x+dx-1] == Xblank)
781 Cave[y-1][x+dx-1] = Yacid_splash_wB;
782 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
786 case Yacid_splash_eB:
787 case Yacid_splash_wB:
788 Cave[y][x+dx] = dx > 0 ? Ynut_e : Ynut_w;
789 Next[y][x+dx] = Xnut_pause;
793 Cave[y][x] = dx > 0 ? Ynut_eB : Ynut_wB;
794 Next[y][x] = Zplayer;
795 play_element_sound(x, y, SAMPLE_roll, Xnut);
799 ply->anim = SPR_push + anim;
806 switch(Cave[y][x+dx])
810 Cave[y][x] = dx > 0 ? Yspring_kill_eB : Yspring_kill_wB;
811 Cave[y][x+dx] = dx > 0 ? Yspring_kill_e : Yspring_kill_w;
812 Next[y][x] = Zplayer;
813 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
814 play_element_sound(x, y, SAMPLE_slurp, Xalien);
815 lev.score += lev.slurp_score;
827 if (Cave[y-1][x+dx+1] == Xblank)
828 Cave[y-1][x+dx+1] = Yacid_splash_eB;
829 if (Cave[y-1][x+dx-1] == Xblank)
830 Cave[y-1][x+dx-1] = Yacid_splash_wB;
831 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
835 case Yacid_splash_eB:
836 case Yacid_splash_wB:
837 Cave[y][x+dx] = dx > 0 ? Yspring_e : Yspring_w;
838 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
841 Cave[y][x] = dx > 0 ? Yspring_eB : Yspring_wB;
842 Next[y][x] = Zplayer;
843 play_element_sound(x, y, SAMPLE_roll, Xspring);
847 ply->anim = SPR_push + anim;
854 case Xsand_stonein_1:
855 case Xsand_stonein_2:
856 case Xsand_stonein_3:
857 case Xsand_stonein_4:
861 ply->anim = SPR_push + anim;
865 switch(Cave[y+dy][x+dx])
875 if (Cave[y+dy-1][x+dx+1] == Xblank)
876 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
877 if (Cave[y+dy-1][x+dx-1] == Xblank)
878 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
879 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
883 case Yacid_splash_eB:
884 case Yacid_splash_wB:
885 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
886 (dx > 0 ? Yballoon_e : Yballoon_w));
887 Next[y+dy][x+dx] = Xballoon;
890 Cave[y][x] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
891 (dx > 0 ? Yballoon_eB : Yballoon_wB));
892 Next[y][x] = Zplayer;
893 play_element_sound(x, y, SAMPLE_push, Xballoon);
898 ply->anim = SPR_push + anim;
910 switch(Cave[y+dy][x+dx])
920 if (Cave[y+dy-1][x+dx+1] == Xblank)
921 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
922 if (Cave[y+dy-1][x+dx-1] == Xblank)
923 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
924 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
928 case Yacid_splash_eB:
929 case Yacid_splash_wB:
930 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
931 (dx > 0 ? Yandroid_e : Yandroid_w));
932 Next[y+dy][x+dx] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
933 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
936 Cave[y][x] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
937 (dx > 0 ? Yandroid_eB : Yandroid_wB));
938 Next[y][x] = Zplayer;
939 play_element_sound(x, y, SAMPLE_push, Xandroid);
944 ply->anim = SPR_push + anim;
949 if (ply->keys & 0x01)
956 if (ply->keys & 0x02)
963 if (ply->keys & 0x04)
970 if (ply->keys & 0x08)
977 if (ply->keys & 0x10)
984 if (ply->keys & 0x20)
991 if (ply->keys & 0x40)
998 if (ply->keys & 0x80)
1004 if (!tab_blank[Cave[y+dy][x+dx]])
1007 Cave[y+dy][x+dx] = Zplayer;
1008 Next[y+dy][x+dx] = Zplayer;
1009 play_element_sound(x, y, SAMPLE_door, element);
1010 ply->anim = SPR_walk + anim;
1016 play_element_sound(x, y, SAMPLE_press, element);
1017 lev.wheel_cnt = lev.wheel_time;
1023 lev.wind_direction = 0;
1027 lev.wind_direction = 1;
1031 lev.wind_direction = 2;
1035 lev.wind_direction = 3;
1039 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
1043 play_element_sound(x, y, SAMPLE_press, element);
1044 lev.wind_cnt = lev.wind_time;
1048 play_element_sound(x, y, SAMPLE_press, element);
1053 play_element_sound(x, y, SAMPLE_press, element);
1054 lev.ball_cnt = lev.ball_time;
1055 lev.ball_state = !lev.ball_state;
1059 Cave[y][x] = Yplant;
1060 Next[y][x] = Xplant;
1061 play_element_sound(x, y, SAMPLE_blank, Xplant);
1062 ply->anim = SPR_walk + anim;
1072 ply->anim = SPR_walk + anim;
1079 if (ply->x == oldx && ply->y == oldy) /* no movement */
1082 else /* player wants to snap */
1084 int element = Cave[y][x];
1088 /* fire is pressed */
1091 Cave[y][x] = Ygrass_eat;
1092 Next[y][x] = Xblank;
1093 play_element_sound(x, y, SAMPLE_dirt, element);
1094 ply->anim = SPR_spray + anim;
1098 Cave[y][x] = Ydirt_eat;
1099 Next[y][x] = Xblank;
1100 play_element_sound(x, y, SAMPLE_dirt, element);
1101 ply->anim = SPR_spray + anim;
1105 case Xdiamond_pause:
1106 Cave[y][x] = Ydiamond_eat;
1107 Next[y][x] = Xblank;
1108 play_element_sound(x, y, SAMPLE_collect, element);
1109 lev.score += lev.diamond_score;
1110 lev.required = lev.required < 3 ? 0 : lev.required - 3;
1111 ply->anim = SPR_walk + anim;
1115 case Xemerald_pause:
1116 Cave[y][x] = Yemerald_eat;
1117 Next[y][x] = Xblank;
1118 play_element_sound(x, y, SAMPLE_collect, element);
1119 lev.score += lev.emerald_score;
1120 lev.required = lev.required < 1 ? 0 : lev.required - 1;
1121 ply->anim = SPR_walk + anim;
1125 Cave[y][x] = Ydynamite_eat;
1126 Next[y][x] = Xblank;
1127 play_element_sound(x, y, SAMPLE_collect, element);
1128 lev.score += lev.dynamite_score;
1129 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1130 ply->anim = SPR_walk + anim;
1135 Cave[y][x] = Ykey_1_eat;
1140 Cave[y][x] = Ykey_2_eat;
1145 Cave[y][x] = Ykey_3_eat;
1150 Cave[y][x] = Ykey_4_eat;
1155 Cave[y][x] = Ykey_5_eat;
1160 Cave[y][x] = Ykey_6_eat;
1165 Cave[y][x] = Ykey_7_eat;
1170 Cave[y][x] = Ykey_8_eat;
1174 Next[y][x] = Xblank;
1175 play_element_sound(x, y, SAMPLE_collect, element);
1176 lev.score += lev.key_score;
1177 ply->anim = SPR_walk + anim;
1181 Cave[y][x] = Ylenses_eat;
1182 Next[y][x] = Xblank;
1183 play_element_sound(x, y, SAMPLE_collect, element);
1184 lev.score += lev.lenses_score;
1185 lev.lenses_cnt = lev.lenses_time;
1186 ply->anim = SPR_walk + anim;
1190 Cave[y][x] = Ymagnify_eat;
1191 Next[y][x] = Xblank;
1192 play_element_sound(x, y, SAMPLE_collect, element);
1193 lev.score += lev.magnify_score;
1194 lev.magnify_cnt = lev.magnify_time;
1195 ply->anim = SPR_walk + anim;